diff options
| author | Eric W. Biederman <ebiederm@xmission.com> | 2011-06-15 13:21:48 -0400 |
|---|---|---|
| committer | Eric W. Biederman <ebiederm@xmission.com> | 2012-11-20 07:19:49 -0500 |
| commit | 98f842e675f96ffac96e6c50315790912b2812be (patch) | |
| tree | ed4dee9a6e54e3443e9f3f1614c8a2fcf9b31e0a | |
| parent | bf056bfa80596a5d14b26b17276a56a0dcb080e5 (diff) | |
proc: Usable inode numbers for the namespace file descriptors.
Assign a unique proc inode to each namespace, and use that
inode number to ensure we only allocate at most one proc
inode for every namespace in proc.
A single proc inode per namespace allows userspace to test
to see if two processes are in the same namespace.
This has been a long requested feature and only blocked because
a naive implementation would put the id in a global space and
would ultimately require having a namespace for the names of
namespaces, making migration and certain virtualization tricks
impossible.
We still don't have per superblock inode numbers for proc, which
appears necessary for application unaware checkpoint/restart and
migrations (if the application is using namespace file descriptors)
but that is now allowd by the design if it becomes important.
I have preallocated the ipc and uts initial proc inode numbers so
their structures can be statically initialized.
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
| -rw-r--r-- | fs/mount.h | 1 | ||||
| -rw-r--r-- | fs/namespace.c | 14 | ||||
| -rw-r--r-- | fs/proc/namespaces.c | 24 | ||||
| -rw-r--r-- | include/linux/ipc_namespace.h | 2 | ||||
| -rw-r--r-- | include/linux/pid_namespace.h | 1 | ||||
| -rw-r--r-- | include/linux/proc_fs.h | 7 | ||||
| -rw-r--r-- | include/linux/user_namespace.h | 1 | ||||
| -rw-r--r-- | include/linux/utsname.h | 1 | ||||
| -rw-r--r-- | include/net/net_namespace.h | 2 | ||||
| -rw-r--r-- | init/version.c | 2 | ||||
| -rw-r--r-- | ipc/msgutil.c | 2 | ||||
| -rw-r--r-- | ipc/namespace.c | 16 | ||||
| -rw-r--r-- | kernel/pid.c | 1 | ||||
| -rw-r--r-- | kernel/pid_namespace.c | 12 | ||||
| -rw-r--r-- | kernel/user.c | 2 | ||||
| -rw-r--r-- | kernel/user_namespace.c | 15 | ||||
| -rw-r--r-- | kernel/utsname.c | 17 | ||||
| -rw-r--r-- | net/core/net_namespace.c | 24 |
18 files changed, 132 insertions, 12 deletions
diff --git a/fs/mount.h b/fs/mount.h index 630fafc616bb..cd5007980400 100644 --- a/fs/mount.h +++ b/fs/mount.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | struct mnt_namespace { | 5 | struct mnt_namespace { |
| 6 | atomic_t count; | 6 | atomic_t count; |
| 7 | unsigned int proc_inum; | ||
| 7 | struct mount * root; | 8 | struct mount * root; |
| 8 | struct list_head list; | 9 | struct list_head list; |
| 9 | struct user_namespace *user_ns; | 10 | struct user_namespace *user_ns; |
diff --git a/fs/namespace.c b/fs/namespace.c index cab78a74aca3..c1bbe86f4920 100644 --- a/fs/namespace.c +++ b/fs/namespace.c | |||
| @@ -2301,6 +2301,7 @@ dput_out: | |||
| 2301 | 2301 | ||
| 2302 | static void free_mnt_ns(struct mnt_namespace *ns) | 2302 | static void free_mnt_ns(struct mnt_namespace *ns) |
| 2303 | { | 2303 | { |
| 2304 | proc_free_inum(ns->proc_inum); | ||
| 2304 | put_user_ns(ns->user_ns); | 2305 | put_user_ns(ns->user_ns); |
| 2305 | kfree(ns); | 2306 | kfree(ns); |
| 2306 | } | 2307 | } |
| @@ -2317,10 +2318,16 @@ static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1); | |||
| 2317 | static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns) | 2318 | static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns) |
| 2318 | { | 2319 | { |
| 2319 | struct mnt_namespace *new_ns; | 2320 | struct mnt_namespace *new_ns; |
| 2321 | int ret; | ||
| 2320 | 2322 | ||
| 2321 | new_ns = kmalloc(sizeof(struct mnt_namespace), GFP_KERNEL); | 2323 | new_ns = kmalloc(sizeof(struct mnt_namespace), GFP_KERNEL); |
| 2322 | if (!new_ns) | 2324 | if (!new_ns) |
| 2323 | return ERR_PTR(-ENOMEM); | 2325 | return ERR_PTR(-ENOMEM); |
| 2326 | ret = proc_alloc_inum(&new_ns->proc_inum); | ||
| 2327 | if (ret) { | ||
| 2328 | kfree(new_ns); | ||
| 2329 | return ERR_PTR(ret); | ||
| 2330 | } | ||
| 2324 | new_ns->seq = atomic64_add_return(1, &mnt_ns_seq); | 2331 | new_ns->seq = atomic64_add_return(1, &mnt_ns_seq); |
| 2325 | atomic_set(&new_ns->count, 1); | 2332 | atomic_set(&new_ns->count, 1); |
| 2326 | new_ns->root = NULL; | 2333 | new_ns->root = NULL; |
| @@ -2799,10 +2806,17 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns) | |||
| 2799 | return 0; | 2806 | return 0; |
| 2800 | } | 2807 | } |
| 2801 | 2808 | ||
| 2809 | static unsigned int mntns_inum(void *ns) | ||
| 2810 | { | ||
| 2811 | struct mnt_namespace *mnt_ns = ns; | ||
| 2812 | return mnt_ns->proc_inum; | ||
| 2813 | } | ||
| 2814 | |||
| 2802 | const struct proc_ns_operations mntns_operations = { | 2815 | const struct proc_ns_operations mntns_operations = { |
| 2803 | .name = "mnt", | 2816 | .name = "mnt", |
| 2804 | .type = CLONE_NEWNS, | 2817 | .type = CLONE_NEWNS, |
| 2805 | .get = mntns_get, | 2818 | .get = mntns_get, |
| 2806 | .put = mntns_put, | 2819 | .put = mntns_put, |
| 2807 | .install = mntns_install, | 2820 | .install = mntns_install, |
| 2821 | .inum = mntns_inum, | ||
| 2808 | }; | 2822 | }; |
diff --git a/fs/proc/namespaces.c b/fs/proc/namespaces.c index 7a6d8d69cdb8..b7a47196c8c3 100644 --- a/fs/proc/namespaces.c +++ b/fs/proc/namespaces.c | |||
| @@ -82,7 +82,7 @@ static struct dentry *proc_ns_get_dentry(struct super_block *sb, | |||
| 82 | return ERR_PTR(-ENOMEM); | 82 | return ERR_PTR(-ENOMEM); |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | inode = new_inode(sb); | 85 | inode = iget_locked(sb, ns_ops->inum(ns)); |
| 86 | if (!inode) { | 86 | if (!inode) { |
| 87 | dput(dentry); | 87 | dput(dentry); |
| 88 | ns_ops->put(ns); | 88 | ns_ops->put(ns); |
| @@ -90,13 +90,17 @@ static struct dentry *proc_ns_get_dentry(struct super_block *sb, | |||
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | ei = PROC_I(inode); | 92 | ei = PROC_I(inode); |
| 93 | inode->i_ino = get_next_ino(); | 93 | if (inode->i_state & I_NEW) { |
| 94 | inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; | 94 | inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; |
| 95 | inode->i_op = &ns_inode_operations; | 95 | inode->i_op = &ns_inode_operations; |
| 96 | inode->i_mode = S_IFREG | S_IRUGO; | 96 | inode->i_mode = S_IFREG | S_IRUGO; |
| 97 | inode->i_fop = &ns_file_operations; | 97 | inode->i_fop = &ns_file_operations; |
| 98 | ei->ns_ops = ns_ops; | 98 | ei->ns_ops = ns_ops; |
| 99 | ei->ns = ns; | 99 | ei->ns = ns; |
| 100 | unlock_new_inode(inode); | ||
| 101 | } else { | ||
| 102 | ns_ops->put(ns); | ||
| 103 | } | ||
| 100 | 104 | ||
| 101 | d_set_d_op(dentry, &ns_dentry_operations); | 105 | d_set_d_op(dentry, &ns_dentry_operations); |
| 102 | result = d_instantiate_unique(dentry, inode); | 106 | result = d_instantiate_unique(dentry, inode); |
| @@ -162,12 +166,12 @@ static int proc_ns_readlink(struct dentry *dentry, char __user *buffer, int bufl | |||
| 162 | if (!ns) | 166 | if (!ns) |
| 163 | goto out_put_task; | 167 | goto out_put_task; |
| 164 | 168 | ||
| 165 | snprintf(name, sizeof(name), "%s", ns_ops->name); | 169 | snprintf(name, sizeof(name), "%s:[%u]", ns_ops->name, ns_ops->inum(ns)); |
| 166 | len = strlen(name); | 170 | len = strlen(name); |
| 167 | 171 | ||
| 168 | if (len > buflen) | 172 | if (len > buflen) |
| 169 | len = buflen; | 173 | len = buflen; |
| 170 | if (copy_to_user(buffer, ns_ops->name, len)) | 174 | if (copy_to_user(buffer, name, len)) |
| 171 | len = -EFAULT; | 175 | len = -EFAULT; |
| 172 | 176 | ||
| 173 | ns_ops->put(ns); | 177 | ns_ops->put(ns); |
diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h index f03af702a39d..fe771978e877 100644 --- a/include/linux/ipc_namespace.h +++ b/include/linux/ipc_namespace.h | |||
| @@ -67,6 +67,8 @@ struct ipc_namespace { | |||
| 67 | 67 | ||
| 68 | /* user_ns which owns the ipc ns */ | 68 | /* user_ns which owns the ipc ns */ |
| 69 | struct user_namespace *user_ns; | 69 | struct user_namespace *user_ns; |
| 70 | |||
| 71 | unsigned int proc_inum; | ||
| 70 | }; | 72 | }; |
| 71 | 73 | ||
| 72 | extern struct ipc_namespace init_ipc_ns; | 74 | extern struct ipc_namespace init_ipc_ns; |
diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h index 4c96acdb2489..bf285999273a 100644 --- a/include/linux/pid_namespace.h +++ b/include/linux/pid_namespace.h | |||
| @@ -37,6 +37,7 @@ struct pid_namespace { | |||
| 37 | kgid_t pid_gid; | 37 | kgid_t pid_gid; |
| 38 | int hide_pid; | 38 | int hide_pid; |
| 39 | int reboot; /* group exit code if this pidns was rebooted */ | 39 | int reboot; /* group exit code if this pidns was rebooted */ |
| 40 | unsigned int proc_inum; | ||
| 40 | }; | 41 | }; |
| 41 | 42 | ||
| 42 | extern struct pid_namespace init_pid_ns; | 43 | extern struct pid_namespace init_pid_ns; |
diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h index bf1d000fbba6..2e24018b7cec 100644 --- a/include/linux/proc_fs.h +++ b/include/linux/proc_fs.h | |||
| @@ -28,7 +28,11 @@ struct mm_struct; | |||
| 28 | */ | 28 | */ |
| 29 | 29 | ||
| 30 | enum { | 30 | enum { |
| 31 | PROC_ROOT_INO = 1, | 31 | PROC_ROOT_INO = 1, |
| 32 | PROC_IPC_INIT_INO = 0xEFFFFFFFU, | ||
| 33 | PROC_UTS_INIT_INO = 0xEFFFFFFEU, | ||
| 34 | PROC_USER_INIT_INO = 0xEFFFFFFDU, | ||
| 35 | PROC_PID_INIT_INO = 0xEFFFFFFCU, | ||
| 32 | }; | 36 | }; |
| 33 | 37 | ||
| 34 | /* | 38 | /* |
| @@ -263,6 +267,7 @@ struct proc_ns_operations { | |||
| 263 | void *(*get)(struct task_struct *task); | 267 | void *(*get)(struct task_struct *task); |
| 264 | void (*put)(void *ns); | 268 | void (*put)(void *ns); |
| 265 | int (*install)(struct nsproxy *nsproxy, void *ns); | 269 | int (*install)(struct nsproxy *nsproxy, void *ns); |
| 270 | unsigned int (*inum)(void *ns); | ||
| 266 | }; | 271 | }; |
| 267 | extern const struct proc_ns_operations netns_operations; | 272 | extern const struct proc_ns_operations netns_operations; |
| 268 | extern const struct proc_ns_operations utsns_operations; | 273 | extern const struct proc_ns_operations utsns_operations; |
diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h index 17651f08d67f..b9bd2e6c73cc 100644 --- a/include/linux/user_namespace.h +++ b/include/linux/user_namespace.h | |||
| @@ -25,6 +25,7 @@ struct user_namespace { | |||
| 25 | struct user_namespace *parent; | 25 | struct user_namespace *parent; |
| 26 | kuid_t owner; | 26 | kuid_t owner; |
| 27 | kgid_t group; | 27 | kgid_t group; |
| 28 | unsigned int proc_inum; | ||
| 28 | }; | 29 | }; |
| 29 | 30 | ||
| 30 | extern struct user_namespace init_user_ns; | 31 | extern struct user_namespace init_user_ns; |
diff --git a/include/linux/utsname.h b/include/linux/utsname.h index 221f4a0a7502..239e27733d6c 100644 --- a/include/linux/utsname.h +++ b/include/linux/utsname.h | |||
| @@ -23,6 +23,7 @@ struct uts_namespace { | |||
| 23 | struct kref kref; | 23 | struct kref kref; |
| 24 | struct new_utsname name; | 24 | struct new_utsname name; |
| 25 | struct user_namespace *user_ns; | 25 | struct user_namespace *user_ns; |
| 26 | unsigned int proc_inum; | ||
| 26 | }; | 27 | }; |
| 27 | extern struct uts_namespace init_uts_ns; | 28 | extern struct uts_namespace init_uts_ns; |
| 28 | 29 | ||
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h index c5a43f56b796..de644bcd8613 100644 --- a/include/net/net_namespace.h +++ b/include/net/net_namespace.h | |||
| @@ -56,6 +56,8 @@ struct net { | |||
| 56 | 56 | ||
| 57 | struct user_namespace *user_ns; /* Owning user namespace */ | 57 | struct user_namespace *user_ns; /* Owning user namespace */ |
| 58 | 58 | ||
| 59 | unsigned int proc_inum; | ||
| 60 | |||
| 59 | struct proc_dir_entry *proc_net; | 61 | struct proc_dir_entry *proc_net; |
| 60 | struct proc_dir_entry *proc_net_stat; | 62 | struct proc_dir_entry *proc_net_stat; |
| 61 | 63 | ||
diff --git a/init/version.c b/init/version.c index 86fe0ccb997a..58170f18912d 100644 --- a/init/version.c +++ b/init/version.c | |||
| @@ -12,6 +12,7 @@ | |||
| 12 | #include <linux/utsname.h> | 12 | #include <linux/utsname.h> |
| 13 | #include <generated/utsrelease.h> | 13 | #include <generated/utsrelease.h> |
| 14 | #include <linux/version.h> | 14 | #include <linux/version.h> |
| 15 | #include <linux/proc_fs.h> | ||
| 15 | 16 | ||
| 16 | #ifndef CONFIG_KALLSYMS | 17 | #ifndef CONFIG_KALLSYMS |
| 17 | #define version(a) Version_ ## a | 18 | #define version(a) Version_ ## a |
| @@ -34,6 +35,7 @@ struct uts_namespace init_uts_ns = { | |||
| 34 | .domainname = UTS_DOMAINNAME, | 35 | .domainname = UTS_DOMAINNAME, |
| 35 | }, | 36 | }, |
| 36 | .user_ns = &init_user_ns, | 37 | .user_ns = &init_user_ns, |
| 38 | .proc_inum = PROC_UTS_INIT_INO, | ||
| 37 | }; | 39 | }; |
| 38 | EXPORT_SYMBOL_GPL(init_uts_ns); | 40 | EXPORT_SYMBOL_GPL(init_uts_ns); |
| 39 | 41 | ||
diff --git a/ipc/msgutil.c b/ipc/msgutil.c index 26143d377c95..6471f1bdae96 100644 --- a/ipc/msgutil.c +++ b/ipc/msgutil.c | |||
| @@ -16,6 +16,7 @@ | |||
| 16 | #include <linux/msg.h> | 16 | #include <linux/msg.h> |
| 17 | #include <linux/ipc_namespace.h> | 17 | #include <linux/ipc_namespace.h> |
| 18 | #include <linux/utsname.h> | 18 | #include <linux/utsname.h> |
| 19 | #include <linux/proc_fs.h> | ||
| 19 | #include <asm/uaccess.h> | 20 | #include <asm/uaccess.h> |
| 20 | 21 | ||
| 21 | #include "util.h" | 22 | #include "util.h" |
| @@ -30,6 +31,7 @@ DEFINE_SPINLOCK(mq_lock); | |||
| 30 | struct ipc_namespace init_ipc_ns = { | 31 | struct ipc_namespace init_ipc_ns = { |
| 31 | .count = ATOMIC_INIT(1), | 32 | .count = ATOMIC_INIT(1), |
| 32 | .user_ns = &init_user_ns, | 33 | .user_ns = &init_user_ns, |
| 34 | .proc_inum = PROC_IPC_INIT_INO, | ||
| 33 | }; | 35 | }; |
| 34 | 36 | ||
| 35 | atomic_t nr_ipc_ns = ATOMIC_INIT(1); | 37 | atomic_t nr_ipc_ns = ATOMIC_INIT(1); |
diff --git a/ipc/namespace.c b/ipc/namespace.c index 72c868277793..cf3386a51de2 100644 --- a/ipc/namespace.c +++ b/ipc/namespace.c | |||
| @@ -26,9 +26,16 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns, | |||
| 26 | if (ns == NULL) | 26 | if (ns == NULL) |
| 27 | return ERR_PTR(-ENOMEM); | 27 | return ERR_PTR(-ENOMEM); |
| 28 | 28 | ||
| 29 | err = proc_alloc_inum(&ns->proc_inum); | ||
| 30 | if (err) { | ||
| 31 | kfree(ns); | ||
| 32 | return ERR_PTR(err); | ||
| 33 | } | ||
| 34 | |||
| 29 | atomic_set(&ns->count, 1); | 35 | atomic_set(&ns->count, 1); |
| 30 | err = mq_init_ns(ns); | 36 | err = mq_init_ns(ns); |
| 31 | if (err) { | 37 | if (err) { |
| 38 | proc_free_inum(ns->proc_inum); | ||
| 32 | kfree(ns); | 39 | kfree(ns); |
| 33 | return ERR_PTR(err); | 40 | return ERR_PTR(err); |
| 34 | } | 41 | } |
| @@ -111,6 +118,7 @@ static void free_ipc_ns(struct ipc_namespace *ns) | |||
| 111 | */ | 118 | */ |
| 112 | ipcns_notify(IPCNS_REMOVED); | 119 | ipcns_notify(IPCNS_REMOVED); |
| 113 | put_user_ns(ns->user_ns); | 120 | put_user_ns(ns->user_ns); |
| 121 | proc_free_inum(ns->proc_inum); | ||
| 114 | kfree(ns); | 122 | kfree(ns); |
| 115 | } | 123 | } |
| 116 | 124 | ||
| @@ -172,10 +180,18 @@ static int ipcns_install(struct nsproxy *nsproxy, void *new) | |||
| 172 | return 0; | 180 | return 0; |
| 173 | } | 181 | } |
| 174 | 182 | ||
| 183 | static unsigned int ipcns_inum(void *vp) | ||
| 184 | { | ||
| 185 | struct ipc_namespace *ns = vp; | ||
| 186 | |||
| 187 | return ns->proc_inum; | ||
| 188 | } | ||
| 189 | |||
| 175 | const struct proc_ns_operations ipcns_operations = { | 190 | const struct proc_ns_operations ipcns_operations = { |
| 176 | .name = "ipc", | 191 | .name = "ipc", |
| 177 | .type = CLONE_NEWIPC, | 192 | .type = CLONE_NEWIPC, |
| 178 | .get = ipcns_get, | 193 | .get = ipcns_get, |
| 179 | .put = ipcns_put, | 194 | .put = ipcns_put, |
| 180 | .install = ipcns_install, | 195 | .install = ipcns_install, |
| 196 | .inum = ipcns_inum, | ||
| 181 | }; | 197 | }; |
diff --git a/kernel/pid.c b/kernel/pid.c index 6e8da291de49..3026ddae0a34 100644 --- a/kernel/pid.c +++ b/kernel/pid.c | |||
| @@ -80,6 +80,7 @@ struct pid_namespace init_pid_ns = { | |||
| 80 | .level = 0, | 80 | .level = 0, |
| 81 | .child_reaper = &init_task, | 81 | .child_reaper = &init_task, |
| 82 | .user_ns = &init_user_ns, | 82 | .user_ns = &init_user_ns, |
| 83 | .proc_inum = PROC_PID_INIT_INO, | ||
| 83 | }; | 84 | }; |
| 84 | EXPORT_SYMBOL_GPL(init_pid_ns); | 85 | EXPORT_SYMBOL_GPL(init_pid_ns); |
| 85 | 86 | ||
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c index 68508d330634..560da0dab230 100644 --- a/kernel/pid_namespace.c +++ b/kernel/pid_namespace.c | |||
| @@ -107,6 +107,10 @@ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns | |||
| 107 | if (ns->pid_cachep == NULL) | 107 | if (ns->pid_cachep == NULL) |
| 108 | goto out_free_map; | 108 | goto out_free_map; |
| 109 | 109 | ||
| 110 | err = proc_alloc_inum(&ns->proc_inum); | ||
| 111 | if (err) | ||
| 112 | goto out_free_map; | ||
| 113 | |||
| 110 | kref_init(&ns->kref); | 114 | kref_init(&ns->kref); |
| 111 | ns->level = level; | 115 | ns->level = level; |
| 112 | ns->parent = get_pid_ns(parent_pid_ns); | 116 | ns->parent = get_pid_ns(parent_pid_ns); |
| @@ -133,6 +137,7 @@ static void destroy_pid_namespace(struct pid_namespace *ns) | |||
| 133 | { | 137 | { |
| 134 | int i; | 138 | int i; |
| 135 | 139 | ||
| 140 | proc_free_inum(ns->proc_inum); | ||
| 136 | for (i = 0; i < PIDMAP_ENTRIES; i++) | 141 | for (i = 0; i < PIDMAP_ENTRIES; i++) |
| 137 | kfree(ns->pidmap[i].page); | 142 | kfree(ns->pidmap[i].page); |
| 138 | put_user_ns(ns->user_ns); | 143 | put_user_ns(ns->user_ns); |
| @@ -345,12 +350,19 @@ static int pidns_install(struct nsproxy *nsproxy, void *ns) | |||
| 345 | return 0; | 350 | return 0; |
| 346 | } | 351 | } |
| 347 | 352 | ||
| 353 | static unsigned int pidns_inum(void *ns) | ||
| 354 | { | ||
| 355 | struct pid_namespace *pid_ns = ns; | ||
| 356 | return pid_ns->proc_inum; | ||
| 357 | } | ||
| 358 | |||
| 348 | const struct proc_ns_operations pidns_operations = { | 359 | const struct proc_ns_operations pidns_operations = { |
| 349 | .name = "pid", | 360 | .name = "pid", |
| 350 | .type = CLONE_NEWPID, | 361 | .type = CLONE_NEWPID, |
| 351 | .get = pidns_get, | 362 | .get = pidns_get, |
| 352 | .put = pidns_put, | 363 | .put = pidns_put, |
| 353 | .install = pidns_install, | 364 | .install = pidns_install, |
| 365 | .inum = pidns_inum, | ||
| 354 | }; | 366 | }; |
| 355 | 367 | ||
| 356 | static __init int pid_namespaces_init(void) | 368 | static __init int pid_namespaces_init(void) |
diff --git a/kernel/user.c b/kernel/user.c index 750acffbe9ec..33acb5e53a5f 100644 --- a/kernel/user.c +++ b/kernel/user.c | |||
| @@ -16,6 +16,7 @@ | |||
| 16 | #include <linux/interrupt.h> | 16 | #include <linux/interrupt.h> |
| 17 | #include <linux/export.h> | 17 | #include <linux/export.h> |
| 18 | #include <linux/user_namespace.h> | 18 | #include <linux/user_namespace.h> |
| 19 | #include <linux/proc_fs.h> | ||
| 19 | 20 | ||
| 20 | /* | 21 | /* |
| 21 | * userns count is 1 for root user, 1 for init_uts_ns, | 22 | * userns count is 1 for root user, 1 for init_uts_ns, |
| @@ -51,6 +52,7 @@ struct user_namespace init_user_ns = { | |||
| 51 | }, | 52 | }, |
| 52 | .owner = GLOBAL_ROOT_UID, | 53 | .owner = GLOBAL_ROOT_UID, |
| 53 | .group = GLOBAL_ROOT_GID, | 54 | .group = GLOBAL_ROOT_GID, |
| 55 | .proc_inum = PROC_USER_INIT_INO, | ||
| 54 | }; | 56 | }; |
| 55 | EXPORT_SYMBOL_GPL(init_user_ns); | 57 | EXPORT_SYMBOL_GPL(init_user_ns); |
| 56 | 58 | ||
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c index 89f6eaed067a..f5975ccf9348 100644 --- a/kernel/user_namespace.c +++ b/kernel/user_namespace.c | |||
| @@ -58,6 +58,7 @@ int create_user_ns(struct cred *new) | |||
| 58 | struct user_namespace *ns, *parent_ns = new->user_ns; | 58 | struct user_namespace *ns, *parent_ns = new->user_ns; |
| 59 | kuid_t owner = new->euid; | 59 | kuid_t owner = new->euid; |
| 60 | kgid_t group = new->egid; | 60 | kgid_t group = new->egid; |
| 61 | int ret; | ||
| 61 | 62 | ||
| 62 | /* The creator needs a mapping in the parent user namespace | 63 | /* The creator needs a mapping in the parent user namespace |
| 63 | * or else we won't be able to reasonably tell userspace who | 64 | * or else we won't be able to reasonably tell userspace who |
| @@ -71,6 +72,12 @@ int create_user_ns(struct cred *new) | |||
| 71 | if (!ns) | 72 | if (!ns) |
| 72 | return -ENOMEM; | 73 | return -ENOMEM; |
| 73 | 74 | ||
| 75 | ret = proc_alloc_inum(&ns->proc_inum); | ||
| 76 | if (ret) { | ||
| 77 | kmem_cache_free(user_ns_cachep, ns); | ||
| 78 | return ret; | ||
| 79 | } | ||
| 80 | |||
| 74 | kref_init(&ns->kref); | 81 | kref_init(&ns->kref); |
| 75 | /* Leave the new->user_ns reference with the new user namespace. */ | 82 | /* Leave the new->user_ns reference with the new user namespace. */ |
| 76 | ns->parent = parent_ns; | 83 | ns->parent = parent_ns; |
| @@ -103,6 +110,7 @@ void free_user_ns(struct kref *kref) | |||
| 103 | container_of(kref, struct user_namespace, kref); | 110 | container_of(kref, struct user_namespace, kref); |
| 104 | 111 | ||
| 105 | parent = ns->parent; | 112 | parent = ns->parent; |
| 113 | proc_free_inum(ns->proc_inum); | ||
| 106 | kmem_cache_free(user_ns_cachep, ns); | 114 | kmem_cache_free(user_ns_cachep, ns); |
| 107 | put_user_ns(parent); | 115 | put_user_ns(parent); |
| 108 | } | 116 | } |
| @@ -808,12 +816,19 @@ static int userns_install(struct nsproxy *nsproxy, void *ns) | |||
| 808 | return commit_creds(cred); | 816 | return commit_creds(cred); |
| 809 | } | 817 | } |
| 810 | 818 | ||
| 819 | static unsigned int userns_inum(void *ns) | ||
| 820 | { | ||
| 821 | struct user_namespace *user_ns = ns; | ||
| 822 | return user_ns->proc_inum; | ||
| 823 | } | ||
| 824 | |||
| 811 | const struct proc_ns_operations userns_operations = { | 825 | const struct proc_ns_operations userns_operations = { |
| 812 | .name = "user", | 826 | .name = "user", |
| 813 | .type = CLONE_NEWUSER, | 827 | .type = CLONE_NEWUSER, |
| 814 | .get = userns_get, | 828 | .get = userns_get, |
| 815 | .put = userns_put, | 829 | .put = userns_put, |
| 816 | .install = userns_install, | 830 | .install = userns_install, |
| 831 | .inum = userns_inum, | ||
| 817 | }; | 832 | }; |
| 818 | 833 | ||
| 819 | static __init int user_namespaces_init(void) | 834 | static __init int user_namespaces_init(void) |
diff --git a/kernel/utsname.c b/kernel/utsname.c index fdc619eb61ef..f6336d51d64c 100644 --- a/kernel/utsname.c +++ b/kernel/utsname.c | |||
| @@ -36,11 +36,18 @@ static struct uts_namespace *clone_uts_ns(struct user_namespace *user_ns, | |||
| 36 | struct uts_namespace *old_ns) | 36 | struct uts_namespace *old_ns) |
| 37 | { | 37 | { |
| 38 | struct uts_namespace *ns; | 38 | struct uts_namespace *ns; |
| 39 | int err; | ||
| 39 | 40 | ||
| 40 | ns = create_uts_ns(); | 41 | ns = create_uts_ns(); |
| 41 | if (!ns) | 42 | if (!ns) |
| 42 | return ERR_PTR(-ENOMEM); | 43 | return ERR_PTR(-ENOMEM); |
| 43 | 44 | ||
| 45 | err = proc_alloc_inum(&ns->proc_inum); | ||
| 46 | if (err) { | ||
| 47 | kfree(ns); | ||
| 48 | return ERR_PTR(err); | ||
| 49 | } | ||
| 50 | |||
| 44 | down_read(&uts_sem); | 51 | down_read(&uts_sem); |
| 45 | memcpy(&ns->name, &old_ns->name, sizeof(ns->name)); | 52 | memcpy(&ns->name, &old_ns->name, sizeof(ns->name)); |
| 46 | ns->user_ns = get_user_ns(user_ns); | 53 | ns->user_ns = get_user_ns(user_ns); |
| @@ -77,6 +84,7 @@ void free_uts_ns(struct kref *kref) | |||
| 77 | 84 | ||
| 78 | ns = container_of(kref, struct uts_namespace, kref); | 85 | ns = container_of(kref, struct uts_namespace, kref); |
| 79 | put_user_ns(ns->user_ns); | 86 | put_user_ns(ns->user_ns); |
| 87 | proc_free_inum(ns->proc_inum); | ||
| 80 | kfree(ns); | 88 | kfree(ns); |
| 81 | } | 89 | } |
| 82 | 90 | ||
| @@ -114,11 +122,18 @@ static int utsns_install(struct nsproxy *nsproxy, void *new) | |||
| 114 | return 0; | 122 | return 0; |
| 115 | } | 123 | } |
| 116 | 124 | ||
| 125 | static unsigned int utsns_inum(void *vp) | ||
| 126 | { | ||
| 127 | struct uts_namespace *ns = vp; | ||
| 128 | |||
| 129 | return ns->proc_inum; | ||
| 130 | } | ||
| 131 | |||
| 117 | const struct proc_ns_operations utsns_operations = { | 132 | const struct proc_ns_operations utsns_operations = { |
| 118 | .name = "uts", | 133 | .name = "uts", |
| 119 | .type = CLONE_NEWUTS, | 134 | .type = CLONE_NEWUTS, |
| 120 | .get = utsns_get, | 135 | .get = utsns_get, |
| 121 | .put = utsns_put, | 136 | .put = utsns_put, |
| 122 | .install = utsns_install, | 137 | .install = utsns_install, |
| 138 | .inum = utsns_inum, | ||
| 123 | }; | 139 | }; |
| 124 | |||
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index ec2870b44c1f..2e9a3132b8dd 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c | |||
| @@ -381,6 +381,21 @@ struct net *get_net_ns_by_pid(pid_t pid) | |||
| 381 | } | 381 | } |
| 382 | EXPORT_SYMBOL_GPL(get_net_ns_by_pid); | 382 | EXPORT_SYMBOL_GPL(get_net_ns_by_pid); |
| 383 | 383 | ||
| 384 | static __net_init int net_ns_net_init(struct net *net) | ||
| 385 | { | ||
| 386 | return proc_alloc_inum(&net->proc_inum); | ||
| 387 | } | ||
| 388 | |||
| 389 | static __net_exit void net_ns_net_exit(struct net *net) | ||
| 390 | { | ||
| 391 | proc_free_inum(net->proc_inum); | ||
| 392 | } | ||
| 393 | |||
| 394 | static struct pernet_operations __net_initdata net_ns_ops = { | ||
| 395 | .init = net_ns_net_init, | ||
| 396 | .exit = net_ns_net_exit, | ||
| 397 | }; | ||
| 398 | |||
| 384 | static int __init net_ns_init(void) | 399 | static int __init net_ns_init(void) |
| 385 | { | 400 | { |
| 386 | struct net_generic *ng; | 401 | struct net_generic *ng; |
| @@ -412,6 +427,8 @@ static int __init net_ns_init(void) | |||
| 412 | 427 | ||
| 413 | mutex_unlock(&net_mutex); | 428 | mutex_unlock(&net_mutex); |
| 414 | 429 | ||
| 430 | register_pernet_subsys(&net_ns_ops); | ||
| 431 | |||
| 415 | return 0; | 432 | return 0; |
| 416 | } | 433 | } |
| 417 | 434 | ||
| @@ -640,11 +657,18 @@ static int netns_install(struct nsproxy *nsproxy, void *ns) | |||
| 640 | return 0; | 657 | return 0; |
| 641 | } | 658 | } |
| 642 | 659 | ||
| 660 | static unsigned int netns_inum(void *ns) | ||
| 661 | { | ||
| 662 | struct net *net = ns; | ||
| 663 | return net->proc_inum; | ||
| 664 | } | ||
| 665 | |||
| 643 | const struct proc_ns_operations netns_operations = { | 666 | const struct proc_ns_operations netns_operations = { |
| 644 | .name = "net", | 667 | .name = "net", |
| 645 | .type = CLONE_NEWNET, | 668 | .type = CLONE_NEWNET, |
| 646 | .get = netns_get, | 669 | .get = netns_get, |
| 647 | .put = netns_put, | 670 | .put = netns_put, |
| 648 | .install = netns_install, | 671 | .install = netns_install, |
| 672 | .inum = netns_inum, | ||
| 649 | }; | 673 | }; |
| 650 | #endif | 674 | #endif |
