提交 142e1d1d 编写于 作者: E Eric W. Biederman

userns: Allow unprivileged use of setns.

- 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: NSerge Hallyn <serge.hallyn@canonical.com>
Signed-off-by: N"Eric W. Biederman" <ebiederm@xmission.com>
上级 b33c77ef
...@@ -161,8 +161,12 @@ static void ipcns_put(void *ns) ...@@ -161,8 +161,12 @@ static void ipcns_put(void *ns)
return put_ipc_ns(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 */ /* Ditch state from the old ipc namespace */
exit_sem(current); exit_sem(current);
put_ipc_ns(nsproxy->ipc_ns); put_ipc_ns(nsproxy->ipc_ns);
......
...@@ -242,9 +242,6 @@ SYSCALL_DEFINE2(setns, int, fd, int, nstype) ...@@ -242,9 +242,6 @@ SYSCALL_DEFINE2(setns, int, fd, int, nstype)
struct file *file; struct file *file;
int err; int err;
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
file = proc_ns_fget(fd); file = proc_ns_fget(fd);
if (IS_ERR(file)) if (IS_ERR(file))
return PTR_ERR(file); return PTR_ERR(file);
......
...@@ -102,8 +102,13 @@ static void utsns_put(void *ns) ...@@ -102,8 +102,13 @@ static void utsns_put(void *ns)
put_uts_ns(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); get_uts_ns(ns);
put_uts_ns(nsproxy->uts_ns); put_uts_ns(nsproxy->uts_ns);
nsproxy->uts_ns = ns; nsproxy->uts_ns = ns;
......
...@@ -630,8 +630,13 @@ static void netns_put(void *ns) ...@@ -630,8 +630,13 @@ static void netns_put(void *ns)
static int netns_install(struct nsproxy *nsproxy, 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); put_net(nsproxy->net_ns);
nsproxy->net_ns = get_net(ns); nsproxy->net_ns = get_net(net);
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册