plucky (2) chroot.2.gz

Provided by: manpages-ja-dev_0.5.0.0.20221215+dfsg-1_all bug

名前

       chroot - ルートディレクトリを変更する

書式

       #include <unistd.h>

       int chroot(const char *path);

   glibc 向けの機能検査マクロの要件 (feature_test_macros(7)  参照):

       chroot():
           glibc 2.2.2 以降:
               _XOPEN_SOURCE && ! (_POSIX_C_SOURCE >= 200112L)
                   || /* glibc 2.20 以降: */ _DEFAULT_SOURCE
                   || /* Glibc 2.19 以前: */ _BSD_SOURCE
           glibc 2.2.2 より前: なし

説明

       chroot()  は、呼び出し元プロセスのルートディレクトリを path で指定されたディレクトリに変更する。 このディ
       レクトリ以下が / から始まるパス名として使われる。  このルートディレクトリは呼び出し元のプロセスの全ての子
       プロセスに受け継がれる。

       特権プロセス  (Linux  では、そのプロセスのユーザー名前空間で CAP_SYS_CHROOT ケーパビリティを持つプロセス)
       のみが chroot()  を呼び出すことができる。

       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, chroot()  has been used by daemons to restrict themselves
       prior to passing paths supplied by untrusted users to system calls such as open(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 chdir(2)  to the to-be-moved directory, wait for it to be moved
       out, then open a path like ../../../etc/passwd.

       A slightly trickier variation also works under some circumstances if chdir(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.

       このコールは現在の作業ディレクトリ  (working  directory) を変更しない。 そのため、このコールの後に '.' が
       '/' を 根とするツリーの外になる場合がある。 特に、スーパーユーザーは以下のようにすることで "chroot  jail"
       から逃げ出せてしまう。

           mkdir foo; chroot foo; cd ..

       このコールはオープンファイルディスクリプターをクローズしないので、   このようなファイルディスクリプターは
       chroot ツリーの外にある ファイルにアクセスできる。

返り値

       成功した場合は 0 が返される。エラーの場合は -1 が返され、 errno が適切に設定される。

エラー

       ファイルシステムによっては他のエラーが返される事がある。 一般的なエラーを以下に挙げる:

       EACCES パス名の構成要素に検索許可がない (path_resolution(7)  も見よ)。

       EFAULT path がアクセスできるアドレス空間外を指している。

       EIO    I/O エラーが発生した。

       ELOOP  path を解決する際に遭遇したシンボリックリンクが多過ぎる。

       ENAMETOOLONG
              path が長過ぎる。

       ENOENT ファイルが存在しない。

       ENOMEM カーネルに十分なメモリーがない。

       ENOTDIR
              path の構成要素がディレクトリではない。

       EPERM  呼び出し側に十分な特権がない。

準拠

       SVr4, 4.4BSD, SUSv2 (但し、SUSv2 では過去の名残とされている)。 この関数は POSIX.1-2001 にはない。

注意

       fork(2)  で作成された子プロセスは、 親プロセスのルートディレクトリを継承する。 execve(2) の場合も、ルート
       ディレクトリは変更されない。

       The  magic  symbolic  link,  /proc/[pid]/root,  can  be  used to discover a process's root directory; see
       proc(5)  for details.

       FreeBSD にはより強力な jail()  システムコールがある。

関連項目

       chroot(1), chdir(2), pivot_root(2), path_resolution(7), switch_root(8)

この文書について

       この man ページは Linux man-pages プロジェクトのリリース 5.10  の一部である。プロジェクトの説明とバグ報告
       に関する情報は https://www.kernel.org/doc/man-pages/ に書かれている。