OSDN Git Service

0d44bbfdbb32dbe14aadc149dfc60e22e194c8c3
[linuxjm/jm.git] / manual / LDP_man-pages / draft / man2 / chroot.2
1 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Modified by Michael Haardt <michael@moria.de>
26 .\" Modified 1993-07-21 by Rik Faith <faith@cs.unc.edu>
27 .\" Modified 1994-08-21 by Michael Chastain <mec@shell.portal.com>
28 .\" Modified 1996-06-13 by aeb
29 .\" Modified 1996-11-06 by Eric S. Raymond <esr@thyrsus.com>
30 .\" Modified 1997-08-21 by Joseph S. Myers <jsm28@cam.ac.uk>
31 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
32 .\"
33 .\"*******************************************************************
34 .\"
35 .\" This file was generated with po4a. Translate the source file.
36 .\"
37 .\"*******************************************************************
38 .\"
39 .\" Japanese Version Copyright (c) 1996 Yosiaki Yanagihara
40 .\"         all rights reserved.
41 .\" Translated Mon Jun 24 14:29:55 JST 1996
42 .\"         by Yosiaki Yanagihara <yosiaki@bsd2.kbnes.nec.co.jp>
43 .\" Modified Sat Dec 13 23:29:07 JST 1997
44 .\"         by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
45 .\" Updated & Modified Fri 6 Apr 2001
46 .\"         by NAKANO Takeo <nakano@apm.seikei.ac.jp>
47 .\" Updated & Modified Thu Dec 23 10:04:20 JST 2004
48 .\"         by Yuichi SATO <ysato444@yahoo.co.jp>
49 .\"
50 .TH CHROOT 2 2020\-12\-21 Linux "Linux Programmer's Manual"
51 .SH 名前
52 chroot \- ルートディレクトリを変更する
53 .SH 書式
54 \fB#include <unistd.h>\fP
55 .PP
56 \fBint chroot(const char *\fP\fIpath\fP\fB);\fP
57 .PP
58 .RS -4
59 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
60 .RE
61 .PP
62 \fBchroot\fP():
63 .ad l
64 .RS 4
65 .PD 0
66 .TP  4
67 glibc 2.2.2 以降:
68 .nf
69 _XOPEN_SOURCE && ! (_POSIX_C_SOURCE\ >=\ 200112L)
70     || /* Since glibc 2.20: */ _DEFAULT_SOURCE
71     || /* Glibc versions <= 2.19: */ _BSD_SOURCE
72 .fi
73 .TP  4
74 glibc 2.2.2 より前: なし
75 .PD
76 .RE
77 .ad b
78 .SH 説明
79 \fBchroot\fP()  は、呼び出し元プロセスのルートディレクトリを \fIpath\fP で指定されたディレクトリに変更する。 このディレクトリ以下が
80 \fI/\fP から始まるパス名として使われる。 このルートディレクトリは呼び出し元のプロセスの全ての子プロセスに受け継がれる。
81 .PP
82 Only a privileged process (Linux: one with the \fBCAP_SYS_CHROOT\fP capability
83 in its user namespace) may call \fBchroot\fP().
84 .PP
85 This call changes an ingredient in the pathname resolution process and does
86 nothing else.  In particular, it is not intended to be used for any kind of
87 security purpose, neither to fully sandbox a process nor to restrict
88 filesystem system calls.  In the past, \fBchroot\fP()  has been used by daemons
89 to restrict themselves prior to passing paths supplied by untrusted users to
90 system calls such as \fBopen\fP(2).  However, if a folder is moved out of the
91 chroot directory, an attacker can exploit that to get out of the chroot
92 directory as well.  The easiest way to do that is to \fBchdir\fP(2)  to the
93 to\-be\-moved directory, wait for it to be moved out, then open a path like
94 \&../../../etc/passwd.
95 .PP
96 .\" This is how the "slightly trickier variation" works:
97 .\" https://github.com/QubesOS/qubes-secpack/blob/master/QSBs/qsb-014-2015.txt#L142
98 A slightly trickier variation also works under some circumstances if
99 \fBchdir\fP(2)  is not permitted.  If a daemon allows a "chroot directory" to
100 be specified, that usually means that if you want to prevent remote users
101 from accessing files outside the chroot directory, you must ensure that
102 folders are never moved out of it.
103 .PP
104 このコールは現在の作業ディレクトリ (working directory) を変更しない。 そのため、このコールの後に \(aq\fI.\fP\(aq が
105 \(aq\fI/\fP\(aq を 根とするツリーの外になる場合がある。 特に、スーパーユーザーは以下のようにすることで "chroot jail"
106 から逃げ出せてしまう。
107 .PP
108 .in +4n
109 .EX
110 mkdir foo; chroot foo; cd ..
111 .EE
112 .in
113 .PP
114 このコールはオープンファイルディスクリプターをクローズしないので、 このようなファイルディスクリプターは chroot ツリーの外にある
115 ファイルにアクセスできる。
116 .SH 返り値
117 成功した場合は 0 が返される。エラーの場合は \-1 が返され、 \fIerrno\fP が適切に設定される。
118 .SH エラー
119 ファイルシステムによっては他のエラーが返される事がある。 一般的なエラーを以下に挙げる:
120 .TP 
121 \fBEACCES\fP
122 .\" Also search permission is required on the final component,
123 .\" maybe just to guarantee that it is a directory?
124 パス名の構成要素に検索許可がない (\fBpath_resolution\fP(7)  も見よ)。
125 .TP 
126 \fBEFAULT\fP
127 \fIpath\fP がアクセスできるアドレス空間外を指している。
128 .TP 
129 \fBEIO\fP
130 I/O エラーが発生した。
131 .TP 
132 \fBELOOP\fP
133 \fIpath\fP を解決する際に遭遇したシンボリックリンクが多過ぎる。
134 .TP 
135 \fBENAMETOOLONG\fP
136 \fIpath\fP が長過ぎる。
137 .TP 
138 \fBENOENT\fP
139 ファイルが存在しない。
140 .TP 
141 \fBENOMEM\fP
142 カーネルに十分なメモリーがない。
143 .TP 
144 \fBENOTDIR\fP
145 \fIpath\fP の構成要素がディレクトリではない。
146 .TP 
147 \fBEPERM\fP
148 呼び出し側に十分な特権がない。
149 .SH 準拠
150 .\" SVr4 documents additional EINTR, ENOLINK and EMULTIHOP error conditions.
151 .\" X/OPEN does not document EIO, ENOMEM or EFAULT error conditions.
152 SVr4, 4.4BSD, SUSv2 (但し、SUSv2 では過去の名残とされている)。 この関数は POSIX.1\-2001 にはない。
153 .SH 注意
154 \fBfork\fP(2)  で作成された子プロセスは、 親プロセスのルートディレクトリを継承する。 \fBexecve\fP(2)
155 の場合も、ルートディレクトリは変更されない。
156 .PP
157 The magic symbolic link, \fI/proc/[pid]/root\fP, can be used to discover a
158 process's root directory; see \fBproc\fP(5)  for details.
159 .PP
160 FreeBSD にはより強力な \fBjail\fP()  システムコールがある。
161 .SH 関連項目
162 \fBchroot\fP(1), \fBchdir\fP(2), \fBpivot_root\fP(2), \fBpath_resolution\fP(7),
163 \fBswitch_root\fP(8)
164 .SH この文書について
165 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は
166 \%https://www.kernel.org/doc/man\-pages/ に書かれている。