Skip to contentSkip to conversation

HID: input: set usage type to key on keycode remap

PATCH In review Thomas Weißschuh 2 participants 2 messages Oct 28, 2021 – Nov 7, 2021 HID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 HID: input: set usage type to key on keycode remap

When a scancode is manually remapped that previously was not handled as key, then the old usage type was incorrectly reused.

This caused issues on a "04b3:301b IBM Corp. SK-8815 Keyboard" which has marked some of its keys with an invalid HID usage. These invalid usage keys are being ignored since support for USB programmable buttons was added.

The scancodes are however remapped explicitly by the systemd hwdb to the keycodes that are printed on the physical buttons. During this mapping step the existing usage is retrieved which will be found with a default type of 0 (EV_SYN) instead of EV_KEY.

The events with the correct code but EV_SYN type are not forwarded to userspace.

This also leads to a kernel oops when trying to print the report descriptor via debugfs. hid_resolv_event() tries to resolve a EV_SYN event with an EV_KEY code which leads to an out-of-bounds access in the EV_SYN names array.

Fixes bcfa8d1457 ("HID: input: Add support for Programmable Buttons")
Fixes f5854fad39 ("Input: hid-input - allow mapping unknown usages")
---
 drivers/hid/hid-input.c | 1 +
 1 file changed, 1 insertion(+)
drivers/hid/hid-input.c +1 -0
index 4b5ebeacd283..21d8cc64064d 100644
@@ -160,6 +160,7 @@ static int hidinput_setkeycode(struct input_dev *dev,
 	if (usage) {
 		*old_keycode = usage->type == EV_KEY ?
 				usage->code : KEY_RESERVED;
+		usage->type = EV_KEY;
 		usage->code = ke->keycode;
 
 		clear_bit(*old_keycode, dev->keybit);

base-commit: 42d43c92fc577dca59ed74aec7868abec8d6ca6e

Signature · 1 line
2.33.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 21 lines · Thomas Weißschuh

When a scancode is manually remapped that previously was not handled as key, then the old usage type was incorrectly reused.

This caused issues on a "04b3:301b IBM Corp. SK-8815 Keyboard" which has marked some of its keys with an invalid HID usage. These invalid usage keys are being ignored since support for USB programmable buttons was added.

The scancodes are however remapped explicitly by the systemd hwdb to the keycodes that are printed on the physical buttons. During this mapping step the existing usage is retrieved which will be found with a default type of 0 (EV_SYN) instead of EV_KEY.

The events with the correct code but EV_SYN type are not forwarded to userspace.

This also leads to a kernel oops when trying to print the report descriptor via debugfs. hid_resolv_event() tries to resolve a EV_SYN event with an EV_KEY code which leads to an out-of-bounds access in the EV_SYN names array.

Quoted 5 lines
Fixes bcfa8d1457 ("HID: input: Add support for Programmable Buttons")
Fixes f5854fad39 ("Input: hid-input - allow mapping unknown usages")

Makes sense.

Quoted 17 lines
---
 drivers/hid/hid-input.c | 1 +
 1 file changed, 1 insertion(+)
drivers/hid/hid-input.c +1 -0
index 4b5ebeacd283..21d8cc64064d 100644
@@ -160,6 +160,7 @@ static int hidinput_setkeycode(struct input_dev *dev,
 	if (usage) {
 		*old_keycode = usage->type == EV_KEY ?
 				usage->code : KEY_RESERVED;
+		usage->type = EV_KEY;
 		usage->code = ke->keycode;
 
 		clear_bit(*old_keycode, dev->keybit);
Quoted 4 lines

base-commit: 42d43c92fc577dca59ed74aec7868abec8d6ca6e

Signature · 1 line
2.33.1

Thanks.

Signature · 1 line
Dmitry