Skip to contentSkip to conversation

tty: vt: keyboard: add range check to kbs->kb_func index

PATCH In review Colin King 2 participants 2 messages Sep 20, 2017

Subsystems (2)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 tty: vt: keyboard: add range check to kbs->kb_func index

From: Colin Ian King <[email protected]>

A value outside the range 0..MAX_NR_FUNC-1 in kbs->kb_func will cause an array bounds overflow on func_table. Fix this by adding a range check.

Detected by CoverityScan, CID#401961 ("Untrusted array index read")

Fixes 079c9534a96d ("vt:tackle kbd_table")
---
 drivers/tty/vt/keyboard.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/tty/vt/keyboard.c +5 -0
index f4166263bb3a..1ecf545a96a8 100644
@@ -1982,6 +1982,11 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
 	kbs->kb_string[sizeof(kbs->kb_string)-1] = '\0';
 	i = kbs->kb_func;
 
+	if (i < 0 || i >= MAX_NR_FUNC) {
+		ret = -EINVAL;
+		goto reterr;
+	}
+
 	switch (cmd) {
 	case KDGKBSENT:
 		sz = sizeof(kbs->kb_string) - 1; /* sz should have been
Signature · 1 line
2.14.1
#1 lore raw
Quoted 19 lines · Colin King

From: Colin Ian King <[email protected]>

A value outside the range 0..MAX_NR_FUNC-1 in kbs->kb_func will cause an array bounds overflow on func_table. Fix this by adding a range check.

Detected by CoverityScan, CID#401961 ("Untrusted array index read")

Fixes 079c9534a96d ("vt:tackle kbd_table")
---
 drivers/tty/vt/keyboard.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/tty/vt/keyboard.c +0 -0
index f4166263bb3a..1ecf545a96a8 100644

drivers/tty/vt/keyboard.c int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm) · line 1985

Quoted 4 lines
drivers/tty/vt/keyboard.c +1 -0
@@ -1982,6 +1982,11 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
 	kbs->kb_string[sizeof(kbs->kb_string)-1] = '\0';
 	i = kbs->kb_func;
 
+	if (i < 0 || i >= MAX_NR_FUNC) {

kbs->kb_func is an unsigned char and MAX_NR_FUNC is 256 so this check will never be true.

regards,
dan carpenter