* [PATCH v2] tty: allow TIOCSLCKTRMIOS with CAP_CHECKPOINT_RESTORE
@ 2023-12-08 14:36 Adrian Reber
2023-12-08 15:29 ` Andrei Vagin
0 siblings, 1 reply; 2+ messages in thread
From: Adrian Reber @ 2023-12-08 14:36 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby, linux-kernel, linux-serial
Cc: Christian Brauner
The capability CAP_CHECKPOINT_RESTORE was introduced to allow non-root
users to checkpoint and restore processes as non-root with CRIU.
This change extends CAP_CHECKPOINT_RESTORE to enable the CRIU option
'--shell-job' as non-root. CRIU's man-page describes the '--shell-job'
option like this:
Allow one to dump shell jobs. This implies the restored task will
inherit session and process group ID from the criu itself. This option
also allows to migrate a single external tty connection, to migrate
applications like top.
TIOCSLCKTRMIOS can only be done if the process has CAP_SYS_ADMIN and
this change extends it to CAP_SYS_ADMIN or CAP_CHECKPOINT_RESTORE.
With this change it is possible to checkpoint and restore processes
which have a tty connection as non-root if CAP_CHECKPOINT_RESTORE is
set.
Acked-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Adrian Reber <areber@redhat.com>
---
Changes in v2:
- replaced "if (!capable(CAP_SYS_ADMIN) && !capable(CAP_CHECKPOINT_RESTORE))"
with "if (!checkpoint_restore_ns_capable(&init_user_ns))" as suggested
by Christian Brauner
- v1: https://lore.kernel.org/linux-serial/20231206134340.7093-1-areber@redhat.com/
---
drivers/tty/tty_ioctl.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
index 4b499301a3db..85de90eebc7b 100644
--- a/drivers/tty/tty_ioctl.c
+++ b/drivers/tty/tty_ioctl.c
@@ -844,7 +844,7 @@ int tty_mode_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
ret = -EFAULT;
return ret;
case TIOCSLCKTRMIOS:
- if (!capable(CAP_SYS_ADMIN))
+ if (!checkpoint_restore_ns_capable(&init_user_ns))
return -EPERM;
copy_termios_locked(real_tty, &kterm);
if (user_termios_to_kernel_termios(&kterm,
@@ -861,7 +861,7 @@ int tty_mode_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
ret = -EFAULT;
return ret;
case TIOCSLCKTRMIOS:
- if (!capable(CAP_SYS_ADMIN))
+ if (!checkpoint_restore_ns_capable(&init_user_ns))
return -EPERM;
copy_termios_locked(real_tty, &kterm);
if (user_termios_to_kernel_termios_1(&kterm,
base-commit: 98b1cc82c4affc16f5598d4fa14b1858671b2263
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] tty: allow TIOCSLCKTRMIOS with CAP_CHECKPOINT_RESTORE
2023-12-08 14:36 [PATCH v2] tty: allow TIOCSLCKTRMIOS with CAP_CHECKPOINT_RESTORE Adrian Reber
@ 2023-12-08 15:29 ` Andrei Vagin
0 siblings, 0 replies; 2+ messages in thread
From: Andrei Vagin @ 2023-12-08 15:29 UTC (permalink / raw)
To: Adrian Reber
Cc: Greg Kroah-Hartman, Jiri Slaby, linux-kernel, linux-serial,
Christian Brauner
On Fri, Dec 8, 2023 at 6:37 AM Adrian Reber <areber@redhat.com> wrote:
>
> The capability CAP_CHECKPOINT_RESTORE was introduced to allow non-root
> users to checkpoint and restore processes as non-root with CRIU.
>
> This change extends CAP_CHECKPOINT_RESTORE to enable the CRIU option
> '--shell-job' as non-root. CRIU's man-page describes the '--shell-job'
> option like this:
>
> Allow one to dump shell jobs. This implies the restored task will
> inherit session and process group ID from the criu itself. This option
> also allows to migrate a single external tty connection, to migrate
> applications like top.
>
> TIOCSLCKTRMIOS can only be done if the process has CAP_SYS_ADMIN and
> this change extends it to CAP_SYS_ADMIN or CAP_CHECKPOINT_RESTORE.
>
> With this change it is possible to checkpoint and restore processes
> which have a tty connection as non-root if CAP_CHECKPOINT_RESTORE is
> set.
>
Acked-by: Andrei Vagin <avagin@gmail.com>
> Acked-by: Christian Brauner <brauner@kernel.org>
> Signed-off-by: Adrian Reber <areber@redhat.com>
> ---
> Changes in v2:
> - replaced "if (!capable(CAP_SYS_ADMIN) && !capable(CAP_CHECKPOINT_RESTORE))"
> with "if (!checkpoint_restore_ns_capable(&init_user_ns))" as suggested
> by Christian Brauner
> - v1: https://lore.kernel.org/linux-serial/20231206134340.7093-1-areber@redhat.com/
> ---
> drivers/tty/tty_ioctl.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
> index 4b499301a3db..85de90eebc7b 100644
> --- a/drivers/tty/tty_ioctl.c
> +++ b/drivers/tty/tty_ioctl.c
> @@ -844,7 +844,7 @@ int tty_mode_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
> ret = -EFAULT;
> return ret;
> case TIOCSLCKTRMIOS:
> - if (!capable(CAP_SYS_ADMIN))
> + if (!checkpoint_restore_ns_capable(&init_user_ns))
> return -EPERM;
> copy_termios_locked(real_tty, &kterm);
> if (user_termios_to_kernel_termios(&kterm,
> @@ -861,7 +861,7 @@ int tty_mode_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
> ret = -EFAULT;
> return ret;
> case TIOCSLCKTRMIOS:
> - if (!capable(CAP_SYS_ADMIN))
> + if (!checkpoint_restore_ns_capable(&init_user_ns))
> return -EPERM;
> copy_termios_locked(real_tty, &kterm);
> if (user_termios_to_kernel_termios_1(&kterm,
>
> base-commit: 98b1cc82c4affc16f5598d4fa14b1858671b2263
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-12-08 15:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-08 14:36 [PATCH v2] tty: allow TIOCSLCKTRMIOS with CAP_CHECKPOINT_RESTORE Adrian Reber
2023-12-08 15:29 ` Andrei Vagin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®