[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240115082420.13372-1-mengjingzi@iie.ac.cn>
Date: Mon, 15 Jan 2024 16:24:20 +0800
From: Jingzi Meng <mengjingzi@....ac.cn>
To: gregkh@...uxfoundation.org
Cc: jirislaby@...nel.org,
linux-kernel@...r.kernel.org,
linux-serial@...r.kernel.org
Subject: [PATCH] tty: change the privilege required for tty operarions
Currently, CAP_SYS_ADMIN is responsible for tty-related functions in
tty_ioctl(): TIOCSTI, TIOCCONS, TIOCVHANGUP. CAP_SYS_ADMIN is already
overloaded, change it to CAP_SYS_TTY_CONFIG for a more fine-grained
and accurate access control.
Signed-off-by: Jingzi Meng <mengjingzi@....ac.cn>
---
The userland api affected by this change is the ioctl system call,
especially when the second argument is TIOCSTI, TIOCCONS, TIOCVHANGUP,
which now requires sys_tty_config instead of sys_admin. Tested on Debian
with kernel 6.7.0-rc5.
drivers/tty/tty_io.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index f3ca2105b66d..c81479366317 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -2286,7 +2286,7 @@ static int tiocsti(struct tty_struct *tty, u8 __user *p)
if (!tty_legacy_tiocsti && !capable(CAP_SYS_ADMIN))
return -EIO;
- if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
+ if ((current->signal->tty != tty) && !capable(CAP_SYS_TTY_CONFIG))
return -EPERM;
if (get_user(ch, p))
return -EFAULT;
@@ -2390,7 +2390,7 @@ static int tiocswinsz(struct tty_struct *tty, struct winsize __user *arg)
*/
static int tioccons(struct file *file)
{
- if (!capable(CAP_SYS_ADMIN))
+ if (!capable(CAP_SYS_TTY_CONFIG))
return -EPERM;
if (file->f_op->write_iter == redirected_tty_write) {
struct file *f;
@@ -2719,7 +2719,7 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
case TIOCSETD:
return tiocsetd(tty, p);
case TIOCVHANGUP:
- if (!capable(CAP_SYS_ADMIN))
+ if (!capable(CAP_SYS_TTY_CONFIG))
return -EPERM;
tty_vhangup(tty);
return 0;
--
2.20.1
Powered by blists - more mailing lists