diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2016-08-08 15:20:23 -0400 |
---|---|---|
committer | Eric W. Biederman <ebiederm@xmission.com> | 2016-08-08 15:42:03 -0400 |
commit | aba356616386e6e573a34c6d64ed12443686e5c8 (patch) | |
tree | 6dd896d8191f5893ba69251e6916b22929579a8e | |
parent | f7af3d1c03136275b876f58644599b120cf4ffdd (diff) |
ipcns: Add a limit on the number of ipc namespaces
Acked-by: Kees Cook <keescook@chromium.org>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
-rw-r--r-- | include/linux/ipc_namespace.h | 1 | ||||
-rw-r--r-- | include/linux/user_namespace.h | 1 | ||||
-rw-r--r-- | ipc/namespace.c | 45 | ||||
-rw-r--r-- | kernel/ucount.c | 1 |
4 files changed, 37 insertions, 11 deletions
diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h index d10e54f03c09..848e5796400e 100644 --- a/include/linux/ipc_namespace.h +++ b/include/linux/ipc_namespace.h | |||
@@ -58,6 +58,7 @@ struct ipc_namespace { | |||
58 | 58 | ||
59 | /* user_ns which owns the ipc ns */ | 59 | /* user_ns which owns the ipc ns */ |
60 | struct user_namespace *user_ns; | 60 | struct user_namespace *user_ns; |
61 | struct ucounts *ucounts; | ||
61 | 62 | ||
62 | struct ns_common ns; | 63 | struct ns_common ns; |
63 | }; | 64 | }; |
diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h index f9df7dd2609a..e1d672186f00 100644 --- a/include/linux/user_namespace.h +++ b/include/linux/user_namespace.h | |||
@@ -28,6 +28,7 @@ enum ucount_type { | |||
28 | UCOUNT_USER_NAMESPACES, | 28 | UCOUNT_USER_NAMESPACES, |
29 | UCOUNT_PID_NAMESPACES, | 29 | UCOUNT_PID_NAMESPACES, |
30 | UCOUNT_UTS_NAMESPACES, | 30 | UCOUNT_UTS_NAMESPACES, |
31 | UCOUNT_IPC_NAMESPACES, | ||
31 | UCOUNT_COUNTS, | 32 | UCOUNT_COUNTS, |
32 | }; | 33 | }; |
33 | 34 | ||
diff --git a/ipc/namespace.c b/ipc/namespace.c index d87e6baa1323..730914214135 100644 --- a/ipc/namespace.c +++ b/ipc/namespace.c | |||
@@ -16,39 +16,61 @@ | |||
16 | 16 | ||
17 | #include "util.h" | 17 | #include "util.h" |
18 | 18 | ||
19 | static struct ucounts *inc_ipc_namespaces(struct user_namespace *ns) | ||
20 | { | ||
21 | return inc_ucount(ns, current_euid(), UCOUNT_IPC_NAMESPACES); | ||
22 | } | ||
23 | |||
24 | static void dec_ipc_namespaces(struct ucounts *ucounts) | ||
25 | { | ||
26 | dec_ucount(ucounts, UCOUNT_IPC_NAMESPACES); | ||
27 | } | ||
28 | |||
19 | static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns, | 29 | static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns, |
20 | struct ipc_namespace *old_ns) | 30 | struct ipc_namespace *old_ns) |
21 | { | 31 | { |
22 | struct ipc_namespace *ns; | 32 | struct ipc_namespace *ns; |
33 | struct ucounts *ucounts; | ||
23 | int err; | 34 | int err; |
24 | 35 | ||
36 | err = -ENFILE; | ||
37 | ucounts = inc_ipc_namespaces(user_ns); | ||
38 | if (!ucounts) | ||
39 | goto fail; | ||
40 | |||
41 | err = -ENOMEM; | ||
25 | ns = kmalloc(sizeof(struct ipc_namespace), GFP_KERNEL); | 42 | ns = kmalloc(sizeof(struct ipc_namespace), GFP_KERNEL); |
26 | if (ns == NULL) | 43 | if (ns == NULL) |
27 | return ERR_PTR(-ENOMEM); | 44 | goto fail_dec; |
28 | 45 | ||
29 | err = ns_alloc_inum(&ns->ns); | 46 | err = ns_alloc_inum(&ns->ns); |
30 | if (err) { | 47 | if (err) |
31 | kfree(ns); | 48 | goto fail_free; |
32 | return ERR_PTR(err); | ||
33 | } | ||
34 | ns->ns.ops = &ipcns_operations; | 49 | ns->ns.ops = &ipcns_operations; |
35 | 50 | ||
36 | atomic_set(&ns->count, 1); | 51 | atomic_set(&ns->count, 1); |
37 | ns->user_ns = get_user_ns(user_ns); | 52 | ns->user_ns = get_user_ns(user_ns); |
53 | ns->ucounts = ucounts; | ||
38 | 54 | ||
39 | err = mq_init_ns(ns); | 55 | err = mq_init_ns(ns); |
40 | if (err) { | 56 | if (err) |
41 | put_user_ns(ns->user_ns); | 57 | goto fail_put; |
42 | ns_free_inum(&ns->ns); | ||
43 | kfree(ns); | ||
44 | return ERR_PTR(err); | ||
45 | } | ||
46 | 58 | ||
47 | sem_init_ns(ns); | 59 | sem_init_ns(ns); |
48 | msg_init_ns(ns); | 60 | msg_init_ns(ns); |
49 | shm_init_ns(ns); | 61 | shm_init_ns(ns); |
50 | 62 | ||
51 | return ns; | 63 | return ns; |
64 | |||
65 | fail_put: | ||
66 | put_user_ns(ns->user_ns); | ||
67 | ns_free_inum(&ns->ns); | ||
68 | fail_free: | ||
69 | kfree(ns); | ||
70 | fail_dec: | ||
71 | dec_ipc_namespaces(ucounts); | ||
72 | fail: | ||
73 | return ERR_PTR(err); | ||
52 | } | 74 | } |
53 | 75 | ||
54 | struct ipc_namespace *copy_ipcs(unsigned long flags, | 76 | struct ipc_namespace *copy_ipcs(unsigned long flags, |
@@ -96,6 +118,7 @@ static void free_ipc_ns(struct ipc_namespace *ns) | |||
96 | msg_exit_ns(ns); | 118 | msg_exit_ns(ns); |
97 | shm_exit_ns(ns); | 119 | shm_exit_ns(ns); |
98 | 120 | ||
121 | dec_ipc_namespaces(ns->ucounts); | ||
99 | put_user_ns(ns->user_ns); | 122 | put_user_ns(ns->user_ns); |
100 | ns_free_inum(&ns->ns); | 123 | ns_free_inum(&ns->ns); |
101 | kfree(ns); | 124 | kfree(ns); |
diff --git a/kernel/ucount.c b/kernel/ucount.c index 866850e2eb92..fbab75424da6 100644 --- a/kernel/ucount.c +++ b/kernel/ucount.c | |||
@@ -70,6 +70,7 @@ static struct ctl_table user_table[] = { | |||
70 | UCOUNT_ENTRY("max_user_namespaces"), | 70 | UCOUNT_ENTRY("max_user_namespaces"), |
71 | UCOUNT_ENTRY("max_pid_namespaces"), | 71 | UCOUNT_ENTRY("max_pid_namespaces"), |
72 | UCOUNT_ENTRY("max_uts_namespaces"), | 72 | UCOUNT_ENTRY("max_uts_namespaces"), |
73 | UCOUNT_ENTRY("max_ipc_namespaces"), | ||
73 | { } | 74 | { } |
74 | }; | 75 | }; |
75 | #endif /* CONFIG_SYSCTL */ | 76 | #endif /* CONFIG_SYSCTL */ |