kernel: allow reboots from user_ns
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.
--- kernel/sys.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/sys.c +3 -2
@@ -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
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_BOOTprocesses in the user namespace that owns the pid namespace.Signed-off-by Glauber Costa <[email protected]>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@@ -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
Serge Hallyn
Acked-byQuoted 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_BOOTprocesses in the user namespace that owns the pid namespace.Signed-off-by Glauber Costa <[email protected]>
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@@ -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
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_BOOTprocesses in the user namespace that owns the pid namespace.Signed-off-by Glauber Costa <[email protected]>
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@@ -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
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_BOOTprocesses in the user namespace that owns the pid namespace.Signed-off-by Glauber Costa <[email protected]>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...
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_BOOTprocesses in the user namespace that owns the pid namespace.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Glauber Costa <[email protected]>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
@@ -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;
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.