vt: Some small vt bugfixes found by code scans
Greg Kroah-Hartman
maintainercover vt: Some small vt bugfixes found by code scans
Joshua at AISLE has been kind enough to run a bunch of scans on the tty/serial code and here are two minor fixes for the vt code that the tools found.
---
Joshua Rogers (2):
vt: stabilize tty reference in kbd_keycode with tty_port_tty_get
vt: add permission check for KDSKBMETA ioctl
drivers/tty/vt/keyboard.c | 5 ++++- drivers/tty/vt/vt_ioctl.c | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-)
---
base-commit: 8ba098e6b6ff0db8edf28528d1552be261af30d4
change-id: 20260731-tty-vt-stuff-eb7c6f3f7727
Best regards,
Signature · 1 line
Greg Kroah-Hartman <[email protected]>
Greg Kroah-Hartman
maintainerPATCH 1/2 vt: stabilize tty reference in kbd_keycode with tty_port_tty_get
From: Joshua Rogers <[email protected]>
kbd_keycode() reads vc->port.tty without acquiring a tty reference, racing against con_shutdown() which clears port.tty under a different lock. Use tty_port_tty_get()/tty_kref_put() to hold a proper reference for the duration the tty pointer is needed.
--- drivers/tty/vt/keyboard.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/tty/vt/keyboard.c +4 -1
@@ -1437,7 +1437,7 @@ static void kbd_keycode(unsigned int keycode, int down, bool hw_raw)struct keyboard_notifier_param param = { .vc = vc, .value = keycode, .down = down };int rc; - tty = vc->port.tty; + tty =tty_port_tty_get (&vc->port);if (tty && (!tty->driver_data)) {/* No driver data? Strange. Okay we fix it then. */
@@ -1497,9 +1497,12 @@ static void kbd_keycode(unsigned int keycode, int down, bool hw_raw)* characters get aren't echoed locally. This makes key repeat * usable with slow applications and under heavy loads. */ +tty_kref_put (tty);return ; } +tty_kref_put (tty); + param.shift = shift_final = (shift_state | kbd->slockstate) ^ kbd->lockstate; param.ledstate = kbd->ledflagstate; key_map = key_maps[shift_final];
Signature · 1 line
2.55.0
Greg Kroah-Hartman
maintainerPATCH 2/2 vt: add permission check for KDSKBMETA ioctl
In reply to Greg Kroah-HartmanFrom: Joshua Rogers <[email protected]>
KDSKBMETA modifies keyboard meta mode but lacks the !perm check that all other keyboard setter ioctls in vt_k_ioctl() enforce, allowing a process to change meta mode on a non-controlling console without authorization.
--- drivers/tty/vt/vt_ioctl.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/tty/vt/vt_ioctl.c +2 -0
@@ -406,6 +406,8 @@ static int vt_k_ioctl(struct tty_struct *tty, unsigned int cmd,/* this could be folded into KDSKBMODE, but for compatibility reasons it is not so easy to fold KDGKBMETA into KDGKBMODE */ case KDSKBMETA : +if (!perm) +return -EPERM ;return vt_do_kdskbmeta (console, arg);case KDGKBMETA :
Signature · 1 line
2.55.0