Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • Thank you! Do you know why it’s necessary to chroot(2) again? I mean, do you know why is it necessary for Linux to have the cwd inside the “known space” of the current root for operations like os.getcwd() to succeed? Commented Mar 8, 2021 at 19:18
  • Yes: because when you're outside of the current (ch)root tree, this directory can't be resolved from / Commented Mar 8, 2021 at 19:19
  • 1
    Python should indeed be smart enough to call fchdir(), since Python 3.3.: docs.python.org/3/library/os.html#os.chdir Commented Mar 8, 2021 at 22:19
  • @ilkkachu - help(os.chdir) says that os.chdir() may be given a file descriptor on platforms that support it. It was therefore I used this function. Commented Mar 9, 2021 at 8:25
  • @A.B - Do you have any idea on how to accomplish what Linus describes as "The smallest part, in fact. And you should be aware that root can always get out of a chroot() if he just has enough tools - and the tools aren't even very big. "mknod" + "mount" will do it even in the absence of a way to add binaries, as will /proc access)."? How can mknod+mount be used to to break out of chroot, if the /dev directory is not present? Also, /proc may be used to escape the jail by cd /proc/<pid>/root? Commented Mar 9, 2021 at 9:28