public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Shaya Potter <spotter@cs.columbia.edu>
To: Ville Herva <vherva@niksula.hut.fi>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: can chroot be made safe for non-root?
Date: 22 Oct 2002 10:15:36 -0400	[thread overview]
Message-ID: <1035296135.1089.35.camel@zaphod> (raw)
In-Reply-To: <20021022072132.GN147946@niksula.cs.hut.fi>

On Tue, 2002-10-22 at 03:21, Ville Herva wrote:
> On Mon, Oct 21, 2002 at 04:22:12PM +0100, you [Alan Cox] wrote:
> > On Wed, 2002-10-16 at 07:44, Philippe Troin wrote:
> > > > Is there a reason besides standards compliance that chroot() does not
> > > > already change directory to the chroot'd directory for root processes?
> > > > Would it actually break existing apps if it did change the directory?
> > > 
> > > Probably not. Make that: change the directory to chroot'd directory if
> > > the current working directory is outside the chroot. That is, leave
> > > the cwd alone if it is already inside the chroot.
> > 
> > Last time it was tried real apps broke.
> > 
> > chroot is not jail chroot is not a sandbox. Do the job right (eg the
> > vroot work) and it'll get a lot further
> 
> vserver (http://www.solucorp.qc.ca/miscprj/s_context.hc) seems to work
> pretty decently. It's somewhat similar to bsd's jail.

from vserver patch

diff -rc2P linux-2.4.19/fs/namei.c linux-2.4.19ctx-14/fs/namei.c
*** linux-2.4.19/fs/namei.c     Tue Aug  6 15:02:24 2002
--- linux-2.4.19ctx-14/fs/namei.c       Sun Oct 13 23:58:55 2002
***************
*** 153,156 ****
--- 153,165 ----
        umode_t                 mode = inode->i_mode;
  
+       /*
+               A dir with permission bit all 0s is a dead zone for
+               process running in a vserver. By doing
+                       chmod 000 /vservers
+               you fix the "escape from chroot" bug.
+       */
+       if ((mode & 0777) == 0
+               && S_ISDIR(mode)
+               && current->s_context != 0) return -EACCES;
        if (mask & MAY_WRITE) {
                /*

I don't think that will work, especially as it seems vserver's dont
nest.

I described an algo (on this list a day or 2 ago) that should work for
fixing the fd problem (everything else seems to be root's power related,
not chroot related)

we add a new field to the task_struct, which is some linked list of
chroot points, normally null for non chrooted processes.

when we call chroot, we dont just change the fs_struct, we pre-append
the same data as a linked list node to the beg of the list (i.e. the
element in the task struct)

in follow_dotdot() instead of checking against the fs_struct, we
basically say
	if (!current->chroot_points)
		; //we know we are not chrooted
	else
		for each element in chroot_list
			if current dir = chroot dir
				chroot = true;
				break
		
		if ( chroot )
			do whatever kernel does now
		else 
			do whatever kernel does now.

on fork, all you have to do is copy the list efficiently b/w parent and
child.

the reason this works, is that any fd you get has to be inside a chroot
point (or within the original root), therefore if you try to chroot
under a chroot while holding fd's, there will be a .. of one of those
fd's that will be a chroot point, that you can kill the path_walk at.



  reply	other threads:[~2002-10-22 14:09 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-16  5:51 can chroot be made safe for non-root? Eric Buddington
2002-10-16  6:44 ` Philippe Troin
2002-10-16 21:18   ` David Wagner
2002-10-16 22:04     ` Philippe Troin
2002-10-16 22:00       ` David Wagner
2002-10-19 17:44   ` Eric Buddington
2002-10-19 19:07     ` Bernd Eckenfels
     [not found]       ` <200210201715.07150.landley@trommello.org>
2002-10-21 20:29         ` Bernd Eckenfels
2002-10-22 15:42     ` Jesse Pollard
2002-10-22 16:55       ` Shaya Potter
2002-10-21 15:22   ` Alan Cox
2002-10-22  7:21     ` Ville Herva
2002-10-22 14:15       ` Shaya Potter [this message]
2002-10-22 15:55         ` Martin Josefsson
2002-10-16 21:14 ` David Wagner
2002-10-18 19:01 ` Pavel Machek
2002-10-18 20:14   ` David Wagner
2002-10-18 21:07     ` Shaya Potter
2002-10-18 21:00       ` David Wagner
2002-10-18 21:36         ` Shaya Potter
  -- strict thread matches above, loose matches on Subject: below --
2002-10-17  5:08 Niels Provos
2002-10-19 19:42 Hank Leininger
2002-10-20 10:40 ` Bernd Eckenfels
2002-10-20 14:49   ` Shaya Potter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1035296135.1089.35.camel@zaphod \
    --to=spotter@cs.columbia.edu \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vherva@niksula.hut.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox