Skip to content

Commit

Permalink
userns: Allow unprivileged use of setns.
Browse files Browse the repository at this point in the history
- Push the permission check from the core setns syscall into
  the setns install methods where the user namespace of the
  target namespace can be determined, and used in a ns_capable
  call.

Acked-by: Serge Hallyn <[email protected]>
Signed-off-by: "Eric W. Biederman" <[email protected]>
  • Loading branch information
ebiederm committed Nov 20, 2012
1 parent b33c77e commit 142e1d1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
6 changes: 5 additions & 1 deletion ipc/namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,12 @@ static void ipcns_put(void *ns)
return put_ipc_ns(ns);
}

static int ipcns_install(struct nsproxy *nsproxy, void *ns)
static int ipcns_install(struct nsproxy *nsproxy, void *new)
{
struct ipc_namespace *ns = new;
if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN))
return -EPERM;

/* Ditch state from the old ipc namespace */
exit_sem(current);
put_ipc_ns(nsproxy->ipc_ns);
Expand Down
3 changes: 0 additions & 3 deletions kernel/nsproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,6 @@ SYSCALL_DEFINE2(setns, int, fd, int, nstype)
struct file *file;
int err;

if (!capable(CAP_SYS_ADMIN))
return -EPERM;

file = proc_ns_fget(fd);
if (IS_ERR(file))
return PTR_ERR(file);
Expand Down
7 changes: 6 additions & 1 deletion kernel/utsname.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,13 @@ static void utsns_put(void *ns)
put_uts_ns(ns);
}

static int utsns_install(struct nsproxy *nsproxy, void *ns)
static int utsns_install(struct nsproxy *nsproxy, void *new)
{
struct uts_namespace *ns = new;

if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN))
return -EPERM;

get_uts_ns(ns);
put_uts_ns(nsproxy->uts_ns);
nsproxy->uts_ns = ns;
Expand Down
7 changes: 6 additions & 1 deletion net/core/net_namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,13 @@ static void netns_put(void *ns)

static int netns_install(struct nsproxy *nsproxy, void *ns)
{
struct net *net = ns;

if (!ns_capable(net->user_ns, CAP_SYS_ADMIN))
return -EPERM;

put_net(nsproxy->net_ns);
nsproxy->net_ns = get_net(ns);
nsproxy->net_ns = get_net(net);
return 0;
}

Expand Down

0 comments on commit 142e1d1

Please sign in to comment.