Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1448015
| From | "Eric W. Biederman" <ebiederm@xmission.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH v2 07/10] ipcns: Add a limit on the number of ipc namespaces |
| Date | 2016-07-21 19:00 +0200 |
| Message-ID | <rXpuj-1Dd-59@gated-at.bofh.it> (permalink) |
| References | <rXpuh-1Dd-3@gated-at.bofh.it> <rXpuh-1Dd-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
include/linux/user_namespace.h | 1 +
ipc/namespace.c | 42 +++++++++++++++++++++++++++++++-----------
kernel/user_namespace.c | 1 +
3 files changed, 33 insertions(+), 11 deletions(-)
diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
index bed2506081fe..367cf08ff63d 100644
--- a/include/linux/user_namespace.h
+++ b/include/linux/user_namespace.h
@@ -26,6 +26,7 @@ enum ucounts {
UCOUNT_USER_NAMESPACES,
UCOUNT_PID_NAMESPACES,
UCOUNT_UTS_NAMESPACES,
+ UCOUNT_IPC_NAMESPACES,
UCOUNT_COUNTS,
};
diff --git a/ipc/namespace.c b/ipc/namespace.c
index 04cb07eb81f1..3996a1e41a1d 100644
--- a/ipc/namespace.c
+++ b/ipc/namespace.c
@@ -16,33 +16,42 @@
#include "util.h"
+static bool inc_ipc_namespaces(struct user_namespace *ns)
+{
+ return inc_ucount(ns, UCOUNT_IPC_NAMESPACES);
+}
+
+static void dec_ipc_namespaces(struct user_namespace *ns)
+{
+ dec_ucount(ns, UCOUNT_IPC_NAMESPACES);
+}
+
static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns,
struct ipc_namespace *old_ns)
{
struct ipc_namespace *ns;
int err;
+ err = -ENFILE;
+ if (!inc_ipc_namespaces(user_ns))
+ goto fail;
+
+ err = -ENOMEM;
ns = kmalloc(sizeof(struct ipc_namespace), GFP_KERNEL);
if (ns == NULL)
- return ERR_PTR(-ENOMEM);
+ goto fail_dec;
err = ns_alloc_inum(&ns->ns);
- if (err) {
- kfree(ns);
- return ERR_PTR(err);
- }
+ if (err)
+ goto fail_free;
ns->ns.ops = &ipcns_operations;
atomic_set(&ns->count, 1);
ns->user_ns = get_user_ns(user_ns);
err = mq_init_ns(ns);
- if (err) {
- put_user_ns(ns->user_ns);
- ns_free_inum(&ns->ns);
- kfree(ns);
- return ERR_PTR(err);
- }
+ if (err)
+ goto fail_put;
atomic_inc(&nr_ipc_ns);
sem_init_ns(ns);
@@ -50,6 +59,16 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns,
shm_init_ns(ns);
return ns;
+
+fail_put:
+ put_user_ns(ns->user_ns);
+ ns_free_inum(&ns->ns);
+fail_free:
+ kfree(ns);
+fail_dec:
+ dec_ipc_namespaces(user_ns);
+fail:
+ return ERR_PTR(err);
}
struct ipc_namespace *copy_ipcs(unsigned long flags,
@@ -98,6 +117,7 @@ static void free_ipc_ns(struct ipc_namespace *ns)
shm_exit_ns(ns);
atomic_dec(&nr_ipc_ns);
+ dec_ipc_namespaces(ns->user_ns);
put_user_ns(ns->user_ns);
ns_free_inum(&ns->ns);
kfree(ns);
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
index 6b205c24e888..060d3e099f87 100644
--- a/kernel/user_namespace.c
+++ b/kernel/user_namespace.c
@@ -79,6 +79,7 @@ static struct ctl_table userns_table[] = {
UCOUNT_ENTRY("max_user_namespaces"),
UCOUNT_ENTRY("max_pid_namespaces"),
UCOUNT_ENTRY("max_uts_namespaces"),
+ UCOUNT_ENTRY("max_ipc_namespaces"),
{ }
};
#endif /* CONFIG_SYSCTL */
--
2.8.3
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v2 00/10] userns: sysctl limits for namespaces ebiederm@xmission.com (Eric W. Biederman) - 2016-07-21 19:00 +0200
[PATCH v2 08/10] cgroupns: Add a limit on the number of cgroup namespaces "Eric W. Biederman" <ebiederm@xmission.com> - 2016-07-21 19:00 +0200
[PATCH v2 10/10] mntns: Add a limit on the number of mount namespaces. "Eric W. Biederman" <ebiederm@xmission.com> - 2016-07-21 19:00 +0200
[PATCH v2 07/10] ipcns: Add a limit on the number of ipc namespaces "Eric W. Biederman" <ebiederm@xmission.com> - 2016-07-21 19:00 +0200
[PATCH v2 01/10] sysctl: Stop implicitly passing current into sysctl_table_root.lookup "Eric W. Biederman" <ebiederm@xmission.com> - 2016-07-21 19:00 +0200
[PATCH v2 03/10] userns: Add a limit on the number of user namespaces "Eric W. Biederman" <ebiederm@xmission.com> - 2016-07-21 19:00 +0200
Re: [PATCH v2 00/10] userns: sysctl limits for namespaces Colin Walters <walters@verbum.org> - 2016-07-22 15:40 +0200
Re: [PATCH v2 00/10] userns: sysctl limits for namespaces ebiederm@xmission.com (Eric W. Biederman) - 2016-07-22 21:00 +0200
Re: [PATCH v2 00/10] userns: sysctl limits for namespaces Kees Cook <keescook@chromium.org> - 2016-07-22 23:50 +0200
Re: [PATCH v2 00/10] userns: sysctl limits for namespaces ebiederm@xmission.com (Eric W. Biederman) - 2016-07-23 04:30 +0200
csiph-web