Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 346319
b: refs/heads/master
c: 0c55cfc
h: refs/heads/master
i:
  346317: 1ab8fbf
  346315: eac8aa8
  346311: af94264
  346303: b5eb86d
v: v3
  • Loading branch information
Eric W. Biederman committed Nov 19, 2012
1 parent cdd4906 commit fb16227
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 27 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 7a472ef4be8387bc05a42e16309b02c8ca943a40
refs/heads/master: 0c55cfc4166d9a0f38de779bd4d75a90afbe7734
69 changes: 43 additions & 26 deletions trunk/fs/namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
goto dput_and_out;

retval = -EPERM;
if (!capable(CAP_SYS_ADMIN))
if (!ns_capable(mnt->mnt_ns->user_ns, CAP_SYS_ADMIN))
goto dput_and_out;

retval = do_umount(mnt, flags);
Expand All @@ -1295,7 +1295,7 @@ SYSCALL_DEFINE1(oldumount, char __user *, name)

static int mount_is_safe(struct path *path)
{
if (capable(CAP_SYS_ADMIN))
if (ns_capable(real_mount(path->mnt)->mnt_ns->user_ns, CAP_SYS_ADMIN))
return 0;
return -EPERM;
#ifdef notyet
Expand Down Expand Up @@ -1633,7 +1633,7 @@ static int do_change_type(struct path *path, int flag)
int type;
int err = 0;

if (!capable(CAP_SYS_ADMIN))
if (!ns_capable(mnt->mnt_ns->user_ns, CAP_SYS_ADMIN))
return -EPERM;

if (path->dentry != path->mnt->mnt_root)
Expand Down Expand Up @@ -1797,7 +1797,7 @@ static int do_move_mount(struct path *path, const char *old_name)
struct mount *p;
struct mount *old;
int err = 0;
if (!capable(CAP_SYS_ADMIN))
if (!ns_capable(real_mount(path->mnt)->mnt_ns->user_ns, CAP_SYS_ADMIN))
return -EPERM;
if (!old_name || !*old_name)
return -EINVAL;
Expand Down Expand Up @@ -1884,21 +1884,6 @@ static struct vfsmount *fs_set_subtype(struct vfsmount *mnt, const char *fstype)
return ERR_PTR(err);
}

static struct vfsmount *
do_kern_mount(const char *fstype, int flags, const char *name, void *data)
{
struct file_system_type *type = get_fs_type(fstype);
struct vfsmount *mnt;
if (!type)
return ERR_PTR(-ENODEV);
mnt = vfs_kern_mount(type, flags, name, data);
if (!IS_ERR(mnt) && (type->fs_flags & FS_HAS_SUBTYPE) &&
!mnt->mnt_sb->s_subtype)
mnt = fs_set_subtype(mnt, fstype);
put_filesystem(type);
return mnt;
}

/*
* add a mount into a namespace's mount tree
*/
Expand Down Expand Up @@ -1944,20 +1929,46 @@ static int do_add_mount(struct mount *newmnt, struct path *path, int mnt_flags)
* create a new mount for userspace and request it to be added into the
* namespace's tree
*/
static int do_new_mount(struct path *path, const char *type, int flags,
static int do_new_mount(struct path *path, const char *fstype, int flags,
int mnt_flags, const char *name, void *data)
{
struct file_system_type *type;
struct user_namespace *user_ns;
struct vfsmount *mnt;
int err;

if (!type)
if (!fstype)
return -EINVAL;

/* we need capabilities... */
if (!capable(CAP_SYS_ADMIN))
user_ns = real_mount(path->mnt)->mnt_ns->user_ns;
if (!ns_capable(user_ns, CAP_SYS_ADMIN))
return -EPERM;

mnt = do_kern_mount(type, flags, name, data);
type = get_fs_type(fstype);
if (!type)
return -ENODEV;

if (user_ns != &init_user_ns) {
if (!(type->fs_flags & FS_USERNS_MOUNT)) {
put_filesystem(type);
return -EPERM;
}
/* Only in special cases allow devices from mounts
* created outside the initial user namespace.
*/
if (!(type->fs_flags & FS_USERNS_DEV_MOUNT)) {
flags |= MS_NODEV;
mnt_flags |= MNT_NODEV;
}
}

mnt = vfs_kern_mount(type, flags, name, data);
if (!IS_ERR(mnt) && (type->fs_flags & FS_HAS_SUBTYPE) &&
!mnt->mnt_sb->s_subtype)
mnt = fs_set_subtype(mnt, fstype);

put_filesystem(type);
if (IS_ERR(mnt))
return PTR_ERR(mnt);

Expand Down Expand Up @@ -2549,7 +2560,7 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
struct mount *new_mnt, *root_mnt;
int error;

if (!capable(CAP_SYS_ADMIN))
if (!ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN))
return -EPERM;

error = user_path_dir(new_root, &new);
Expand Down Expand Up @@ -2631,8 +2642,13 @@ static void __init init_mount_tree(void)
struct vfsmount *mnt;
struct mnt_namespace *ns;
struct path root;
struct file_system_type *type;

mnt = do_kern_mount("rootfs", 0, "rootfs", NULL);
type = get_fs_type("rootfs");
if (!type)
panic("Can't find rootfs type");
mnt = vfs_kern_mount(type, 0, "rootfs", NULL);
put_filesystem(type);
if (IS_ERR(mnt))
panic("Can't create rootfs");

Expand Down Expand Up @@ -2757,7 +2773,8 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
struct mnt_namespace *mnt_ns = ns;
struct path root;

if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_CHROOT))
if (!ns_capable(mnt_ns->user_ns, CAP_SYS_ADMIN) ||
!nsown_capable(CAP_SYS_CHROOT))
return -EINVAL;

if (fs->users != 1)
Expand Down
2 changes: 2 additions & 0 deletions trunk/include/linux/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1812,6 +1812,8 @@ struct file_system_type {
#define FS_REQUIRES_DEV 1
#define FS_BINARY_MOUNTDATA 2
#define FS_HAS_SUBTYPE 4
#define FS_USERNS_MOUNT 8 /* Can be mounted by userns root */
#define FS_USERNS_DEV_MOUNT 16 /* A userns mount does not imply MNT_NODEV */
#define FS_REVAL_DOT 16384 /* Check the paths ".", ".." for staleness */
#define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() during rename() internally. */
struct dentry *(*mount) (struct file_system_type *, int,
Expand Down

0 comments on commit fb16227

Please sign in to comment.