Skip to content

Commit c2b1df2

Browse files
amlutodavem330
authored andcommitted
Rename nsproxy.pid_ns to nsproxy.pid_ns_for_children
nsproxy.pid_ns is *not* the task's pid namespace. The name should clarify that. This makes it more obvious that setns on a pid namespace is weird -- it won't change the pid namespace shown in procfs. Signed-off-by: Andy Lutomirski <luto@amacapital.net> Reviewed-by: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent d661684 commit c2b1df2

4 files changed

Lines changed: 24 additions & 18 deletions

File tree

‎include/linux/nsproxy.h‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ struct fs_struct;
1414
* A structure to contain pointers to all per-process
1515
* namespaces - fs (mount), uts, network, sysvipc, etc.
1616
*
17+
* The pid namespace is an exception -- it's accessed using
18+
* task_active_pid_ns. The pid namespace here is the
19+
* namespace that children will use.
20+
*
1721
* 'count' is the number of tasks holding a reference.
1822
* The count for each namespace, then, will be the number
1923
* of nsproxies pointing to it, not the number of tasks.
@@ -27,7 +31,7 @@ struct nsproxy {
2731
struct uts_namespace *uts_ns;
2832
struct ipc_namespace *ipc_ns;
2933
struct mnt_namespace *mnt_ns;
30-
struct pid_namespace *pid_ns;
34+
struct pid_namespace *pid_ns_for_children;
3135
struct net *net_ns;
3236
};
3337
extern struct nsproxy init_nsproxy;

‎kernel/fork.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
11771177
* don't allow the creation of threads.
11781178
*/
11791179
if ((clone_flags & (CLONE_VM|CLONE_NEWPID)) &&
1180-
(task_active_pid_ns(current) != current->nsproxy->pid_ns))
1180+
(task_active_pid_ns(current) !=
1181+
current->nsproxy->pid_ns_for_children))
11811182
return ERR_PTR(-EINVAL);
11821183

11831184
retval = security_task_create(clone_flags);
@@ -1351,7 +1352,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
13511352

13521353
if (pid != &init_struct_pid) {
13531354
retval = -ENOMEM;
1354-
pid = alloc_pid(p->nsproxy->pid_ns);
1355+
pid = alloc_pid(p->nsproxy->pid_ns_for_children);
13551356
if (!pid)
13561357
goto bad_fork_cleanup_io;
13571358
}

‎kernel/nsproxy.c‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@
2929
static struct kmem_cache *nsproxy_cachep;
3030

3131
struct nsproxy init_nsproxy = {
32-
.count = ATOMIC_INIT(1),
33-
.uts_ns = &init_uts_ns,
32+
.count = ATOMIC_INIT(1),
33+
.uts_ns = &init_uts_ns,
3434
#if defined(CONFIG_POSIX_MQUEUE) || defined(CONFIG_SYSVIPC)
35-
.ipc_ns = &init_ipc_ns,
35+
.ipc_ns = &init_ipc_ns,
3636
#endif
37-
.mnt_ns = NULL,
38-
.pid_ns = &init_pid_ns,
37+
.mnt_ns = NULL,
38+
.pid_ns_for_children = &init_pid_ns,
3939
#ifdef CONFIG_NET
40-
.net_ns = &init_net,
40+
.net_ns = &init_net,
4141
#endif
4242
};
4343

@@ -85,9 +85,10 @@ static struct nsproxy *create_new_namespaces(unsigned long flags,
8585
goto out_ipc;
8686
}
8787

88-
new_nsp->pid_ns = copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns);
89-
if (IS_ERR(new_nsp->pid_ns)) {
90-
err = PTR_ERR(new_nsp->pid_ns);
88+
new_nsp->pid_ns_for_children =
89+
copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns_for_children);
90+
if (IS_ERR(new_nsp->pid_ns_for_children)) {
91+
err = PTR_ERR(new_nsp->pid_ns_for_children);
9192
goto out_pid;
9293
}
9394

@@ -100,8 +101,8 @@ static struct nsproxy *create_new_namespaces(unsigned long flags,
100101
return new_nsp;
101102

102103
out_net:
103-
if (new_nsp->pid_ns)
104-
put_pid_ns(new_nsp->pid_ns);
104+
if (new_nsp->pid_ns_for_children)
105+
put_pid_ns(new_nsp->pid_ns_for_children);
105106
out_pid:
106107
if (new_nsp->ipc_ns)
107108
put_ipc_ns(new_nsp->ipc_ns);
@@ -174,8 +175,8 @@ void free_nsproxy(struct nsproxy *ns)
174175
put_uts_ns(ns->uts_ns);
175176
if (ns->ipc_ns)
176177
put_ipc_ns(ns->ipc_ns);
177-
if (ns->pid_ns)
178-
put_pid_ns(ns->pid_ns);
178+
if (ns->pid_ns_for_children)
179+
put_pid_ns(ns->pid_ns_for_children);
179180
put_net(ns->net_ns);
180181
kmem_cache_free(nsproxy_cachep, ns);
181182
}

‎kernel/pid_namespace.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ static int pidns_install(struct nsproxy *nsproxy, void *ns)
349349
if (ancestor != active)
350350
return -EINVAL;
351351

352-
put_pid_ns(nsproxy->pid_ns);
353-
nsproxy->pid_ns = get_pid_ns(new);
352+
put_pid_ns(nsproxy->pid_ns_for_children);
353+
nsproxy->pid_ns_for_children = get_pid_ns(new);
354354
return 0;
355355
}
356356

0 commit comments

Comments
 (0)