1 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\" Modified by Michael Haardt <michael@moria.de>
6 .\" Modified 1993-07-21 by Rik Faith <faith@cs.unc.edu>
7 .\" Modified 1994-08-21 by Michael Chastain <mec@shell.portal.com>
8 .\" Modified 1996-06-13 by aeb
9 .\" Modified 1996-11-06 by Eric S. Raymond <esr@thyrsus.com>
10 .\" Modified 1997-08-21 by Joseph S. Myers <jsm28@cam.ac.uk>
11 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
13 .TH CHROOT 2 2021-03-22 "Linux man-pages (unreleased)"
15 chroot \- change root directory
18 .RI ( libc ", " \-lc )
21 .B #include <unistd.h>
23 .BI "int chroot(const char *" path );
27 Feature Test Macro Requirements for glibc (see
28 .BR feature_test_macros (7)):
34 _XOPEN_SOURCE && ! (_POSIX_C_SOURCE >= 200112L)
35 || /* Since glibc 2.20: */ _DEFAULT_SOURCE
36 || /* Glibc <= 2.19: */ _BSD_SOURCE
42 changes the root directory of the calling process to that specified in
44 This directory will be used for pathnames beginning with \fI/\fP.
45 The root directory is inherited by all children of the calling process.
47 Only a privileged process (Linux: one with the
49 capability in its user namespace) may call
52 This call changes an ingredient in the pathname resolution process
53 and does nothing else.
54 In particular, it is not intended to be used
55 for any kind of security purpose, neither to fully sandbox a process nor
56 to restrict filesystem system calls.
59 has been used by daemons to restrict themselves prior to passing paths
60 supplied by untrusted users to system calls such as
62 However, if a folder is moved out of the chroot directory, an attacker
63 can exploit that to get out of the chroot directory as well.
64 The easiest way to do that is to
66 to the to-be-moved directory, wait for it to be moved out, then open a
67 path like ../../../etc/passwd.
69 .\" This is how the "slightly trickier variation" works:
70 .\" https://github.com/QubesOS/qubes-secpack/blob/master/QSBs/qsb-014-2015.txt#L142
72 trickier variation also works under some circumstances if
75 If a daemon allows a "chroot directory" to be specified,
76 that usually means that if you want to prevent remote users from accessing
77 files outside the chroot directory, you must ensure that folders are never
80 This call does not change the current working directory,
81 so that after the call \(aq\fI.\fP\(aq can
82 be outside the tree rooted at \(aq\fI/\fP\(aq.
83 In particular, the superuser can escape from a "chroot jail"
88 mkdir foo; chroot foo; cd ..
92 This call does not close open file descriptors, and such file
93 descriptors may allow access to files outside the chroot tree.
95 On success, zero is returned.
96 On error, \-1 is returned, and
98 is set to indicate the error.
100 Depending on the filesystem, other errors can be returned.
101 The more general errors are listed below:
104 Search permission is denied on a component of the path prefix.
106 .BR path_resolution (7).)
107 .\" Also search permission is required on the final component,
108 .\" maybe just to guarantee that it is a directory?
112 points outside your accessible address space.
115 An I/O error occurred.
118 Too many symbolic links were encountered in resolving
126 The file does not exist.
129 Insufficient kernel memory was available.
137 The caller has insufficient privilege.
139 SVr4, 4.4BSD, SUSv2 (marked LEGACY).
140 This function is not part of POSIX.1-2001.
141 .\" SVr4 documents additional EINTR, ENOLINK and EMULTIHOP error conditions.
142 .\" X/OPEN does not document EIO, ENOMEM or EFAULT error conditions.
144 A child process created via
146 inherits its parent's root directory.
147 The root directory is left unchanged by
150 The magic symbolic link,
151 .IR /proc/[pid]/root ,
152 can be used to discover a process's root directory; see
156 FreeBSD has a stronger
163 .BR path_resolution (7),