Skip to content

Commit 4f38821

Browse files
dtorJiri Kosina
authored andcommitted
HID: hid-input: clear unmapped usages
We should not be leaving half-mapped usages with potentially invalid keycodes, as that may confuse hidinput_find_key() when the key is located by index, which may end up feeding way too large keycode into the VT keyboard handler and cause OOB write there: BUG: KASAN: global-out-of-bounds in clear_bit include/asm-generic/bitops-instrumented.h:56 [inline] BUG: KASAN: global-out-of-bounds in kbd_keycode drivers/tty/vt/keyboard.c:1411 [inline] BUG: KASAN: global-out-of-bounds in kbd_event+0xe6b/0x3790 drivers/tty/vt/keyboard.c:1495 Write of size 8 at addr ffffffff89a1b2d8 by task syz-executor108/1722 ... kbd_keycode drivers/tty/vt/keyboard.c:1411 [inline] kbd_event+0xe6b/0x3790 drivers/tty/vt/keyboard.c:1495 input_to_handler+0x3b6/0x4c0 drivers/input/input.c:118 input_pass_values.part.0+0x2e3/0x720 drivers/input/input.c:145 input_pass_values drivers/input/input.c:949 [inline] input_set_keycode+0x290/0x320 drivers/input/input.c:954 evdev_handle_set_keycode_v2+0xc4/0x120 drivers/input/evdev.c:882 evdev_do_ioctl drivers/input/evdev.c:1150 [inline] Cc: [email protected] Reported-by: [email protected] Signed-off-by: Dmitry Torokhov <[email protected]> Tested-by: Benjamin Tissoires <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent fd09137 commit 4f38821

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

drivers/hid/hid-input.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,9 +1132,15 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
11321132
}
11331133

11341134
mapped:
1135-
if (device->driver->input_mapped && device->driver->input_mapped(device,
1136-
hidinput, field, usage, &bit, &max) < 0)
1137-
goto ignore;
1135+
if (device->driver->input_mapped &&
1136+
device->driver->input_mapped(device, hidinput, field, usage,
1137+
&bit, &max) < 0) {
1138+
/*
1139+
* The driver indicated that no further generic handling
1140+
* of the usage is desired.
1141+
*/
1142+
return;
1143+
}
11381144

11391145
set_bit(usage->type, input->evbit);
11401146

@@ -1215,9 +1221,11 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
12151221
set_bit(MSC_SCAN, input->mscbit);
12161222
}
12171223

1218-
ignore:
12191224
return;
12201225

1226+
ignore:
1227+
usage->type = 0;
1228+
usage->code = 0;
12211229
}
12221230

12231231
static void hidinput_handle_scroll(struct hid_usage *usage,

0 commit comments

Comments
 (0)