diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2015-05-09 00:22:29 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2015-07-21 13:10:01 -0400 |
commit | b5eb51f2ee063044401492650e9e01bb35974870 (patch) | |
tree | 111e5f73c54f26603d577e05c0d1726f6bc04b84 | |
parent | 8e7c56b6f14d1388d5aa2feb5b28dd6360199cef (diff) |
mnt: Refactor the logic for mounting sysfs and proc in a user namespace
commit 1b852bceb0d111e510d1a15826ecc4a19358d512 upstream.
Fresh mounts of proc and sysfs are a very special case that works very
much like a bind mount. Unfortunately the current structure can not
preserve the MNT_LOCK... mount flags. Therefore refactor the logic
into a form that can be modified to preserve those lock bits.
Add a new filesystem flag FS_USERNS_VISIBLE that requires some mount
of the filesystem be fully visible in the current mount namespace,
before the filesystem may be mounted.
Move the logic for calling fs_fully_visible from proc and sysfs into
fs/namespace.c where it has greater access to mount namespace state.
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | fs/namespace.c | 8 | ||||
-rw-r--r-- | fs/proc/root.c | 5 | ||||
-rw-r--r-- | fs/sysfs/mount.c | 5 | ||||
-rw-r--r-- | include/linux/fs.h | 2 |
4 files changed, 10 insertions, 10 deletions
diff --git a/fs/namespace.c b/fs/namespace.c index c40b48cd7647..50a0d950404c 100644 --- a/fs/namespace.c +++ b/fs/namespace.c | |||
@@ -2332,6 +2332,8 @@ unlock: | |||
2332 | return err; | 2332 | return err; |
2333 | } | 2333 | } |
2334 | 2334 | ||
2335 | static bool fs_fully_visible(struct file_system_type *fs_type); | ||
2336 | |||
2335 | /* | 2337 | /* |
2336 | * create a new mount for userspace and request it to be added into the | 2338 | * create a new mount for userspace and request it to be added into the |
2337 | * namespace's tree | 2339 | * namespace's tree |
@@ -2363,6 +2365,10 @@ static int do_new_mount(struct path *path, const char *fstype, int flags, | |||
2363 | flags |= MS_NODEV; | 2365 | flags |= MS_NODEV; |
2364 | mnt_flags |= MNT_NODEV | MNT_LOCK_NODEV; | 2366 | mnt_flags |= MNT_NODEV | MNT_LOCK_NODEV; |
2365 | } | 2367 | } |
2368 | if (type->fs_flags & FS_USERNS_VISIBLE) { | ||
2369 | if (!fs_fully_visible(type)) | ||
2370 | return -EPERM; | ||
2371 | } | ||
2366 | } | 2372 | } |
2367 | 2373 | ||
2368 | mnt = vfs_kern_mount(type, flags, name, data); | 2374 | mnt = vfs_kern_mount(type, flags, name, data); |
@@ -3164,7 +3170,7 @@ bool current_chrooted(void) | |||
3164 | return chrooted; | 3170 | return chrooted; |
3165 | } | 3171 | } |
3166 | 3172 | ||
3167 | bool fs_fully_visible(struct file_system_type *type) | 3173 | static bool fs_fully_visible(struct file_system_type *type) |
3168 | { | 3174 | { |
3169 | struct mnt_namespace *ns = current->nsproxy->mnt_ns; | 3175 | struct mnt_namespace *ns = current->nsproxy->mnt_ns; |
3170 | struct mount *mnt; | 3176 | struct mount *mnt; |
diff --git a/fs/proc/root.c b/fs/proc/root.c index 3d987dfdef83..68feb0f70e63 100644 --- a/fs/proc/root.c +++ b/fs/proc/root.c | |||
@@ -112,9 +112,6 @@ static struct dentry *proc_mount(struct file_system_type *fs_type, | |||
112 | ns = task_active_pid_ns(current); | 112 | ns = task_active_pid_ns(current); |
113 | options = data; | 113 | options = data; |
114 | 114 | ||
115 | if (!capable(CAP_SYS_ADMIN) && !fs_fully_visible(fs_type)) | ||
116 | return ERR_PTR(-EPERM); | ||
117 | |||
118 | /* Does the mounter have privilege over the pid namespace? */ | 115 | /* Does the mounter have privilege over the pid namespace? */ |
119 | if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN)) | 116 | if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN)) |
120 | return ERR_PTR(-EPERM); | 117 | return ERR_PTR(-EPERM); |
@@ -159,7 +156,7 @@ static struct file_system_type proc_fs_type = { | |||
159 | .name = "proc", | 156 | .name = "proc", |
160 | .mount = proc_mount, | 157 | .mount = proc_mount, |
161 | .kill_sb = proc_kill_sb, | 158 | .kill_sb = proc_kill_sb, |
162 | .fs_flags = FS_USERNS_MOUNT, | 159 | .fs_flags = FS_USERNS_VISIBLE | FS_USERNS_MOUNT, |
163 | }; | 160 | }; |
164 | 161 | ||
165 | void __init proc_root_init(void) | 162 | void __init proc_root_init(void) |
diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c index 8a49486bf30c..1c6ac6fcee9f 100644 --- a/fs/sysfs/mount.c +++ b/fs/sysfs/mount.c | |||
@@ -31,9 +31,6 @@ static struct dentry *sysfs_mount(struct file_system_type *fs_type, | |||
31 | bool new_sb; | 31 | bool new_sb; |
32 | 32 | ||
33 | if (!(flags & MS_KERNMOUNT)) { | 33 | if (!(flags & MS_KERNMOUNT)) { |
34 | if (!capable(CAP_SYS_ADMIN) && !fs_fully_visible(fs_type)) | ||
35 | return ERR_PTR(-EPERM); | ||
36 | |||
37 | if (!kobj_ns_current_may_mount(KOBJ_NS_TYPE_NET)) | 34 | if (!kobj_ns_current_may_mount(KOBJ_NS_TYPE_NET)) |
38 | return ERR_PTR(-EPERM); | 35 | return ERR_PTR(-EPERM); |
39 | } | 36 | } |
@@ -58,7 +55,7 @@ static struct file_system_type sysfs_fs_type = { | |||
58 | .name = "sysfs", | 55 | .name = "sysfs", |
59 | .mount = sysfs_mount, | 56 | .mount = sysfs_mount, |
60 | .kill_sb = sysfs_kill_sb, | 57 | .kill_sb = sysfs_kill_sb, |
61 | .fs_flags = FS_USERNS_MOUNT, | 58 | .fs_flags = FS_USERNS_VISIBLE | FS_USERNS_MOUNT, |
62 | }; | 59 | }; |
63 | 60 | ||
64 | int __init sysfs_init(void) | 61 | int __init sysfs_init(void) |
diff --git a/include/linux/fs.h b/include/linux/fs.h index 0d5ae7d5dc53..571aab91bfc0 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h | |||
@@ -1897,6 +1897,7 @@ struct file_system_type { | |||
1897 | #define FS_HAS_SUBTYPE 4 | 1897 | #define FS_HAS_SUBTYPE 4 |
1898 | #define FS_USERNS_MOUNT 8 /* Can be mounted by userns root */ | 1898 | #define FS_USERNS_MOUNT 8 /* Can be mounted by userns root */ |
1899 | #define FS_USERNS_DEV_MOUNT 16 /* A userns mount does not imply MNT_NODEV */ | 1899 | #define FS_USERNS_DEV_MOUNT 16 /* A userns mount does not imply MNT_NODEV */ |
1900 | #define FS_USERNS_VISIBLE 32 /* FS must already be visible */ | ||
1900 | #define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() during rename() internally. */ | 1901 | #define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() during rename() internally. */ |
1901 | struct dentry *(*mount) (struct file_system_type *, int, | 1902 | struct dentry *(*mount) (struct file_system_type *, int, |
1902 | const char *, void *); | 1903 | const char *, void *); |
@@ -1984,7 +1985,6 @@ extern int vfs_ustat(dev_t, struct kstatfs *); | |||
1984 | extern int freeze_super(struct super_block *super); | 1985 | extern int freeze_super(struct super_block *super); |
1985 | extern int thaw_super(struct super_block *super); | 1986 | extern int thaw_super(struct super_block *super); |
1986 | extern bool our_mnt(struct vfsmount *mnt); | 1987 | extern bool our_mnt(struct vfsmount *mnt); |
1987 | extern bool fs_fully_visible(struct file_system_type *); | ||
1988 | 1988 | ||
1989 | extern int current_umask(void); | 1989 | extern int current_umask(void); |
1990 | 1990 | ||