Skip to contentSkip to conversation

tty: vt: keyboard: fix general protection fault in k_meta

PATCH In review Soham Kute 2 participants 2 messages Feb 7 – Mar 12 TTY layer and serial drivers

lore
Share & tools
lore

Soham Kute

author
#0 lore raw

PATCH 1/1 tty: vt: keyboard: fix general protection fault in k_meta

syzbot reported a general protection fault in k_meta() caused by dereferencing an invalid keyboard pointer when checking META mode.

Add a defensive check to ensure the keyboard pointer is valid before calling vc_kbd_mode().

Reported-by [email protected]
---
 drivers/tty/vt/keyboard.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/vt/keyboard.c +1 -1
index d65fc60dd..b535d7a42 100644
@@ -880,7 +880,7 @@ static void k_meta(struct vc_data *vc, unsigned char value, char up_flag)
 	if (up_flag)
 		return;
 
-	if (vc_kbd_mode(kbd, VC_META)) {
+	if (kbd && vc_kbd_mode(kbd, VC_META)) {
 		put_queue(vc, '\033');
 		put_queue(vc, value);
 	} else
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 5 lines · Soham Kute

syzbot reported a general protection fault in k_meta() caused by dereferencing an invalid keyboard pointer when checking META mode.

Add a defensive check to ensure the keyboard pointer is valid before calling vc_kbd_mode().

How can kbd be NULL here? What causes that to happen?

Quoted 13 lines
Reported-by [email protected]
---
 drivers/tty/vt/keyboard.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/vt/keyboard.c +0 -0
index d65fc60dd..b535d7a42 100644

drivers/tty/vt/keyboard.c static void k_meta(struct vc_data *vc, unsigned char value, char up_flag) · line 883

Quoted 5 lines
drivers/tty/vt/keyboard.c +1 -1
@@ -880,7 +880,7 @@ static void k_meta(struct vc_data *vc, unsigned char value, char up_flag)
 	if (up_flag)
 		return;
 
-	if (vc_kbd_mode(kbd, VC_META)) {
+	if (kbd && vc_kbd_mode(kbd, VC_META)) {

What prevents kbd from being NULL _right_ after you check it? There's no locking here at all...

Perhaps fix the root problem here?

thanks,

greg k-h