Commit aba35661 authored by Eric W. Biederman's avatar Eric W. Biederman

ipcns: Add a limit on the number of ipc namespaces

Acked-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
parent f7af3d1c
...@@ -58,6 +58,7 @@ struct ipc_namespace { ...@@ -58,6 +58,7 @@ struct ipc_namespace {
/* user_ns which owns the ipc ns */ /* user_ns which owns the ipc ns */
struct user_namespace *user_ns; struct user_namespace *user_ns;
struct ucounts *ucounts;
struct ns_common ns; struct ns_common ns;
}; };
......
...@@ -28,6 +28,7 @@ enum ucount_type { ...@@ -28,6 +28,7 @@ enum ucount_type {
UCOUNT_USER_NAMESPACES, UCOUNT_USER_NAMESPACES,
UCOUNT_PID_NAMESPACES, UCOUNT_PID_NAMESPACES,
UCOUNT_UTS_NAMESPACES, UCOUNT_UTS_NAMESPACES,
UCOUNT_IPC_NAMESPACES,
UCOUNT_COUNTS, UCOUNT_COUNTS,
}; };
......
...@@ -16,39 +16,61 @@ ...@@ -16,39 +16,61 @@
#include "util.h" #include "util.h"
static struct ucounts *inc_ipc_namespaces(struct user_namespace *ns)
{
return inc_ucount(ns, current_euid(), UCOUNT_IPC_NAMESPACES);
}
static void dec_ipc_namespaces(struct ucounts *ucounts)
{
dec_ucount(ucounts, UCOUNT_IPC_NAMESPACES);
}
static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns, static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns,
struct ipc_namespace *old_ns) struct ipc_namespace *old_ns)
{ {
struct ipc_namespace *ns; struct ipc_namespace *ns;
struct ucounts *ucounts;
int err; int err;
err = -ENFILE;
ucounts = inc_ipc_namespaces(user_ns);
if (!ucounts)
goto fail;
err = -ENOMEM;
ns = kmalloc(sizeof(struct ipc_namespace), GFP_KERNEL); ns = kmalloc(sizeof(struct ipc_namespace), GFP_KERNEL);
if (ns == NULL) if (ns == NULL)
return ERR_PTR(-ENOMEM); goto fail_dec;
err = ns_alloc_inum(&ns->ns); err = ns_alloc_inum(&ns->ns);
if (err) { if (err)
kfree(ns); goto fail_free;
return ERR_PTR(err);
}
ns->ns.ops = &ipcns_operations; ns->ns.ops = &ipcns_operations;
atomic_set(&ns->count, 1); atomic_set(&ns->count, 1);
ns->user_ns = get_user_ns(user_ns); ns->user_ns = get_user_ns(user_ns);
ns->ucounts = ucounts;
err = mq_init_ns(ns); err = mq_init_ns(ns);
if (err) { if (err)
put_user_ns(ns->user_ns); goto fail_put;
ns_free_inum(&ns->ns);
kfree(ns);
return ERR_PTR(err);
}
sem_init_ns(ns); sem_init_ns(ns);
msg_init_ns(ns); msg_init_ns(ns);
shm_init_ns(ns); shm_init_ns(ns);
return 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(ucounts);
fail:
return ERR_PTR(err);
} }
struct ipc_namespace *copy_ipcs(unsigned long flags, struct ipc_namespace *copy_ipcs(unsigned long flags,
...@@ -96,6 +118,7 @@ static void free_ipc_ns(struct ipc_namespace *ns) ...@@ -96,6 +118,7 @@ static void free_ipc_ns(struct ipc_namespace *ns)
msg_exit_ns(ns); msg_exit_ns(ns);
shm_exit_ns(ns); shm_exit_ns(ns);
dec_ipc_namespaces(ns->ucounts);
put_user_ns(ns->user_ns); put_user_ns(ns->user_ns);
ns_free_inum(&ns->ns); ns_free_inum(&ns->ns);
kfree(ns); kfree(ns);
......
...@@ -70,6 +70,7 @@ static struct ctl_table user_table[] = { ...@@ -70,6 +70,7 @@ static struct ctl_table user_table[] = {
UCOUNT_ENTRY("max_user_namespaces"), UCOUNT_ENTRY("max_user_namespaces"),
UCOUNT_ENTRY("max_pid_namespaces"), UCOUNT_ENTRY("max_pid_namespaces"),
UCOUNT_ENTRY("max_uts_namespaces"), UCOUNT_ENTRY("max_uts_namespaces"),
UCOUNT_ENTRY("max_ipc_namespaces"),
{ } { }
}; };
#endif /* CONFIG_SYSCTL */ #endif /* CONFIG_SYSCTL */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment