Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge patch series "ns: rework common initialization"

Christian Brauner <brauner@kernel.org> says:

The current scheme still involves a lot of open-coding and copy-pasing
and bleeds a lot of unnecessary details into actual namespace
implementers. Encapsulate it in the common helpers and simplify it all.

* patches from https://lore.kernel.org/20250917-work-namespace-ns_common-v1-0-1b3bda8ef8f2@kernel.org:
ns: add ns_common_free()
nscommon: simplify initialization
net: centralize ns_common initialization
mnt: simplify ns_common_init() handling
nsfs: add inode number for anon namespace
cgroup: split namespace into separate header
nscommon: move to separate file
mnt: expose pointer to init_mnt_ns
uts: split namespace into separate header

Signed-off-by: Christian Brauner <brauner@kernel.org>

+235 -178
+22 -14
fs/namespace.c
··· 4082 4082 static void free_mnt_ns(struct mnt_namespace *ns) 4083 4083 { 4084 4084 if (!is_anon_ns(ns)) 4085 - ns_free_inum(&ns->ns); 4085 + ns_common_free(ns); 4086 4086 dec_mnt_namespaces(ns->ucounts); 4087 4087 mnt_ns_tree_remove(ns); 4088 4088 } ··· 4103 4103 return ERR_PTR(-ENOMEM); 4104 4104 } 4105 4105 4106 - ret = ns_common_init(&new_ns->ns, &mntns_operations, !anon); 4106 + if (anon) 4107 + ret = ns_common_init_inum(new_ns, &mntns_operations, MNT_NS_ANON_INO); 4108 + else 4109 + ret = ns_common_init(new_ns, &mntns_operations); 4107 4110 if (ret) { 4108 4111 kfree(new_ns); 4109 4112 dec_mnt_namespaces(ucounts); ··· 4154 4151 new = copy_tree(old, old->mnt.mnt_root, copy_flags); 4155 4152 if (IS_ERR(new)) { 4156 4153 namespace_unlock(); 4157 - ns_free_inum(&new_ns->ns); 4154 + ns_common_free(ns); 4158 4155 dec_mnt_namespaces(new_ns->ucounts); 4159 4156 mnt_ns_release(new_ns); 4160 4157 return ERR_CAST(new); ··· 6011 6008 return ret; 6012 6009 } 6013 6010 6011 + struct mnt_namespace init_mnt_ns = { 6012 + .ns.inum = PROC_MNT_INIT_INO, 6013 + .ns.ops = &mntns_operations, 6014 + .user_ns = &init_user_ns, 6015 + .ns.count = REFCOUNT_INIT(1), 6016 + .passive = REFCOUNT_INIT(1), 6017 + .mounts = RB_ROOT, 6018 + .poll = __WAIT_QUEUE_HEAD_INITIALIZER(init_mnt_ns.poll), 6019 + }; 6020 + 6014 6021 static void __init init_mount_tree(void) 6015 6022 { 6016 6023 struct vfsmount *mnt; 6017 6024 struct mount *m; 6018 - struct mnt_namespace *ns; 6019 6025 struct path root; 6020 6026 6021 6027 mnt = vfs_kern_mount(&rootfs_fs_type, 0, "rootfs", NULL); 6022 6028 if (IS_ERR(mnt)) 6023 6029 panic("Can't create rootfs"); 6024 6030 6025 - ns = alloc_mnt_ns(&init_user_ns, true); 6026 - if (IS_ERR(ns)) 6027 - panic("Can't allocate initial namespace"); 6028 - ns->ns.inum = PROC_MNT_INIT_INO; 6029 6031 m = real_mount(mnt); 6030 - ns->root = m; 6031 - ns->nr_mounts = 1; 6032 - mnt_add_to_ns(ns, m); 6033 - init_task.nsproxy->mnt_ns = ns; 6034 - get_mnt_ns(ns); 6032 + init_mnt_ns.root = m; 6033 + init_mnt_ns.nr_mounts = 1; 6034 + mnt_add_to_ns(&init_mnt_ns, m); 6035 + init_task.nsproxy->mnt_ns = &init_mnt_ns; 6036 + get_mnt_ns(&init_mnt_ns); 6035 6037 6036 6038 root.mnt = mnt; 6037 6039 root.dentry = mnt->mnt_root; ··· 6044 6036 set_fs_pwd(current->fs, &root); 6045 6037 set_fs_root(current->fs, &root); 6046 6038 6047 - ns_tree_add(ns); 6039 + ns_tree_add(&init_mnt_ns); 6048 6040 } 6049 6041 6050 6042 void __init mnt_init(void)
+1 -50
include/linux/cgroup.h
··· 27 27 #include <linux/kernel_stat.h> 28 28 29 29 #include <linux/cgroup-defs.h> 30 + #include <linux/cgroup_namespace.h> 30 31 31 32 struct kernel_clone_args; 32 33 ··· 784 783 785 784 #endif /* CONFIG_CGROUP_DATA */ 786 785 787 - struct cgroup_namespace { 788 - struct ns_common ns; 789 - struct user_namespace *user_ns; 790 - struct ucounts *ucounts; 791 - struct css_set *root_cset; 792 - }; 793 - 794 - extern struct cgroup_namespace init_cgroup_ns; 795 - 796 - #ifdef CONFIG_CGROUPS 797 - 798 - static inline struct cgroup_namespace *to_cg_ns(struct ns_common *ns) 799 - { 800 - return container_of(ns, struct cgroup_namespace, ns); 801 - } 802 - 803 - void free_cgroup_ns(struct cgroup_namespace *ns); 804 - 805 - struct cgroup_namespace *copy_cgroup_ns(unsigned long flags, 806 - struct user_namespace *user_ns, 807 - struct cgroup_namespace *old_ns); 808 - 809 - int cgroup_path_ns(struct cgroup *cgrp, char *buf, size_t buflen, 810 - struct cgroup_namespace *ns); 811 - 812 - static inline void get_cgroup_ns(struct cgroup_namespace *ns) 813 - { 814 - refcount_inc(&ns->ns.count); 815 - } 816 - 817 - static inline void put_cgroup_ns(struct cgroup_namespace *ns) 818 - { 819 - if (refcount_dec_and_test(&ns->ns.count)) 820 - free_cgroup_ns(ns); 821 - } 822 - 823 - #else /* !CONFIG_CGROUPS */ 824 - 825 - static inline void free_cgroup_ns(struct cgroup_namespace *ns) { } 826 - static inline struct cgroup_namespace * 827 - copy_cgroup_ns(unsigned long flags, struct user_namespace *user_ns, 828 - struct cgroup_namespace *old_ns) 829 - { 830 - return old_ns; 831 - } 832 - 833 - static inline void get_cgroup_ns(struct cgroup_namespace *ns) { } 834 - static inline void put_cgroup_ns(struct cgroup_namespace *ns) { } 835 - 836 - #endif /* !CONFIG_CGROUPS */ 837 786 838 787 #ifdef CONFIG_CGROUPS 839 788
+56
include/linux/cgroup_namespace.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _LINUX_CGROUP_NAMESPACE_H 3 + #define _LINUX_CGROUP_NAMESPACE_H 4 + 5 + struct cgroup_namespace { 6 + struct ns_common ns; 7 + struct user_namespace *user_ns; 8 + struct ucounts *ucounts; 9 + struct css_set *root_cset; 10 + }; 11 + 12 + extern struct cgroup_namespace init_cgroup_ns; 13 + 14 + #ifdef CONFIG_CGROUPS 15 + 16 + static inline struct cgroup_namespace *to_cg_ns(struct ns_common *ns) 17 + { 18 + return container_of(ns, struct cgroup_namespace, ns); 19 + } 20 + 21 + void free_cgroup_ns(struct cgroup_namespace *ns); 22 + 23 + struct cgroup_namespace *copy_cgroup_ns(unsigned long flags, 24 + struct user_namespace *user_ns, 25 + struct cgroup_namespace *old_ns); 26 + 27 + int cgroup_path_ns(struct cgroup *cgrp, char *buf, size_t buflen, 28 + struct cgroup_namespace *ns); 29 + 30 + static inline void get_cgroup_ns(struct cgroup_namespace *ns) 31 + { 32 + refcount_inc(&ns->ns.count); 33 + } 34 + 35 + static inline void put_cgroup_ns(struct cgroup_namespace *ns) 36 + { 37 + if (refcount_dec_and_test(&ns->ns.count)) 38 + free_cgroup_ns(ns); 39 + } 40 + 41 + #else /* !CONFIG_CGROUPS */ 42 + 43 + static inline void free_cgroup_ns(struct cgroup_namespace *ns) { } 44 + static inline struct cgroup_namespace * 45 + copy_cgroup_ns(unsigned long flags, struct user_namespace *user_ns, 46 + struct cgroup_namespace *old_ns) 47 + { 48 + return old_ns; 49 + } 50 + 51 + static inline void get_cgroup_ns(struct cgroup_namespace *ns) { } 52 + static inline void put_cgroup_ns(struct cgroup_namespace *ns) { } 53 + 54 + #endif /* !CONFIG_CGROUPS */ 55 + 56 + #endif /* _LINUX_CGROUP_NAMESPACE_H */
+2
include/linux/mnt_namespace.h
··· 11 11 struct user_namespace; 12 12 struct ns_common; 13 13 14 + extern struct mnt_namespace init_mnt_ns; 15 + 14 16 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *, 15 17 struct user_namespace *, struct fs_struct *); 16 18 extern void put_mnt_ns(struct mnt_namespace *ns);
+41
include/linux/ns_common.h
··· 16 16 struct user_namespace; 17 17 struct uts_namespace; 18 18 19 + extern struct cgroup_namespace init_cgroup_ns; 20 + extern struct ipc_namespace init_ipc_ns; 21 + extern struct mnt_namespace init_mnt_ns; 22 + extern struct net init_net; 23 + extern struct pid_namespace init_pid_ns; 24 + extern struct time_namespace init_time_ns; 25 + extern struct user_namespace init_user_ns; 26 + extern struct uts_namespace init_uts_ns; 27 + 19 28 struct ns_common { 20 29 struct dentry *stashed; 21 30 const struct proc_ns_operations *ops; ··· 40 31 }; 41 32 }; 42 33 34 + int __ns_common_init(struct ns_common *ns, const struct proc_ns_operations *ops, int inum); 35 + void __ns_common_free(struct ns_common *ns); 36 + 43 37 #define to_ns_common(__ns) \ 44 38 _Generic((__ns), \ 45 39 struct cgroup_namespace *: &(__ns)->ns, \ ··· 53 41 struct time_namespace *: &(__ns)->ns, \ 54 42 struct user_namespace *: &(__ns)->ns, \ 55 43 struct uts_namespace *: &(__ns)->ns) 44 + 45 + #define ns_init_inum(__ns) \ 46 + _Generic((__ns), \ 47 + struct cgroup_namespace *: CGROUP_NS_INIT_INO, \ 48 + struct ipc_namespace *: IPC_NS_INIT_INO, \ 49 + struct mnt_namespace *: MNT_NS_INIT_INO, \ 50 + struct net *: NET_NS_INIT_INO, \ 51 + struct pid_namespace *: PID_NS_INIT_INO, \ 52 + struct time_namespace *: TIME_NS_INIT_INO, \ 53 + struct user_namespace *: USER_NS_INIT_INO, \ 54 + struct uts_namespace *: UTS_NS_INIT_INO) 55 + 56 + #define ns_init_ns(__ns) \ 57 + _Generic((__ns), \ 58 + struct cgroup_namespace *: &init_cgroup_ns, \ 59 + struct ipc_namespace *: &init_ipc_ns, \ 60 + struct mnt_namespace *: &init_mnt_ns, \ 61 + struct net *: &init_net, \ 62 + struct pid_namespace *: &init_pid_ns, \ 63 + struct time_namespace *: &init_time_ns, \ 64 + struct user_namespace *: &init_user_ns, \ 65 + struct uts_namespace *: &init_uts_ns) 66 + 67 + #define ns_common_init(__ns, __ops) \ 68 + __ns_common_init(to_ns_common(__ns), __ops, (((__ns) == ns_init_ns(__ns)) ? ns_init_inum(__ns) : 0)) 69 + 70 + #define ns_common_init_inum(__ns, __ops, __inum) __ns_common_init(to_ns_common(__ns), __ops, __inum) 71 + 72 + #define ns_common_free(__ns) __ns_common_free(to_ns_common((__ns))) 56 73 57 74 #endif
-21
include/linux/proc_ns.h
··· 66 66 67 67 #endif /* CONFIG_PROC_FS */ 68 68 69 - static inline int ns_common_init(struct ns_common *ns, 70 - const struct proc_ns_operations *ops, 71 - bool alloc_inum) 72 - { 73 - if (alloc_inum) { 74 - int ret; 75 - ret = proc_alloc_inum(&ns->inum); 76 - if (ret) 77 - return ret; 78 - } 79 - refcount_set(&ns->count, 1); 80 - ns->stashed = NULL; 81 - ns->ops = ops; 82 - ns->ns_id = 0; 83 - RB_CLEAR_NODE(&ns->ns_tree_node); 84 - INIT_LIST_HEAD(&ns->ns_list_node); 85 - return 0; 86 - } 87 - 88 - #define ns_free_inum(ns) proc_free_inum((ns)->inum) 89 - 90 69 #define get_proc_ns(inode) ((struct ns_common *)(inode)->i_private) 91 70 92 71 #endif /* _LINUX_PROC_NS_H */
+65
include/linux/uts_namespace.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _LINUX_UTS_NAMESPACE_H 3 + #define _LINUX_UTS_NAMESPACE_H 4 + 5 + #include <linux/ns_common.h> 6 + #include <uapi/linux/utsname.h> 7 + 8 + struct user_namespace; 9 + extern struct user_namespace init_user_ns; 10 + 11 + struct uts_namespace { 12 + struct new_utsname name; 13 + struct user_namespace *user_ns; 14 + struct ucounts *ucounts; 15 + struct ns_common ns; 16 + } __randomize_layout; 17 + 18 + extern struct uts_namespace init_uts_ns; 19 + 20 + #ifdef CONFIG_UTS_NS 21 + static inline struct uts_namespace *to_uts_ns(struct ns_common *ns) 22 + { 23 + return container_of(ns, struct uts_namespace, ns); 24 + } 25 + 26 + static inline void get_uts_ns(struct uts_namespace *ns) 27 + { 28 + refcount_inc(&ns->ns.count); 29 + } 30 + 31 + extern struct uts_namespace *copy_utsname(unsigned long flags, 32 + struct user_namespace *user_ns, struct uts_namespace *old_ns); 33 + extern void free_uts_ns(struct uts_namespace *ns); 34 + 35 + static inline void put_uts_ns(struct uts_namespace *ns) 36 + { 37 + if (refcount_dec_and_test(&ns->ns.count)) 38 + free_uts_ns(ns); 39 + } 40 + 41 + void uts_ns_init(void); 42 + #else 43 + static inline void get_uts_ns(struct uts_namespace *ns) 44 + { 45 + } 46 + 47 + static inline void put_uts_ns(struct uts_namespace *ns) 48 + { 49 + } 50 + 51 + static inline struct uts_namespace *copy_utsname(unsigned long flags, 52 + struct user_namespace *user_ns, struct uts_namespace *old_ns) 53 + { 54 + if (flags & CLONE_NEWUTS) 55 + return ERR_PTR(-EINVAL); 56 + 57 + return old_ns; 58 + } 59 + 60 + static inline void uts_ns_init(void) 61 + { 62 + } 63 + #endif 64 + 65 + #endif /* _LINUX_UTS_NAMESPACE_H */
+1 -57
include/linux/utsname.h
··· 7 7 #include <linux/nsproxy.h> 8 8 #include <linux/ns_common.h> 9 9 #include <linux/err.h> 10 - #include <uapi/linux/utsname.h> 10 + #include <linux/uts_namespace.h> 11 11 12 12 enum uts_proc { 13 13 UTS_PROC_ARCH, ··· 17 17 UTS_PROC_HOSTNAME, 18 18 UTS_PROC_DOMAINNAME, 19 19 }; 20 - 21 - struct user_namespace; 22 - extern struct user_namespace init_user_ns; 23 - 24 - struct uts_namespace { 25 - struct new_utsname name; 26 - struct user_namespace *user_ns; 27 - struct ucounts *ucounts; 28 - struct ns_common ns; 29 - } __randomize_layout; 30 - extern struct uts_namespace init_uts_ns; 31 - 32 - #ifdef CONFIG_UTS_NS 33 - static inline struct uts_namespace *to_uts_ns(struct ns_common *ns) 34 - { 35 - return container_of(ns, struct uts_namespace, ns); 36 - } 37 - 38 - static inline void get_uts_ns(struct uts_namespace *ns) 39 - { 40 - refcount_inc(&ns->ns.count); 41 - } 42 - 43 - extern struct uts_namespace *copy_utsname(unsigned long flags, 44 - struct user_namespace *user_ns, struct uts_namespace *old_ns); 45 - extern void free_uts_ns(struct uts_namespace *ns); 46 - 47 - static inline void put_uts_ns(struct uts_namespace *ns) 48 - { 49 - if (refcount_dec_and_test(&ns->ns.count)) 50 - free_uts_ns(ns); 51 - } 52 - 53 - void uts_ns_init(void); 54 - #else 55 - static inline void get_uts_ns(struct uts_namespace *ns) 56 - { 57 - } 58 - 59 - static inline void put_uts_ns(struct uts_namespace *ns) 60 - { 61 - } 62 - 63 - static inline struct uts_namespace *copy_utsname(unsigned long flags, 64 - struct user_namespace *user_ns, struct uts_namespace *old_ns) 65 - { 66 - if (flags & CLONE_NEWUTS) 67 - return ERR_PTR(-EINVAL); 68 - 69 - return old_ns; 70 - } 71 - 72 - static inline void uts_ns_init(void) 73 - { 74 - } 75 - #endif 76 20 77 21 #ifdef CONFIG_PROC_SYSCTL 78 22 extern void uts_proc_notify(enum uts_proc proc);
+3
include/uapi/linux/nsfs.h
··· 53 53 TIME_NS_INIT_INO = 0xEFFFFFFAU, 54 54 NET_NS_INIT_INO = 0xEFFFFFF9U, 55 55 MNT_NS_INIT_INO = 0xEFFFFFF8U, 56 + #ifdef __KERNEL__ 57 + MNT_NS_ANON_INO = 0xEFFFFFF7U, 58 + #endif 56 59 }; 57 60 58 61 struct nsfs_file_handle {
+3 -3
ipc/namespace.c
··· 62 62 if (ns == NULL) 63 63 goto fail_dec; 64 64 65 - err = ns_common_init(&ns->ns, &ipcns_operations, true); 65 + err = ns_common_init(ns, &ipcns_operations); 66 66 if (err) 67 67 goto fail_free; 68 68 ··· 97 97 98 98 fail_put: 99 99 put_user_ns(ns->user_ns); 100 - ns_free_inum(&ns->ns); 100 + ns_common_free(ns); 101 101 fail_free: 102 102 kfree(ns); 103 103 fail_dec: ··· 161 161 162 162 dec_ipc_namespaces(ns->ucounts); 163 163 put_user_ns(ns->user_ns); 164 - ns_free_inum(&ns->ns); 164 + ns_common_free(ns); 165 165 kfree(ns); 166 166 } 167 167
+1 -1
kernel/Makefile
··· 8 8 sysctl.o capability.o ptrace.o user.o \ 9 9 signal.o sys.o umh.o workqueue.o pid.o task_work.o \ 10 10 extable.o params.o \ 11 - kthread.o sys_ni.o nsproxy.o nstree.o \ 11 + kthread.o sys_ni.o nsproxy.o nstree.o nscommon.o \ 12 12 notifier.o ksysfs.o cred.o reboot.o \ 13 13 async.o range.o smpboot.o ucount.o regset.o ksyms_common.o 14 14
+2 -2
kernel/cgroup/namespace.c
··· 27 27 new_ns = kzalloc(sizeof(struct cgroup_namespace), GFP_KERNEL_ACCOUNT); 28 28 if (!new_ns) 29 29 return ERR_PTR(-ENOMEM); 30 - ret = ns_common_init(&new_ns->ns, &cgroupns_operations, true); 30 + ret = ns_common_init(new_ns, &cgroupns_operations); 31 31 if (ret) 32 32 return ERR_PTR(ret); 33 33 ns_tree_add(new_ns); ··· 40 40 put_css_set(ns->root_cset); 41 41 dec_cgroup_namespaces(ns->ucounts); 42 42 put_user_ns(ns->user_ns); 43 - ns_free_inum(&ns->ns); 43 + ns_common_free(ns); 44 44 /* Concurrent nstree traversal depends on a grace period. */ 45 45 kfree_rcu(ns, ns.ns_rcu); 46 46 }
+25
kernel/nscommon.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + 3 + #include <linux/ns_common.h> 4 + #include <linux/proc_ns.h> 5 + 6 + int __ns_common_init(struct ns_common *ns, const struct proc_ns_operations *ops, int inum) 7 + { 8 + refcount_set(&ns->count, 1); 9 + ns->stashed = NULL; 10 + ns->ops = ops; 11 + ns->ns_id = 0; 12 + RB_CLEAR_NODE(&ns->ns_tree_node); 13 + INIT_LIST_HEAD(&ns->ns_list_node); 14 + 15 + if (inum) { 16 + ns->inum = inum; 17 + return 0; 18 + } 19 + return proc_alloc_inum(&ns->inum); 20 + } 21 + 22 + void __ns_common_free(struct ns_common *ns) 23 + { 24 + proc_free_inum(ns->inum); 25 + }
+3 -3
kernel/pid_namespace.c
··· 103 103 if (ns->pid_cachep == NULL) 104 104 goto out_free_idr; 105 105 106 - err = ns_common_init(&ns->ns, &pidns_operations, true); 106 + err = ns_common_init(ns, &pidns_operations); 107 107 if (err) 108 108 goto out_free_idr; 109 109 ··· 127 127 return ns; 128 128 129 129 out_free_inum: 130 - ns_free_inum(&ns->ns); 130 + ns_common_free(ns); 131 131 out_free_idr: 132 132 idr_destroy(&ns->idr); 133 133 kmem_cache_free(pid_ns_cachep, ns); ··· 152 152 ns_tree_remove(ns); 153 153 unregister_pidns_sysctls(ns); 154 154 155 - ns_free_inum(&ns->ns); 155 + ns_common_free(ns); 156 156 157 157 idr_destroy(&ns->idr); 158 158 call_rcu(&ns->rcu, delayed_free_pidns);
+2 -2
kernel/time/namespace.c
··· 97 97 if (!ns->vvar_page) 98 98 goto fail_free; 99 99 100 - err = ns_common_init(&ns->ns, &timens_operations, true); 100 + err = ns_common_init(ns, &timens_operations); 101 101 if (err) 102 102 goto fail_free_page; 103 103 ··· 255 255 ns_tree_remove(ns); 256 256 dec_time_namespaces(ns->ucounts); 257 257 put_user_ns(ns->user_ns); 258 - ns_free_inum(&ns->ns); 258 + ns_common_free(ns); 259 259 __free_page(ns->vvar_page); 260 260 /* Concurrent nstree traversal depends on a grace period. */ 261 261 kfree_rcu(ns, ns.ns_rcu);
+3 -3
kernel/user_namespace.c
··· 126 126 127 127 ns->parent_could_setfcap = cap_raised(new->cap_effective, CAP_SETFCAP); 128 128 129 - ret = ns_common_init(&ns->ns, &userns_operations, true); 129 + ret = ns_common_init(ns, &userns_operations); 130 130 if (ret) 131 131 goto fail_free; 132 132 ··· 165 165 #ifdef CONFIG_PERSISTENT_KEYRINGS 166 166 key_put(ns->persistent_keyring_register); 167 167 #endif 168 - ns_free_inum(&ns->ns); 168 + ns_common_free(ns); 169 169 fail_free: 170 170 kmem_cache_free(user_ns_cachep, ns); 171 171 fail_dec: ··· 220 220 #endif 221 221 retire_userns_sysctls(ns); 222 222 key_free_user_ns(ns); 223 - ns_free_inum(&ns->ns); 223 + ns_common_free(ns); 224 224 /* Concurrent nstree traversal depends on a grace period. */ 225 225 kfree_rcu(ns, ns.ns_rcu); 226 226 dec_user_namespaces(ucounts);
+2 -2
kernel/utsname.c
··· 50 50 if (!ns) 51 51 goto fail_dec; 52 52 53 - err = ns_common_init(&ns->ns, &utsns_operations, true); 53 + err = ns_common_init(ns, &utsns_operations); 54 54 if (err) 55 55 goto fail_free; 56 56 ··· 98 98 ns_tree_remove(ns); 99 99 dec_uts_namespaces(ns->ucounts); 100 100 put_user_ns(ns->user_ns); 101 - ns_free_inum(&ns->ns); 101 + ns_common_free(ns); 102 102 /* Concurrent nstree traversal depends on a grace period. */ 103 103 kfree_rcu(ns, ns.ns_rcu); 104 104 }
+3 -20
net/core/net_namespace.c
··· 409 409 ns_ops = NULL; 410 410 #endif 411 411 412 - ret = ns_common_init(&net->ns, ns_ops, false); 412 + ret = ns_common_init(net, ns_ops); 413 413 if (ret) 414 414 return ret; 415 415 ··· 590 590 591 591 if (rv < 0) { 592 592 put_userns: 593 + ns_common_free(net); 593 594 #ifdef CONFIG_KEYS 594 595 key_remove_domain(net->key_domain); 595 596 #endif ··· 713 712 /* Finally it is safe to free my network namespace structure */ 714 713 list_for_each_entry_safe(net, tmp, &net_exit_list, exit_list) { 715 714 list_del_init(&net->exit_list); 715 + ns_common_free(net); 716 716 dec_net_namespaces(net->ucounts); 717 717 #ifdef CONFIG_KEYS 718 718 key_remove_domain(net->key_domain); ··· 833 831 834 832 static __net_init int net_ns_net_init(struct net *net) 835 833 { 836 - int ret = 0; 837 - 838 - if (net == &init_net) 839 - net->ns.inum = PROC_NET_INIT_INO; 840 - else 841 - ret = proc_alloc_inum(&to_ns_common(net)->inum); 842 - if (ret) 843 - return ret; 844 - 845 834 net_ns_net_debugfs(net); 846 835 return 0; 847 836 } 848 837 849 - static __net_exit void net_ns_net_exit(struct net *net) 850 - { 851 - /* 852 - * Initial network namespace doesn't exit so we don't need any 853 - * special checks here. 854 - */ 855 - ns_free_inum(&net->ns); 856 - } 857 - 858 838 static struct pernet_operations __net_initdata net_ns_ops = { 859 839 .init = net_ns_net_init, 860 - .exit = net_ns_net_exit, 861 840 }; 862 841 863 842 static const struct nla_policy rtnl_net_policy[NETNSA_MAX + 1] = {