Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Re: exiting a chroot environment

by sauoq (Abbot)
on Jul 07, 2003 at 22:46 UTC ( [id://272128]=note: print w/replies, xml ) Need Help??


in reply to Re: exiting a chroot environment
in thread exiting a chroot environment

Freaky as it seems, you can on Linux¹ (Red Hat.)

From chroot(2):

Note that this call does not change the current working directory, so that `.' can be outside the tree rooted at `/'. In particular, the super-user can escape from a `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.

I've confirmed that I can do it in perl with another chroot() to ./../../ (with enough ..s to get me to the real root from the CWD.) I guess "." isn't just symbolic?

Ick.

Thankfully, that's not portable. Other systems are sane.

1. I figured I'd look at the manpage to see if it said "you can't do that" and much to my surprise...

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re: Re: Re: exiting a chroot environment
by MarkM (Curate) on Jul 08, 2003 at 02:31 UTC

    I wouldn't be as quick to declare that this is a Linux failing point. There are no guarantees made by any system that chroot() will ensure that exploits are not possible. chroot() is a UNIX hack to redefine /, and this is where its claim ends. If one truly wants a box to contain a user, one should consider using a virtual machine of some sort.

    It isn't that 'other systems are sane', but rather, 'other systems implement chroot() as a more elaborate hack.' The cost, of course, is performance, and code complexity. Is Linux wrong for not choosing this path? I don't believe so. I believe it is wrong for people to assume that silver bullets to their security problems exist... :-)

      AFAIK, the guarantee provided by all Unix systems is that non-root users can't escape from chroot. I can't find a good reference, but that's always been my understanding of this system call. root's limitations in chroot vary by operating system.

      It's safe to trust chroot as long as you drop root before executing untrusted code.

        What you are talking about is practical experience, and observation. The exact details regarding chroot() do indeed vary by implementation, and therefore, cannot be safely assumed.

        As opposed to me demanding you accept my mortal words, I will refer you to a URL that seems to be quite valuable with regard to this topic. Yes, the easiest exploits involve the user running as root. This should not be taken for granted. Additional precautions are necessary.

        http://www.unixwiz.net/techtips/chroot-practices.html
      It isn't that 'other systems are sane', but rather, 'other systems implement chroot() as a more elaborate hack.' The cost, of course, is performance, and code complexity.

      I really don't know. I haven't looked at any code. I don't care that much, but I am curious. How would it be a "more elaborate hack" to avoid special-casing root? How would it result in more code complexity or less performance? I doubt performance is an issue in any case, but I would think that Linux's behavior would result in more code complexity.

      I believe it is wrong for people to assume that silver bullets to their security problems exist.

      I absolutely agree. (And I never even mentioned security in the first place.)

      Maybe "sane" wasn't the right choice of words. Frankly, I was just surprised as I wasn't familiar with that behavior. I don't really see much advantage to it, but I guess I don't see much harm either. *shrug*

      -sauoq
      "My two cents aren't worth a dime.";
      

        Consider the issue with Linux. The reason '.' can be used to escape from a chroot() environment is because '.' is not special. '.' is a hard link to current directory. In operating systems that implement chroot() to be 'more secure', '.' must be special cased.

        Specifically, '.' and '/..' must be special cased. In the simplest form, this may mean that '/.' and /..' need to be translated in place on reference to appear as if they both referred to '/'.

Re: exiting a chroot environment
by Abigail-II (Bishop) on Jul 07, 2003 at 22:55 UTC
    Urg. I didn't realize Linux behaved so oddly. Yet another reason not to worship Linux (don't get me wrong, I make my money as a "Linux specialist"). Not only is Linux behaviour not portable, the entire chroot concept isn't. chroot is not part of the POSIX standard.

    Abigail

      Not that I am arguing in favour of Linux worship but the chroot man page does say that the linux implementation conforms to a number of standards "CONFORMING TO SVr4, SVID, 4.4BSD, X/OPEN. This function is not part of POSIX.1." and the OpenBSD chroot man page also states that "There are ways for a root process to escape from the chroot jail". Without actually comparing code it is impossible to say one way or another but on the surface it would appear that the Linux implementation is not that "odd".

      --
      Do not seek to follow in the footsteps of the wise. Seek what they sought. -Basho

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://272128]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (1)
As of 2024-04-25 03:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found