Skip to content

Commit b515498

Browse files
hallyntorvalds
authored andcommitted
userns: add a user namespace owner of ipc ns
Changelog: Feb 15: Don't set new ipc->user_ns if we didn't create a new ipc_ns. Feb 23: Move extern declaration to ipc_namespace.h, and group fwd declarations at top. Signed-off-by: Serge E. Hallyn <serge.hallyn@canonical.com> Acked-by: "Eric W. Biederman" <ebiederm@xmission.com> Acked-by: Daniel Lezcano <daniel.lezcano@free.fr> Acked-by: David Howells <dhowells@redhat.com> Cc: James Morris <jmorris@namei.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent fc832ad commit b515498

4 files changed

Lines changed: 16 additions & 2 deletions

File tree

‎include/linux/ipc_namespace.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#define IPCNS_CALLBACK_PRI 0
1717

18+
struct user_namespace;
1819

1920
struct ipc_ids {
2021
int in_use;
@@ -56,6 +57,8 @@ struct ipc_namespace {
5657
unsigned int mq_msg_max; /* initialized to DFLT_MSGMAX */
5758
unsigned int mq_msgsize_max; /* initialized to DFLT_MSGSIZEMAX */
5859

60+
/* user_ns which owns the ipc ns */
61+
struct user_namespace *user_ns;
5962
};
6063

6164
extern struct ipc_namespace init_ipc_ns;

‎ipc/msgutil.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct ipc_namespace init_ipc_ns = {
3232
.mq_msg_max = DFLT_MSGMAX,
3333
.mq_msgsize_max = DFLT_MSGSIZEMAX,
3434
#endif
35+
.user_ns = &init_user_ns,
3536
};
3637

3738
atomic_t nr_ipc_ns = ATOMIC_INIT(1);

‎ipc/namespace.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
#include <linux/slab.h>
1212
#include <linux/fs.h>
1313
#include <linux/mount.h>
14+
#include <linux/user_namespace.h>
1415

1516
#include "util.h"
1617

17-
static struct ipc_namespace *create_ipc_ns(void)
18+
static struct ipc_namespace *create_ipc_ns(struct ipc_namespace *old_ns)
1819
{
1920
struct ipc_namespace *ns;
2021
int err;
@@ -43,14 +44,17 @@ static struct ipc_namespace *create_ipc_ns(void)
4344
ipcns_notify(IPCNS_CREATED);
4445
register_ipcns_notifier(ns);
4546

47+
ns->user_ns = old_ns->user_ns;
48+
get_user_ns(ns->user_ns);
49+
4650
return ns;
4751
}
4852

4953
struct ipc_namespace *copy_ipcs(unsigned long flags, struct ipc_namespace *ns)
5054
{
5155
if (!(flags & CLONE_NEWIPC))
5256
return get_ipc_ns(ns);
53-
return create_ipc_ns();
57+
return create_ipc_ns(ns);
5458
}
5559

5660
/*
@@ -105,6 +109,7 @@ static void free_ipc_ns(struct ipc_namespace *ns)
105109
* order to have a correct value when recomputing msgmni.
106110
*/
107111
ipcns_notify(IPCNS_REMOVED);
112+
put_user_ns(ns->user_ns);
108113
}
109114

110115
/*

‎kernel/nsproxy.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ static struct nsproxy *create_new_namespaces(unsigned long flags,
8080
err = PTR_ERR(new_nsp->ipc_ns);
8181
goto out_ipc;
8282
}
83+
if (new_nsp->ipc_ns != tsk->nsproxy->ipc_ns) {
84+
put_user_ns(new_nsp->ipc_ns->user_ns);
85+
new_nsp->ipc_ns->user_ns = task_cred_xxx(tsk, user)->user_ns;
86+
get_user_ns(new_nsp->ipc_ns->user_ns);
87+
}
8388

8489
new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
8590
if (IS_ERR(new_nsp->pid_ns)) {

0 commit comments

Comments
 (0)