Skip to contentSkip to conversation

kernel: allow reboots from user_ns

PATCH In review Glauber Costa 5 participants 7 messages Feb 14, 2013 – Feb 15, 2013 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel: allow reboots from user_ns

Reboot support for pid namespaces is already implemented and it works well. However, in most containers the tasks will join all namespaces, including the now supported user namespace. In that situation, we will fail the "capable" test and won't be able to reboot.

The proposed solution is to allow reboots for CAP_SYS_BOOT processes in the user namespace that owns the pid namespace.

Cc Eric W. Biederman <[email protected]>
Cc Andrew Morton <[email protected]>
---
 kernel/sys.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/sys.c +3 -2
index 265b376..3b0958e 100644
@@ -435,9 +435,10 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
 {
 	char buffer[256];
 	int ret = 0;
+	struct pid_namespace *curr_pidns = task_active_pid_ns(current);
 
 	/* We only trust the superuser with rebooting the system. */
-	if (!capable(CAP_SYS_BOOT))
+	if (!ns_capable(curr_pidns->user_ns, CAP_SYS_BOOT))
 		return -EPERM;
 
 	/* For safety, we require "magic" arguments. */
@@ -453,7 +454,7 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
 	 * pid_namespace, the command is handled by reboot_pid_ns() which will
 	 * call do_exit().
 	 */
-	ret = reboot_pid_ns(task_active_pid_ns(current), cmd);
+	ret = reboot_pid_ns(curr_pidns, cmd);
 	if (ret)
 		return ret;
 
Signature · 1 line
1.8.1.2
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Glauber Costa

Reboot support for pid namespaces is already implemented and it works well. However, in most containers the tasks will join all namespaces, including the now supported user namespace. In that situation, we will fail the "capable" test and won't be able to reboot.

Quoted 7 lines

The proposed solution is to allow reboots for CAP_SYS_BOOT processes in the user namespace that owns the pid namespace.

Cc Eric W. Biederman <ebiederm-aS9lmoZGLiVWk0Htik3J/[email protected]>
Cc Andrew Morton <akpm-de/[email protected]>

---

Quoted 28 lines
 kernel/sys.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/sys.c +3 -2
index 265b376..3b0958e 100644
@@ -435,9 +435,10 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
 {
 	char buffer[256];
 	int ret = 0;
+	struct pid_namespace *curr_pidns = task_active_pid_ns(current);
 
 	/* We only trust the superuser with rebooting the system. */
-	if (!capable(CAP_SYS_BOOT))
+	if (!ns_capable(curr_pidns->user_ns, CAP_SYS_BOOT))
 		return -EPERM;
 
 	/* For safety, we require "magic" arguments. */
@@ -453,7 +454,7 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
 	 * pid_namespace, the command is handled by reboot_pid_ns() which will
 	 * call do_exit().
 	 */
-	ret = reboot_pid_ns(task_active_pid_ns(current), cmd);
+	ret = reboot_pid_ns(curr_pidns, cmd);
 	if (ret)
 		return ret;
 

A message that is not in the archive (sent off-list or not yet received): 1360843000-31228-1-git-send-email-glommer-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org

Acked-by
#3 lore raw
Quoted 9 lines · Glauber Costa

Reboot support for pid namespaces is already implemented and it works well. However, in most containers the tasks will join all namespaces, including the now supported user namespace. In that situation, we will fail the "capable" test and won't be able to reboot.

The proposed solution is to allow reboots for CAP_SYS_BOOT processes in the user namespace that owns the pid namespace.

Note Li Zefan sent this identical patch last year. It's in my own built userns kernel, and definately required :)

In any case,

Quoted 38 lines
Cc Eric W. Biederman <ebiederm-aS9lmoZGLiVWk0Htik3J/[email protected]>
Cc Andrew Morton <akpm-de/[email protected]>
---
 kernel/sys.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/sys.c +3 -2
index 265b376..3b0958e 100644
@@ -435,9 +435,10 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
 {
 	char buffer[256];
 	int ret = 0;
+	struct pid_namespace *curr_pidns = task_active_pid_ns(current);
 
 	/* We only trust the superuser with rebooting the system. */
-	if (!capable(CAP_SYS_BOOT))
+	if (!ns_capable(curr_pidns->user_ns, CAP_SYS_BOOT))
 		return -EPERM;
 
 	/* For safety, we require "magic" arguments. */
@@ -453,7 +454,7 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
 	 * pid_namespace, the command is handled by reboot_pid_ns() which will
 	 * call do_exit().
 	 */
-	ret = reboot_pid_ns(task_active_pid_ns(current), cmd);
+	ret = reboot_pid_ns(curr_pidns, cmd);
 	if (ret)
 		return ret;
 
Signature · 6 lines
1.8.1.2

_______________________________________________
Containers mailing list
Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linuxfoundation.org/mailman/listinfo/containers
Acked-by on v1 1/1
#4 lore raw
In reply to Glauber Costa
Quoted 9 lines · Glauber Costa

Reboot support for pid namespaces is already implemented and it works well. However, in most containers the tasks will join all namespaces, including the now supported user namespace. In that situation, we will fail the "capable" test and won't be able to reboot.

The proposed solution is to allow reboots for CAP_SYS_BOOT processes in the user namespace that owns the pid namespace.

Note Li Zefan sent this identical patch last year. It's in my own built userns kernel, and definately required :)

In any case,

Quoted 38 lines
Cc Eric W. Biederman <[email protected]>
Cc Andrew Morton <[email protected]>
---
 kernel/sys.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/sys.c +3 -2
index 265b376..3b0958e 100644
@@ -435,9 +435,10 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
 {
 	char buffer[256];
 	int ret = 0;
+	struct pid_namespace *curr_pidns = task_active_pid_ns(current);
 
 	/* We only trust the superuser with rebooting the system. */
-	if (!capable(CAP_SYS_BOOT))
+	if (!ns_capable(curr_pidns->user_ns, CAP_SYS_BOOT))
 		return -EPERM;
 
 	/* For safety, we require "magic" arguments. */
@@ -453,7 +454,7 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
 	 * pid_namespace, the command is handled by reboot_pid_ns() which will
 	 * call do_exit().
 	 */
-	ret = reboot_pid_ns(task_active_pid_ns(current), cmd);
+	ret = reboot_pid_ns(curr_pidns, cmd);
 	if (ret)
 		return ret;
 
Signature · 6 lines
1.8.1.2

_______________________________________________
Containers mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers
#5 lore raw
Quoted 6 lines · Serge Hallyn
Quoted 5 lines · Glauber Costa

Reboot support for pid namespaces is already implemented and it works well. However, in most containers the tasks will join all namespaces, including the now supported user namespace. In that situation, we will fail the "capable" test and won't be able to reboot.

Quoted 8 lines
Quoted 4 lines

The proposed solution is to allow reboots for CAP_SYS_BOOT processes in the user namespace that owns the pid namespace.

Note Li Zefan sent this identical patch last year. It's in my own built userns kernel, and definately required :)

I didn't see that, and using Linus' master my stop container scripts stopped working after I started using Eric's userns...

#6 lore raw
Quoted 10 lines · Glauber Costa
Quoted 9 lines · Serge Hallyn
Quoted 8 lines · Glauber Costa

Reboot support for pid namespaces is already implemented and it works well. However, in most containers the tasks will join all namespaces, including the now supported user namespace. In that situation, we will fail the "capable" test and won't be able to reboot.

The proposed solution is to allow reboots for CAP_SYS_BOOT processes in the user namespace that owns the pid namespace.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Note Li Zefan sent this identical patch last year. It's in my own built userns kernel, and definately required :)

I didn't see that, and using Linus' master my stop container scripts stopped working after I started using Eric's userns...

The patch has been sitting in my for-next branch for quite a while just waiting for the merge window.

Eric

commit 923c7538236564c46ee80c253a416705321f13e3

Author: Li Zefan <[email protected]>
Date:   Thu Dec 27 11:39:12 2012 +0800

userns: Allow unprivileged reboot

In a container with its own pid namespace and user namespace, rebooting the system won't reboot the host, but terminate all the processes in it and thus have the container shutdown, so it's safe.

kernel/sys.c +3 -2
index 265b376..24d1ef5 100644
@@ -433,11 +433,12 @@ static DEFINE_MUTEX(reboot_mutex);
 SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
                void __user *, arg)
 {
+       struct pid_namespace *pid_ns = task_active_pid_ns(current);
        char buffer[256];
        int ret = 0;
 
        /* We only trust the superuser with rebooting the system. */
-       if (!capable(CAP_SYS_BOOT))
+       if (!ns_capable(pid_ns->user_ns, CAP_SYS_BOOT))
                return -EPERM;
 
        /* For safety, we require "magic" arguments. */
@@ -453,7 +454,7 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
         * pid_namespace, the command is handled by reboot_pid_ns() which will
         * call do_exit().
         */
-       ret = reboot_pid_ns(task_active_pid_ns(current), cmd);
+       ret = reboot_pid_ns(pid_ns, cmd);
        if (ret)
                return ret;
#7 lore raw
Quoted 6 lines · Eric W. Biederman
Quoted 2 lines

I didn't see that, and using Linus' master my stop container scripts

Quoted 1 line

stopped working after I started using Eric's userns...

The patch has been sitting in my for-next branch for quite a while just waiting for the merge window.

Eric

Fine by me.