.\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992 .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\" Modified by Michael Haardt .\" Modified 1993-07-21 by Rik Faith .\" Modified 1994-08-21 by Michael Chastain .\" Modified 1996-06-13 by aeb .\" Modified 1996-11-06 by Eric S. Raymond .\" Modified 1997-08-21 by Joseph S. Myers .\" Modified 2004-06-23 by Michael Kerrisk .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 1996 Yosiaki Yanagihara .\" all rights reserved. .\" Translated Mon Jun 24 14:29:55 JST 1996 .\" by Yosiaki Yanagihara .\" Modified Sat Dec 13 23:29:07 JST 1997 .\" by HANATAKA Shinya .\" Updated & Modified Fri 6 Apr 2001 .\" by NAKANO Takeo .\" Updated & Modified Thu Dec 23 10:04:20 JST 2004 .\" by Yuichi SATO .\" .TH CHROOT 2 2020\-12\-21 Linux "Linux Programmer's Manual" .SH 名前 chroot \- ルートディレクトリを変更する .SH 書式 \fB#include \fP .PP \fBint chroot(const char *\fP\fIpath\fP\fB);\fP .PP .RS -4 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .RE .PP \fBchroot\fP(): .ad l .RS 4 .PD 0 .TP 4 glibc 2.2.2 以降: .nf _XOPEN_SOURCE && ! (_POSIX_C_SOURCE\ >=\ 200112L) || /* glibc 2.20 以降: */ _DEFAULT_SOURCE || /* Glibc 2.19 以前: */ _BSD_SOURCE .fi .TP 4 glibc 2.2.2 より前: なし .PD .RE .ad b .SH 説明 \fBchroot\fP() は、呼び出し元プロセスのルートディレクトリを \fIpath\fP で指定されたディレクトリに変更する。 このディレクトリ以下が \fI/\fP から始まるパス名として使われる。 このルートディレクトリは呼び出し元のプロセスの全ての子プロセスに受け継がれる。 .PP 特権プロセス (Linux では、そのプロセスのユーザー名前空間で \fBCAP_SYS_CHROOT\fP ケーパビリティを持つプロセス) のみが \fBchroot\fP() を呼び出すことができる。 .PP This call changes an ingredient in the pathname resolution process and does nothing else. In particular, it is not intended to be used for any kind of security purpose, neither to fully sandbox a process nor to restrict filesystem system calls. In the past, \fBchroot\fP() has been used by daemons to restrict themselves prior to passing paths supplied by untrusted users to system calls such as \fBopen\fP(2). However, if a folder is moved out of the chroot directory, an attacker can exploit that to get out of the chroot directory as well. The easiest way to do that is to \fBchdir\fP(2) to the to\-be\-moved directory, wait for it to be moved out, then open a path like \&../../../etc/passwd. .PP .\" This is how the "slightly trickier variation" works: .\" https://github.com/QubesOS/qubes-secpack/blob/master/QSBs/qsb-014-2015.txt#L142 A slightly trickier variation also works under some circumstances if \fBchdir\fP(2) is not permitted. If a daemon allows a "chroot directory" to be specified, that usually means that if you want to prevent remote users from accessing files outside the chroot directory, you must ensure that folders are never moved out of it. .PP このコールは現在の作業ディレクトリ (working directory) を変更しない。 そのため、このコールの後に \(aq\fI.\fP\(aq が \(aq\fI/\fP\(aq を 根とするツリーの外になる場合がある。 特に、スーパーユーザーは以下のようにすることで "chroot jail" から逃げ出せてしまう。 .PP .in +4n .EX mkdir foo; chroot foo; cd .. .EE .in .PP このコールはオープンファイルディスクリプターをクローズしないので、 このようなファイルディスクリプターは chroot ツリーの外にある ファイルにアクセスできる。 .SH 返り値 成功した場合は 0 が返される。エラーの場合は \-1 が返され、 \fIerrno\fP が適切に設定される。 .SH エラー ファイルシステムによっては他のエラーが返される事がある。 一般的なエラーを以下に挙げる: .TP \fBEACCES\fP .\" Also search permission is required on the final component, .\" maybe just to guarantee that it is a directory? パス名の構成要素に検索許可がない (\fBpath_resolution\fP(7) も見よ)。 .TP \fBEFAULT\fP \fIpath\fP がアクセスできるアドレス空間外を指している。 .TP \fBEIO\fP I/O エラーが発生した。 .TP \fBELOOP\fP \fIpath\fP を解決する際に遭遇したシンボリックリンクが多過ぎる。 .TP \fBENAMETOOLONG\fP \fIpath\fP が長過ぎる。 .TP \fBENOENT\fP ファイルが存在しない。 .TP \fBENOMEM\fP カーネルに十分なメモリーがない。 .TP \fBENOTDIR\fP \fIpath\fP の構成要素がディレクトリではない。 .TP \fBEPERM\fP 呼び出し側に十分な特権がない。 .SH 準拠 .\" SVr4 documents additional EINTR, ENOLINK and EMULTIHOP error conditions. .\" X/OPEN does not document EIO, ENOMEM or EFAULT error conditions. SVr4, 4.4BSD, SUSv2 (但し、SUSv2 では過去の名残とされている)。 この関数は POSIX.1\-2001 にはない。 .SH 注意 \fBfork\fP(2) で作成された子プロセスは、 親プロセスのルートディレクトリを継承する。 \fBexecve\fP(2) の場合も、ルートディレクトリは変更されない。 .PP The magic symbolic link, \fI/proc/[pid]/root\fP, can be used to discover a process's root directory; see \fBproc\fP(5) for details. .PP FreeBSD にはより強力な \fBjail\fP() システムコールがある。 .SH 関連項目 \fBchroot\fP(1), \fBchdir\fP(2), \fBpivot_root\fP(2), \fBpath_resolution\fP(7), \fBswitch_root\fP(8) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は \%https://www.kernel.org/doc/man\-pages/ に書かれている。