Linux Container Development
 help / color / mirror / Atom feed
* [PATCH] userns: Allow unprivileged reboot
@ 2012-12-27  3:39 Li Zefan
  0 siblings, 0 replies; 3+ messages in thread
From: Li Zefan @ 2012-12-27  3:39 UTC (permalink / raw)
  To: ebiederm-aS9lmoZGLiVWk0Htik3J/w; +Cc: Containers, LKML

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.

Signed-off-by: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
---
 kernel/sys.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/sys.c b/kernel/sys.c
index 265b376..24d1ef5 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -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;
 
-- 
1.8.0.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] userns: Allow unprivileged reboot
       [not found] ` <50DBC2E0.3040908-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
@ 2012-12-27  4:29   ` Eric W. Biederman
  2013-01-02 15:13   ` Serge Hallyn
  1 sibling, 0 replies; 3+ messages in thread
From: Eric W. Biederman @ 2012-12-27  4:29 UTC (permalink / raw)
  To: Li Zefan; +Cc: Containers, LKML

Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> writes:

> 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.
>
> Signed-off-by: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>

Applied to my development tree.  It will eventaully make it to my
for-next branch.

Eric

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] userns: Allow unprivileged reboot
       [not found] ` <50DBC2E0.3040908-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
  2012-12-27  4:29   ` [PATCH] userns: Allow unprivileged reboot Eric W. Biederman
@ 2013-01-02 15:13   ` Serge Hallyn
  1 sibling, 0 replies; 3+ messages in thread
From: Serge Hallyn @ 2013-01-02 15:13 UTC (permalink / raw)
  To: Li Zefan; +Cc: Containers, ebiederm-aS9lmoZGLiVWk0Htik3J/w, LKML

Quoting Li Zefan (lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org):
> 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.
> 
> Signed-off-by: Li Zefan <lizefan-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>

Thanks, Li.

fwiw,
Acked-by: Serge E. Hallyn <serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>

-serge

> ---
>  kernel/sys.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/sys.c b/kernel/sys.c
> index 265b376..24d1ef5 100644
> --- a/kernel/sys.c
> +++ b/kernel/sys.c
> @@ -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;
>  
> -- 
> 1.8.0.2
> _______________________________________________
> Containers mailing list
> Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
> https://lists.linuxfoundation.org/mailman/listinfo/containers

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-01-02 15:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <50DBC2E0.3040908@huawei.com>
     [not found] ` <50DBC2E0.3040908-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2012-12-27  4:29   ` [PATCH] userns: Allow unprivileged reboot Eric W. Biederman
2013-01-02 15:13   ` Serge Hallyn
2012-12-27  3:39 Li Zefan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox