diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-12-16 18:53:03 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-12-16 18:53:03 -0500 |
| commit | 603ba7e41bf5d405aba22294af5d075d8898176d (patch) | |
| tree | fb9cf0b7c4912b5105f7da5efdd204cd0e66c8db /kernel | |
| parent | 31f48fc8f226f968d6e6b9b9718abe8e16c51fe8 (diff) | |
| parent | 93fe74b2e2b5d266d630f0c3f8287efcbe6ecd10 (diff) | |
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull vfs pile #2 from Al Viro:
"Next pile (and there'll be one or two more).
The large piece in this one is getting rid of /proc/*/ns/* weirdness;
among other things, it allows to (finally) make nameidata completely
opaque outside of fs/namei.c, making for easier further cleanups in
there"
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
coda_venus_readdir(): use file_inode()
fs/namei.c: fold link_path_walk() call into path_init()
path_init(): don't bother with LOOKUP_PARENT in argument
fs/namei.c: new helper (path_cleanup())
path_init(): store the "base" pointer to file in nameidata itself
make default ->i_fop have ->open() fail with ENXIO
make nameidata completely opaque outside of fs/namei.c
kill proc_ns completely
take the targets of /proc/*/ns/* symlinks to separate fs
bury struct proc_ns in fs/proc
copy address of proc_ns_ops into ns_common
new helpers: ns_alloc_inum/ns_free_inum
make proc_ns_operations work with struct ns_common * instead of void *
switch the rest of proc_ns_operations to working with &...->ns
netns: switch ->get()/->put()/->install()/->inum() to working with &net->ns
make mntns ->get()/->put()/->install()/->inum() work with &mnt_ns->ns
common object embedded into various struct ....ns
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/nsproxy.c | 10 | ||||
| -rw-r--r-- | kernel/pid.c | 5 | ||||
| -rw-r--r-- | kernel/pid_namespace.c | 29 | ||||
| -rw-r--r-- | kernel/user.c | 5 | ||||
| -rw-r--r-- | kernel/user_namespace.c | 29 | ||||
| -rw-r--r-- | kernel/utsname.c | 31 |
6 files changed, 55 insertions, 54 deletions
diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c index ef42d0ab3115..49746c81ad8d 100644 --- a/kernel/nsproxy.c +++ b/kernel/nsproxy.c | |||
| @@ -220,11 +220,10 @@ void exit_task_namespaces(struct task_struct *p) | |||
| 220 | 220 | ||
| 221 | SYSCALL_DEFINE2(setns, int, fd, int, nstype) | 221 | SYSCALL_DEFINE2(setns, int, fd, int, nstype) |
| 222 | { | 222 | { |
| 223 | const struct proc_ns_operations *ops; | ||
| 224 | struct task_struct *tsk = current; | 223 | struct task_struct *tsk = current; |
| 225 | struct nsproxy *new_nsproxy; | 224 | struct nsproxy *new_nsproxy; |
| 226 | struct proc_ns *ei; | ||
| 227 | struct file *file; | 225 | struct file *file; |
| 226 | struct ns_common *ns; | ||
| 228 | int err; | 227 | int err; |
| 229 | 228 | ||
| 230 | file = proc_ns_fget(fd); | 229 | file = proc_ns_fget(fd); |
| @@ -232,9 +231,8 @@ SYSCALL_DEFINE2(setns, int, fd, int, nstype) | |||
| 232 | return PTR_ERR(file); | 231 | return PTR_ERR(file); |
| 233 | 232 | ||
| 234 | err = -EINVAL; | 233 | err = -EINVAL; |
| 235 | ei = get_proc_ns(file_inode(file)); | 234 | ns = get_proc_ns(file_inode(file)); |
| 236 | ops = ei->ns_ops; | 235 | if (nstype && (ns->ops->type != nstype)) |
| 237 | if (nstype && (ops->type != nstype)) | ||
| 238 | goto out; | 236 | goto out; |
| 239 | 237 | ||
| 240 | new_nsproxy = create_new_namespaces(0, tsk, current_user_ns(), tsk->fs); | 238 | new_nsproxy = create_new_namespaces(0, tsk, current_user_ns(), tsk->fs); |
| @@ -243,7 +241,7 @@ SYSCALL_DEFINE2(setns, int, fd, int, nstype) | |||
| 243 | goto out; | 241 | goto out; |
| 244 | } | 242 | } |
| 245 | 243 | ||
| 246 | err = ops->install(new_nsproxy, ei->ns); | 244 | err = ns->ops->install(new_nsproxy, ns); |
| 247 | if (err) { | 245 | if (err) { |
| 248 | free_nsproxy(new_nsproxy); | 246 | free_nsproxy(new_nsproxy); |
| 249 | goto out; | 247 | goto out; |
diff --git a/kernel/pid.c b/kernel/pid.c index 82430c858d69..cd36a5e0d173 100644 --- a/kernel/pid.c +++ b/kernel/pid.c | |||
| @@ -79,7 +79,10 @@ struct pid_namespace init_pid_ns = { | |||
| 79 | .level = 0, | 79 | .level = 0, |
| 80 | .child_reaper = &init_task, | 80 | .child_reaper = &init_task, |
| 81 | .user_ns = &init_user_ns, | 81 | .user_ns = &init_user_ns, |
| 82 | .proc_inum = PROC_PID_INIT_INO, | 82 | .ns.inum = PROC_PID_INIT_INO, |
| 83 | #ifdef CONFIG_PID_NS | ||
| 84 | .ns.ops = &pidns_operations, | ||
| 85 | #endif | ||
| 83 | }; | 86 | }; |
| 84 | EXPORT_SYMBOL_GPL(init_pid_ns); | 87 | EXPORT_SYMBOL_GPL(init_pid_ns); |
| 85 | 88 | ||
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c index bc6d6a89b6e6..a65ba137fd15 100644 --- a/kernel/pid_namespace.c +++ b/kernel/pid_namespace.c | |||
| @@ -105,9 +105,10 @@ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns | |||
| 105 | if (ns->pid_cachep == NULL) | 105 | if (ns->pid_cachep == NULL) |
| 106 | goto out_free_map; | 106 | goto out_free_map; |
| 107 | 107 | ||
| 108 | err = proc_alloc_inum(&ns->proc_inum); | 108 | err = ns_alloc_inum(&ns->ns); |
| 109 | if (err) | 109 | if (err) |
| 110 | goto out_free_map; | 110 | goto out_free_map; |
| 111 | ns->ns.ops = &pidns_operations; | ||
| 111 | 112 | ||
| 112 | kref_init(&ns->kref); | 113 | kref_init(&ns->kref); |
| 113 | ns->level = level; | 114 | ns->level = level; |
| @@ -142,7 +143,7 @@ static void destroy_pid_namespace(struct pid_namespace *ns) | |||
| 142 | { | 143 | { |
| 143 | int i; | 144 | int i; |
| 144 | 145 | ||
| 145 | proc_free_inum(ns->proc_inum); | 146 | ns_free_inum(&ns->ns); |
| 146 | for (i = 0; i < PIDMAP_ENTRIES; i++) | 147 | for (i = 0; i < PIDMAP_ENTRIES; i++) |
| 147 | kfree(ns->pidmap[i].page); | 148 | kfree(ns->pidmap[i].page); |
| 148 | put_user_ns(ns->user_ns); | 149 | put_user_ns(ns->user_ns); |
| @@ -333,7 +334,12 @@ int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd) | |||
| 333 | return 0; | 334 | return 0; |
| 334 | } | 335 | } |
| 335 | 336 | ||
| 336 | static void *pidns_get(struct task_struct *task) | 337 | static inline struct pid_namespace *to_pid_ns(struct ns_common *ns) |
| 338 | { | ||
| 339 | return container_of(ns, struct pid_namespace, ns); | ||
| 340 | } | ||
| 341 | |||
| 342 | static struct ns_common *pidns_get(struct task_struct *task) | ||
| 337 | { | 343 | { |
| 338 | struct pid_namespace *ns; | 344 | struct pid_namespace *ns; |
| 339 | 345 | ||
| @@ -343,18 +349,18 @@ static void *pidns_get(struct task_struct *task) | |||
| 343 | get_pid_ns(ns); | 349 | get_pid_ns(ns); |
| 344 | rcu_read_unlock(); | 350 | rcu_read_unlock(); |
| 345 | 351 | ||
| 346 | return ns; | 352 | return ns ? &ns->ns : NULL; |
| 347 | } | 353 | } |
| 348 | 354 | ||
| 349 | static void pidns_put(void *ns) | 355 | static void pidns_put(struct ns_common *ns) |
| 350 | { | 356 | { |
| 351 | put_pid_ns(ns); | 357 | put_pid_ns(to_pid_ns(ns)); |
| 352 | } | 358 | } |
| 353 | 359 | ||
| 354 | static int pidns_install(struct nsproxy *nsproxy, void *ns) | 360 | static int pidns_install(struct nsproxy *nsproxy, struct ns_common *ns) |
| 355 | { | 361 | { |
| 356 | struct pid_namespace *active = task_active_pid_ns(current); | 362 | struct pid_namespace *active = task_active_pid_ns(current); |
| 357 | struct pid_namespace *ancestor, *new = ns; | 363 | struct pid_namespace *ancestor, *new = to_pid_ns(ns); |
| 358 | 364 | ||
| 359 | if (!ns_capable(new->user_ns, CAP_SYS_ADMIN) || | 365 | if (!ns_capable(new->user_ns, CAP_SYS_ADMIN) || |
| 360 | !ns_capable(current_user_ns(), CAP_SYS_ADMIN)) | 366 | !ns_capable(current_user_ns(), CAP_SYS_ADMIN)) |
| @@ -382,19 +388,12 @@ static int pidns_install(struct nsproxy *nsproxy, void *ns) | |||
| 382 | return 0; | 388 | return 0; |
| 383 | } | 389 | } |
| 384 | 390 | ||
| 385 | static unsigned int pidns_inum(void *ns) | ||
| 386 | { | ||
| 387 | struct pid_namespace *pid_ns = ns; | ||
| 388 | return pid_ns->proc_inum; | ||
| 389 | } | ||
| 390 | |||
| 391 | const struct proc_ns_operations pidns_operations = { | 391 | const struct proc_ns_operations pidns_operations = { |
| 392 | .name = "pid", | 392 | .name = "pid", |
| 393 | .type = CLONE_NEWPID, | 393 | .type = CLONE_NEWPID, |
| 394 | .get = pidns_get, | 394 | .get = pidns_get, |
| 395 | .put = pidns_put, | 395 | .put = pidns_put, |
| 396 | .install = pidns_install, | 396 | .install = pidns_install, |
| 397 | .inum = pidns_inum, | ||
| 398 | }; | 397 | }; |
| 399 | 398 | ||
| 400 | static __init int pid_namespaces_init(void) | 399 | static __init int pid_namespaces_init(void) |
diff --git a/kernel/user.c b/kernel/user.c index 4efa39350e44..69b800aebf13 100644 --- a/kernel/user.c +++ b/kernel/user.c | |||
| @@ -50,7 +50,10 @@ struct user_namespace init_user_ns = { | |||
| 50 | .count = ATOMIC_INIT(3), | 50 | .count = ATOMIC_INIT(3), |
| 51 | .owner = GLOBAL_ROOT_UID, | 51 | .owner = GLOBAL_ROOT_UID, |
| 52 | .group = GLOBAL_ROOT_GID, | 52 | .group = GLOBAL_ROOT_GID, |
| 53 | .proc_inum = PROC_USER_INIT_INO, | 53 | .ns.inum = PROC_USER_INIT_INO, |
| 54 | #ifdef CONFIG_USER_NS | ||
| 55 | .ns.ops = &userns_operations, | ||
| 56 | #endif | ||
| 54 | #ifdef CONFIG_PERSISTENT_KEYRINGS | 57 | #ifdef CONFIG_PERSISTENT_KEYRINGS |
| 55 | .persistent_keyring_register_sem = | 58 | .persistent_keyring_register_sem = |
| 56 | __RWSEM_INITIALIZER(init_user_ns.persistent_keyring_register_sem), | 59 | __RWSEM_INITIALIZER(init_user_ns.persistent_keyring_register_sem), |
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c index aa312b0dc3ec..1491ad00388f 100644 --- a/kernel/user_namespace.c +++ b/kernel/user_namespace.c | |||
| @@ -86,11 +86,12 @@ int create_user_ns(struct cred *new) | |||
| 86 | if (!ns) | 86 | if (!ns) |
| 87 | return -ENOMEM; | 87 | return -ENOMEM; |
| 88 | 88 | ||
| 89 | ret = proc_alloc_inum(&ns->proc_inum); | 89 | ret = ns_alloc_inum(&ns->ns); |
| 90 | if (ret) { | 90 | if (ret) { |
| 91 | kmem_cache_free(user_ns_cachep, ns); | 91 | kmem_cache_free(user_ns_cachep, ns); |
| 92 | return ret; | 92 | return ret; |
| 93 | } | 93 | } |
| 94 | ns->ns.ops = &userns_operations; | ||
| 94 | 95 | ||
| 95 | atomic_set(&ns->count, 1); | 96 | atomic_set(&ns->count, 1); |
| 96 | /* Leave the new->user_ns reference with the new user namespace. */ | 97 | /* Leave the new->user_ns reference with the new user namespace. */ |
| @@ -136,7 +137,7 @@ void free_user_ns(struct user_namespace *ns) | |||
| 136 | #ifdef CONFIG_PERSISTENT_KEYRINGS | 137 | #ifdef CONFIG_PERSISTENT_KEYRINGS |
| 137 | key_put(ns->persistent_keyring_register); | 138 | key_put(ns->persistent_keyring_register); |
| 138 | #endif | 139 | #endif |
| 139 | proc_free_inum(ns->proc_inum); | 140 | ns_free_inum(&ns->ns); |
| 140 | kmem_cache_free(user_ns_cachep, ns); | 141 | kmem_cache_free(user_ns_cachep, ns); |
| 141 | ns = parent; | 142 | ns = parent; |
| 142 | } while (atomic_dec_and_test(&parent->count)); | 143 | } while (atomic_dec_and_test(&parent->count)); |
| @@ -841,7 +842,12 @@ static bool new_idmap_permitted(const struct file *file, | |||
| 841 | return false; | 842 | return false; |
| 842 | } | 843 | } |
| 843 | 844 | ||
| 844 | static void *userns_get(struct task_struct *task) | 845 | static inline struct user_namespace *to_user_ns(struct ns_common *ns) |
| 846 | { | ||
| 847 | return container_of(ns, struct user_namespace, ns); | ||
| 848 | } | ||
| 849 | |||
| 850 | static struct ns_common *userns_get(struct task_struct *task) | ||
| 845 | { | 851 | { |
| 846 | struct user_namespace *user_ns; | 852 | struct user_namespace *user_ns; |
| 847 | 853 | ||
| @@ -849,17 +855,17 @@ static void *userns_get(struct task_struct *task) | |||
| 849 | user_ns = get_user_ns(__task_cred(task)->user_ns); | 855 | user_ns = get_user_ns(__task_cred(task)->user_ns); |
| 850 | rcu_read_unlock(); | 856 | rcu_read_unlock(); |
| 851 | 857 | ||
| 852 | return user_ns; | 858 | return user_ns ? &user_ns->ns : NULL; |
| 853 | } | 859 | } |
| 854 | 860 | ||
| 855 | static void userns_put(void *ns) | 861 | static void userns_put(struct ns_common *ns) |
| 856 | { | 862 | { |
| 857 | put_user_ns(ns); | 863 | put_user_ns(to_user_ns(ns)); |
| 858 | } | 864 | } |
| 859 | 865 | ||
| 860 | static int userns_install(struct nsproxy *nsproxy, void *ns) | 866 | static int userns_install(struct nsproxy *nsproxy, struct ns_common *ns) |
| 861 | { | 867 | { |
| 862 | struct user_namespace *user_ns = ns; | 868 | struct user_namespace *user_ns = to_user_ns(ns); |
| 863 | struct cred *cred; | 869 | struct cred *cred; |
| 864 | 870 | ||
| 865 | /* Don't allow gaining capabilities by reentering | 871 | /* Don't allow gaining capabilities by reentering |
| @@ -888,19 +894,12 @@ static int userns_install(struct nsproxy *nsproxy, void *ns) | |||
| 888 | return commit_creds(cred); | 894 | return commit_creds(cred); |
| 889 | } | 895 | } |
| 890 | 896 | ||
| 891 | static unsigned int userns_inum(void *ns) | ||
| 892 | { | ||
| 893 | struct user_namespace *user_ns = ns; | ||
| 894 | return user_ns->proc_inum; | ||
| 895 | } | ||
| 896 | |||
| 897 | const struct proc_ns_operations userns_operations = { | 897 | const struct proc_ns_operations userns_operations = { |
| 898 | .name = "user", | 898 | .name = "user", |
| 899 | .type = CLONE_NEWUSER, | 899 | .type = CLONE_NEWUSER, |
| 900 | .get = userns_get, | 900 | .get = userns_get, |
| 901 | .put = userns_put, | 901 | .put = userns_put, |
| 902 | .install = userns_install, | 902 | .install = userns_install, |
| 903 | .inum = userns_inum, | ||
| 904 | }; | 903 | }; |
| 905 | 904 | ||
| 906 | static __init int user_namespaces_init(void) | 905 | static __init int user_namespaces_init(void) |
diff --git a/kernel/utsname.c b/kernel/utsname.c index 883aaaa7de8a..831ea7108232 100644 --- a/kernel/utsname.c +++ b/kernel/utsname.c | |||
| @@ -42,12 +42,14 @@ static struct uts_namespace *clone_uts_ns(struct user_namespace *user_ns, | |||
| 42 | if (!ns) | 42 | if (!ns) |
| 43 | return ERR_PTR(-ENOMEM); | 43 | return ERR_PTR(-ENOMEM); |
| 44 | 44 | ||
| 45 | err = proc_alloc_inum(&ns->proc_inum); | 45 | err = ns_alloc_inum(&ns->ns); |
| 46 | if (err) { | 46 | if (err) { |
| 47 | kfree(ns); | 47 | kfree(ns); |
| 48 | return ERR_PTR(err); | 48 | return ERR_PTR(err); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | ns->ns.ops = &utsns_operations; | ||
| 52 | |||
| 51 | down_read(&uts_sem); | 53 | down_read(&uts_sem); |
| 52 | memcpy(&ns->name, &old_ns->name, sizeof(ns->name)); | 54 | memcpy(&ns->name, &old_ns->name, sizeof(ns->name)); |
| 53 | ns->user_ns = get_user_ns(user_ns); | 55 | ns->user_ns = get_user_ns(user_ns); |
| @@ -84,11 +86,16 @@ void free_uts_ns(struct kref *kref) | |||
| 84 | 86 | ||
| 85 | ns = container_of(kref, struct uts_namespace, kref); | 87 | ns = container_of(kref, struct uts_namespace, kref); |
| 86 | put_user_ns(ns->user_ns); | 88 | put_user_ns(ns->user_ns); |
| 87 | proc_free_inum(ns->proc_inum); | 89 | ns_free_inum(&ns->ns); |
| 88 | kfree(ns); | 90 | kfree(ns); |
| 89 | } | 91 | } |
| 90 | 92 | ||
| 91 | static void *utsns_get(struct task_struct *task) | 93 | static inline struct uts_namespace *to_uts_ns(struct ns_common *ns) |
| 94 | { | ||
| 95 | return container_of(ns, struct uts_namespace, ns); | ||
| 96 | } | ||
| 97 | |||
| 98 | static struct ns_common *utsns_get(struct task_struct *task) | ||
| 92 | { | 99 | { |
| 93 | struct uts_namespace *ns = NULL; | 100 | struct uts_namespace *ns = NULL; |
| 94 | struct nsproxy *nsproxy; | 101 | struct nsproxy *nsproxy; |
| @@ -101,17 +108,17 @@ static void *utsns_get(struct task_struct *task) | |||
| 101 | } | 108 | } |
| 102 | task_unlock(task); | 109 | task_unlock(task); |
| 103 | 110 | ||
| 104 | return ns; | 111 | return ns ? &ns->ns : NULL; |
| 105 | } | 112 | } |
| 106 | 113 | ||
| 107 | static void utsns_put(void *ns) | 114 | static void utsns_put(struct ns_common *ns) |
| 108 | { | 115 | { |
| 109 | put_uts_ns(ns); | 116 | put_uts_ns(to_uts_ns(ns)); |
| 110 | } | 117 | } |
| 111 | 118 | ||
| 112 | static int utsns_install(struct nsproxy *nsproxy, void *new) | 119 | static int utsns_install(struct nsproxy *nsproxy, struct ns_common *new) |
| 113 | { | 120 | { |
| 114 | struct uts_namespace *ns = new; | 121 | struct uts_namespace *ns = to_uts_ns(new); |
| 115 | 122 | ||
| 116 | if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN) || | 123 | if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN) || |
| 117 | !ns_capable(current_user_ns(), CAP_SYS_ADMIN)) | 124 | !ns_capable(current_user_ns(), CAP_SYS_ADMIN)) |
| @@ -123,18 +130,10 @@ static int utsns_install(struct nsproxy *nsproxy, void *new) | |||
| 123 | return 0; | 130 | return 0; |
| 124 | } | 131 | } |
| 125 | 132 | ||
| 126 | static unsigned int utsns_inum(void *vp) | ||
| 127 | { | ||
| 128 | struct uts_namespace *ns = vp; | ||
| 129 | |||
| 130 | return ns->proc_inum; | ||
| 131 | } | ||
| 132 | |||
| 133 | const struct proc_ns_operations utsns_operations = { | 133 | const struct proc_ns_operations utsns_operations = { |
| 134 | .name = "uts", | 134 | .name = "uts", |
| 135 | .type = CLONE_NEWUTS, | 135 | .type = CLONE_NEWUTS, |
| 136 | .get = utsns_get, | 136 | .get = utsns_get, |
| 137 | .put = utsns_put, | 137 | .put = utsns_put, |
| 138 | .install = utsns_install, | 138 | .install = utsns_install, |
| 139 | .inum = utsns_inum, | ||
| 140 | }; | 139 | }; |
