Skip to content

Commit 142e1d1

Browse files
committed
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: Serge Hallyn <[email protected]> Signed-off-by: "Eric W. Biederman" <[email protected]>
1 parent b33c77e commit 142e1d1

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

ipc/namespace.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,12 @@ static void ipcns_put(void *ns)
161161
return put_ipc_ns(ns);
162162
}
163163

164-
static int ipcns_install(struct nsproxy *nsproxy, void *ns)
164+
static int ipcns_install(struct nsproxy *nsproxy, void *new)
165165
{
166+
struct ipc_namespace *ns = new;
167+
if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN))
168+
return -EPERM;
169+
166170
/* Ditch state from the old ipc namespace */
167171
exit_sem(current);
168172
put_ipc_ns(nsproxy->ipc_ns);

kernel/nsproxy.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,6 @@ SYSCALL_DEFINE2(setns, int, fd, int, nstype)
242242
struct file *file;
243243
int err;
244244

245-
if (!capable(CAP_SYS_ADMIN))
246-
return -EPERM;
247-
248245
file = proc_ns_fget(fd);
249246
if (IS_ERR(file))
250247
return PTR_ERR(file);

kernel/utsname.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,13 @@ static void utsns_put(void *ns)
102102
put_uts_ns(ns);
103103
}
104104

105-
static int utsns_install(struct nsproxy *nsproxy, void *ns)
105+
static int utsns_install(struct nsproxy *nsproxy, void *new)
106106
{
107+
struct uts_namespace *ns = new;
108+
109+
if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN))
110+
return -EPERM;
111+
107112
get_uts_ns(ns);
108113
put_uts_ns(nsproxy->uts_ns);
109114
nsproxy->uts_ns = ns;

net/core/net_namespace.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,13 @@ static void netns_put(void *ns)
630630

631631
static int netns_install(struct nsproxy *nsproxy, void *ns)
632632
{
633+
struct net *net = ns;
634+
635+
if (!ns_capable(net->user_ns, CAP_SYS_ADMIN))
636+
return -EPERM;
637+
633638
put_net(nsproxy->net_ns);
634-
nsproxy->net_ns = get_net(ns);
639+
nsproxy->net_ns = get_net(net);
635640
return 0;
636641
}
637642

0 commit comments

Comments
 (0)