From: Willy TARREAU <willy@w.ods.org>
To: marcelo@conectiva.com.br, viro@parcelfarce.linux.theplanet.co.uk
Cc: linux-kernel@vger.kernel.org
Subject: [RFC][PATCH-2.4] Prevent mounting on ".."
Date: Sun, 29 Jun 2003 15:09:52 +0200 [thread overview]
Message-ID: <20030629130952.GA246@pcw.home.local> (raw)
Hi Al and Marcelo,
while I was trying to get maximum restrictions on a chroot on 2.4.21-pre,
I found that it's always possible to mount a ramfs or a tmpfs on "..",
and then upload whatever I wanted in it. It's a shame because I was
trying to isolate network daemons inside empty, read-only file-systems,
and I discovered that this effort was worthless. To resume, imagine a
network daemon which does :
chroot("/var/empty") (read-only directory or file-system)
chdir("/")
listen(), accept(), fork(), whatever...
-> external code injection from a cracker :
mount("none", "..", "ramfs")
mkdir("../mydir")
chdir("../mydir")
the cracker now installs whatever he wants here.
The worst is that the new directory can even become invisible from all
other processes, so that the intruder has nothing to fear :-(
So I read fs/namei.c and fs/namespace.c, and found a way to prevent
this. Basically, the only case where it's still possible to mount
something on the current->fs->root now, is when the process wants to
remount the root fs, but no other mounts are allowed.
Since I'm really clueless about VFS code, I might have done it wrong,
or broken something, so I post this patch for comments. If everyone
agrees, I would really appreciate it if it was accepted in mainstream,
because it's a security problem IMHO.
It still applies to 2.5.66 with offset BTW.
Cheers,
Willy
--- linux-2.4.22-pre2/fs/namespace.c Sat May 10 11:36:02 2003
+++ linux-2.4.22-pre2-dotdot-mount/fs/namespace.c Sun Jun 29 14:38:16 2003
@@ -732,6 +732,10 @@
if (flags & MS_REMOUNT)
retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags,
data_page);
+ else if (nd.dentry == current->fs->root &&
+ nd.mnt == current->fs->rootmnt)
+ /* prevents someone from mounting on . or .. */
+ retval = -EINVAL;
else if (flags & MS_BIND)
retval = do_loopback(&nd, dev_name, flags & MS_REC);
else if (flags & MS_MOVE)
next reply other threads:[~2003-06-29 13:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-06-29 13:09 Willy TARREAU [this message]
2003-06-29 14:09 ` Arjan van de Ven
2003-06-29 14:24 ` Willy TARREAU
2003-06-29 14:11 ` viro
2003-06-29 14:20 ` Willy TARREAU
2003-06-29 14:27 ` viro
2003-06-29 14:35 ` Willy TARREAU
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=20030629130952.GA246@pcw.home.local \
--to=willy@w.ods.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcelo@conectiva.com.br \
--cc=viro@parcelfarce.linux.theplanet.co.uk \
/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
all inboxes | Powered by JetHome®