Re: [patch 09/10] unprivileged mounts: propagation: inherit owner from parent

Previous thread: [patch 10/10] unprivileged mounts: add "no submounts" flag by Miklos Szeredi on Wednesday, January 16, 2008 - 8:31 am. (1 message)

Next thread: [patch 00/10] mount ownership and unprivileged mount syscall (v7) by Miklos Szeredi on Wednesday, January 16, 2008 - 8:31 am. (1 message)
To: <akpm@...>, <hch@...>, <serue@...>, <viro@...>, <kzak@...>
Cc: <linux-fsdevel@...>, <linux-kernel@...>, <containers@...>, <util-linux-ng@...>
Date: Wednesday, January 16, 2008 - 8:31 am

From: Miklos Szeredi <mszeredi@suse.cz>

On mount propagation, let the owner of the clone be inherited from the
parent into which it has been propagated.

If the parent has the "nosuid" flag, set this flag for the child as
well. This is needed for the suid-less namespace (use case #2 in the
first patch header), where all mounts are owned by the user and have
the nosuid flag set. In this case the propagated mount needs to have
nosuid, otherwise a suid executable may be misused by the user.

Similar treatment is not needed for "nodev", because devices can't be
abused this way: the user is not able to gain privileges to devices by
rearranging the mount namespace.

Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
---

Index: linux/fs/namespace.c
===================================================================
--- linux.orig/fs/namespace.c 2008-01-16 13:25:09.000000000 +0100
+++ linux/fs/namespace.c 2008-01-16 13:25:11.000000000 +0100
@@ -506,10 +506,10 @@ static int reserve_user_mount(void)
return err;
}

-static void __set_mnt_user(struct vfsmount *mnt)
+static void __set_mnt_user(struct vfsmount *mnt, uid_t owner)
{
WARN_ON(mnt->mnt_flags & MNT_USER);
- mnt->mnt_uid = current->fsuid;
+ mnt->mnt_uid = owner;
mnt->mnt_flags |= MNT_USER;

if (!capable(CAP_SETUID))
@@ -520,7 +520,7 @@ static void __set_mnt_user(struct vfsmou

static void set_mnt_user(struct vfsmount *mnt)
{
- __set_mnt_user(mnt);
+ __set_mnt_user(mnt, current->fsuid);
spin_lock(&vfsmount_lock);
nr_user_mounts++;
spin_unlock(&vfsmount_lock);
@@ -536,7 +536,7 @@ static void clear_mnt_user(struct vfsmou
}

static struct vfsmount *clone_mnt(struct vfsmount *old, struct dentry *root,
- int flag)
+ int flag, uid_t owner)
{
struct super_block *sb = old->mnt_sb;
struct vfsmount *mnt;
@@ -560,7 +560,10 @@ static struct vfsmount *clone_mnt(struct
/* don't copy the MNT_USER flag */
mnt->mnt_flags &= ~MNT_USER;
...

To: Miklos Szeredi <miklos@...>
Cc: <akpm@...>, <hch@...>, <serue@...>, <viro@...>, <kzak@...>, <linux-fsdevel@...>, <linux-kernel@...>, <containers@...>, <util-linux-ng@...>
Date: Monday, January 21, 2008 - 4:23 pm

As discussed many months ago this does seem like the most appropriate
behavior for propagation.

--

Previous thread: [patch 10/10] unprivileged mounts: add "no submounts" flag by Miklos Szeredi on Wednesday, January 16, 2008 - 8:31 am. (1 message)

Next thread: [patch 00/10] mount ownership and unprivileged mount syscall (v7) by Miklos Szeredi on Wednesday, January 16, 2008 - 8:31 am. (1 message)