tty: allow TIOCSLCKTRMIOS with CAP_CHECKPOINT_RESTORE
PATCH 1/1 tty: allow TIOCSLCKTRMIOS with CAP_CHECKPOINT_RESTORE
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.
--- drivers/tty/tty_ioctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/tty/tty_ioctl.c +2 -2
@@ -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 (!capable (CAP_SYS_ADMIN ) && !capable (CAP_CHECKPOINT_RESTORE ))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 (!capable (CAP_SYS_ADMIN ) && !capable (CAP_CHECKPOINT_RESTORE ))return -EPERM ;copy_termios_locked (real_tty, &kterm); if (user_termios_to_kernel_termios_1(&kterm,
base-commit: 98b1cc82c4affc16f5598d4fa14b1858671b2263
Signature · 1 line
2.43.0
Quoted 29 lines · Adrian Reber
The capability
CAP_CHECKPOINT_RESTOREwas introduced to allow non-root users to checkpoint and restore processes as non-root with CRIU.This change extends
CAP_CHECKPOINT_RESTOREto 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_ADMINand this change extends it toCAP_SYS_ADMINorCAP_CHECKPOINT_RESTORE.With this change it is possible to checkpoint and restore processes which have a tty connection as non-root if
CAP_CHECKPOINT_RESTOREis set.Signed-off-by Adrian Reber <[email protected]>--- drivers/tty/tty_ioctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/tty/tty_ioctl.c +0
-0
drivers/tty/tty_ioctl.c int tty_mode_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) · line 847
Quoted 5 lines
drivers/tty/tty_ioctl.c +1
-1@@ -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 (!capable (CAP_SYS_ADMIN ) && !capable (CAP_CHECKPOINT_RESTORE ))
In both cases you should be able to use:
if (!checkpoint_restore_ns_capable(&init_user_ns))
return -EPERM;
with that fixed,
Quoted 17 lines
drivers/tty/tty_ioctl.c +1
-1return -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 (!capable (CAP_SYS_ADMIN ) && !capable (CAP_CHECKPOINT_RESTORE ))return -EPERM ;copy_termios_locked (real_tty, &kterm); if (user_termios_to_kernel_termios_1(&kterm,base-commit:
98b1cc82c4affc16f5598d4fa14b1858671b2263Signature · 1 line
2.43.0