[patch 05/10] unprivileged mounts: allow unprivileged bind mounts

Previous thread: [patch 08/10] unprivileged mounts: allow unprivileged fuse mounts by Miklos Szeredi on Friday, April 27, 2007 - 8:04 am. (1 message)

Next thread: [GIT-PULL] please pull UBI tree by Artem Bityutskiy on Friday, April 27, 2007 - 8:45 am. (8 messages)
To: <akpm@...>, <serue@...>, <viro@...>, <linuxram@...>, <ebiederm@...>, <kzak@...>
Cc: <linux-fsdevel@...>, <linux-kernel@...>, <containers@...>
Date: Friday, April 27, 2007 - 8:04 am

From: Miklos Szeredi <mszeredi@suse.cz>

Allow bind mounts to unprivileged users if the following conditions are met:

- mountpoint is not a symlink
- parent mount is owned by the user
- the number of user mounts is below the maximum

Unprivileged mounts imply MS_SETUSER, and will also have the "nosuid" and
"nodev" mount flags set.

In particular, if mounting process doesn't have CAP_SETUID capability,
then the "nosuid" flag will be added, and if it doesn't have CAP_MKNOD
capability, then the "nodev" flag will be added.

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

Index: linux/fs/namespace.c
===================================================================
--- linux.orig/fs/namespace.c 2007-04-26 13:18:46.000000000 +0200
+++ linux/fs/namespace.c 2007-04-26 13:30:04.000000000 +0200
@@ -237,11 +237,34 @@ static void dec_nr_user_mounts(void)
spin_unlock(&vfsmount_lock);
}

-static void set_mnt_user(struct vfsmount *mnt)
+static int reserve_user_mount(void)
+{
+ int err = 0;
+
+ spin_lock(&vfsmount_lock);
+ if (nr_user_mounts >= max_user_mounts && !capable(CAP_SYS_ADMIN))
+ err = -EPERM;
+ else
+ nr_user_mounts++;
+ spin_unlock(&vfsmount_lock);
+ return err;
+}
+
+static void __set_mnt_user(struct vfsmount *mnt)
{
BUG_ON(mnt->mnt_flags & MNT_USER);
mnt->mnt_uid = current->fsuid;
mnt->mnt_flags |= MNT_USER;
+
+ if (!capable(CAP_SETUID))
+ mnt->mnt_flags |= MNT_NOSUID;
+ if (!capable(CAP_MKNOD))
+ mnt->mnt_flags |= MNT_NODEV;
+}
+
+static void set_mnt_user(struct vfsmount *mnt)
+{
+ __set_mnt_user(mnt);
spin_lock(&vfsmount_lock);
nr_user_mounts++;
spin_unlock(&vfsmount_lock);
@@ -260,10 +283,16 @@ static struct vfsmount *clone_mnt(struct
int flag)
{
struct super_block *sb = old->mnt_sb;
- struct vfsmount *mnt = alloc_vfsmnt(old->mnt_devname);
+ struct vfsmount *mnt;

+ if (flag & CL_SETUSER) {
+ int err = reserve_user_mount();
+ ...

Previous thread: [patch 08/10] unprivileged mounts: allow unprivileged fuse mounts by Miklos Szeredi on Friday, April 27, 2007 - 8:04 am. (1 message)

Next thread: [GIT-PULL] please pull UBI tree by Artem Bityutskiy on Friday, April 27, 2007 - 8:45 am. (8 messages)