HID: asus: do not send keyboard init reports to touchpads
Subsystems (2)
PATCH v2 1/1 HID: asus: do not send keyboard init reports to touchpads
Commit 0919db9f3583 ("HID: asus: always fully initialize devices") added a loop during asus_probe() to send keyboard feature report initializations (asus_kbd_init) to all ASUS HID devices.
On ASUS laptops with I2C/HID touchpads (such as the ASUS E200HA), sending keyboard feature reports (FEATURE_KBD_REPORT_ID) to touchpad endpoints sends invalid feature requests to touchpad hardware, corrupting probe state and causing the touchpad to become unresponsive.
Wrap the asus_report_id_init loop in an if (!drvdata->tp) check so keyboard feature initialization only runs for actual keyboards.
Tested on ASUS E200HA (where touchpad functionality is fully restored) and ASUS VivoBook Flip 14 TP401MA (confirming zero regressions).
---
v2:
- Keep asus_start_multitouch() inside the HID_CLAIMED_INPUT check to avoid any UAF risk if input registration fails (as pointed out by Denis Benato and automated review).
- Focus the fix on skipping keyboard report initialization for touchpads.
--- drivers/hid/hid-asus.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/hid/hid-asus.c +8 -6
@@ -1294,12 +1294,14 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id)return ret; } -for (int r =0 ; r <ARRAY_SIZE (asus_report_id_init); r++) { -if (asus_has_report_id (hdev, asus_report_id_init[r])) { - ret =asus_kbd_init (hdev, asus_report_id_init[r]); -if (ret <0 ) -hid_warn (hdev,"Failed to initialize 0x%x: %d.\n" , - asus_report_id_init[r], ret); +if (!drvdata->tp) { +for (int r =0 ; r <ARRAY_SIZE (asus_report_id_init); r++) { +if (asus_has_report_id (hdev, asus_report_id_init[r])) { + ret =asus_kbd_init (hdev, asus_report_id_init[r]); +if (ret <0 ) +hid_warn (hdev,"Failed to initialize 0x%x: %d.\n" , + asus_report_id_init[r], ret); + } } }
Signature · 1 line
2.47.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Missing hid_is_usb() check before casting the parent device to a usb_interface in asus_kbd_register_leds().
- [High] Dangling pointer drvdata->kbd_backlight causes a Use-After-Free in asus_remove() if asus_hid_register_listener() fails.
- [High] Incorrect teardown order in asus_remove() cancels fn_lock_sync_work before stopping the hardware, leading to a Use-After-Free race condition.
- [High] Dangling pointer dereference of drvdata->input in asus_probe() when a device has multiple report IDs or applications and the last one has no mapped usages. --
--- Patch [1]: [PATCH v2] HID: asus: do not send keyboard init reports to touchpads --- commit 83a2843d77c483e6b894c00208643414ac5b2d26
Author: Panz Dev <[email protected]>
HID: asus: do not send keyboard init reports to touchpads
This commit avoids sending keyboard feature reports to touchpad endpoints by wrapping the initialization loop in an if (!drvdata->tp) check. This prevents sending invalid feature requests that could corrupt the touchpad probe state.
Quoted 3 lines
drivers/hid/hid-asus.c +0
-0
[ ... ]
Quoted 16 lines
drivers/hid/hid-asus.c +8
-6-for (int r =0 ; r <ARRAY_SIZE (asus_report_id_init); r++) { -if (asus_has_report_id (hdev, asus_report_id_init[r])) { - ret =asus_kbd_init (hdev, asus_report_id_init[r]); -if (ret <0 ) -hid_warn (hdev,"Failed to initialize 0x%x: %d.\n" , - asus_report_id_init[r], ret); +if (!drvdata->tp) { +for (int r =0 ; r <ARRAY_SIZE (asus_report_id_init); r++) { +if (asus_has_report_id (hdev, asus_report_id_init[r])) { + ret =asus_kbd_init (hdev, asus_report_id_init[r]); +if (ret <0 ) +hid_warn (hdev,"Failed to initialize 0x%x: %d.\n" , + asus_report_id_init[r], ret); + } } }
[ ... ]
drivers/hid/hid-asus.c
Quoted 3 lines
drivers/hid/hid-asus.c +0
-0if (drvdata->input && (hdev->claimed &HID_CLAIMED_INPUT )) {if (drvdata->tp) drvdata->input->name ="Asus TouchPad" ;
[Severity: High]
This is a pre-existing issue, but can this lead to a use-after-free?
When a device uses HID_QUIRK_MULTI_INPUT, hidinput_connect() creates a separate hid_input for each application. The asus_input_configured() function unconditionally assigns drvdata->input = hi->input.
If the last report ID processed has no valid input usages, the hid_input and its input_dev are freed by the core, leaving drvdata->input pointing to freed memory.
Since earlier valid report IDs successfully registered, HID_CLAIMED_INPUT is set. Could this dereference the freed pointer here to set the name?
While reviewing the driver, I also noticed a few other pre-existing issues in this file:
Quoted 2 lines
static int
asus_kbd_register_leds(struct hid_device *hdev){
[ ... ]
Quoted 6 lines
if (drvdata->quirks & QUIRK_ROG_ALLY_XPAD) {
intf = to_usb_interface(hdev->dev.parent);
udev = interface_to_usbdev(intf);
validate_mcu_fw_version(hdev,
le16_to_cpu(udev->descriptor.idProduct));
}[Severity: Critical]
This is a pre-existing issue, but does asus_kbd_register_leds() need to verify the transport type before casting the parent device?
If the driver is bound via a non-USB transport like an injected uhid device, the parent is not a USB interface. Can this read of the product ID access invalid memory and cause a crash?
[ ... ]
Quoted 5 lines
ret = asus_hid_register_listener(&drvdata->kbd_backlight->listener);
if (ret < 0) {
/* No need to have this still around */
devm_kfree(&hdev->dev, drvdata->kbd_backlight);
}[Severity: High]
This isn't a bug introduced by this patch, but does asus_kbd_register_leds() leave a dangling pointer if asus_hid_register_listener() fails?
The error path calls devm_kfree() on drvdata->kbd_backlight but doesn't set the pointer to NULL.
During unbind, asus_remove() checks if (drvdata->kbd_backlight) and dereferences it. Could this cause a use-after-free?
[ ... ]
Quoted 3 lines
static void
asus_remove(struct hid_device *hdev){ struct asus_drvdata *drvdata = hid_get_drvdata(hdev);
[ ... ]
Quoted 4 lines
if (drvdata->quirks & QUIRK_HID_FN_LOCK) cancel_work_sync(&drvdata->fn_lock_sync_work); hid_hw_stop(hdev);
[Severity: High]
This is a pre-existing issue, but is the teardown order in asus_remove() safe from race conditions?
cancel_work_sync() is called before hid_hw_stop(). Because the hardware is not stopped, incoming HID reports can continue to trigger asus_event() and unconditionally re-queue the worker:
drivers/hid/hid-asus.c:asus_event() {
...
if (drvdata->quirks & QUIRK_HID_FN_LOCK) {
drvdata->fn_lock = !drvdata->fn_lock;
schedule_work(&drvdata->fn_lock_sync_work);
}
...
}Could the pending work item execute after devres frees drvdata, leading to a use-after-free?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 9 lines · Panz Dev
Commit
0919db9f3583("HID: asus: always fully initialize devices") added a loop duringasus_probe()to send keyboard feature report initializations (asus_kbd_init) to all ASUS HID devices.On ASUS laptops with I2C/HID touchpads (such as the ASUS E200HA), sending keyboard feature reports (
FEATURE_KBD_REPORT_ID) to touchpad endpoints sends invalid feature requests to touchpad hardware, corrupting probe state and causing the touchpad to become unresponsive.
Quoted 8 lines
Wrap the
asus_report_id_initloop in anif (!drvdata->tp)check so keyboard feature initialization only runs for actual keyboards.Tested on ASUS E200HA (where touchpad functionality is fully restored) and ASUS VivoBook Flip 14 TP401MA (confirming zero regressions).
Fixes 0919db9f3583 ("HID: asus: always fully initialize devices")
Quoted 36 lines
Signed-off-by Panz Dev <[email protected]>---
v2:
- Keepasus_start_multitouch()inside theHID_CLAIMED_INPUTcheck to avoid any UAF risk if input registration fails (as pointed out by Denis Benato and automated review).
- Focus the fix on skipping keyboard report initialization for touchpads.--- drivers/hid/hid-asus.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)drivers/hid/hid-asus.c +8
-6@@ -1294,12 +1294,14 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id)return ret; } -for (int r =0 ; r <ARRAY_SIZE (asus_report_id_init); r++) { -if (asus_has_report_id (hdev, asus_report_id_init[r])) { - ret =asus_kbd_init (hdev, asus_report_id_init[r]); -if (ret <0 ) -hid_warn (hdev,"Failed to initialize 0x%x: %d.\n" , - asus_report_id_init[r], ret); +if (!drvdata->tp) { +for (int r =0 ; r <ARRAY_SIZE (asus_report_id_init); r++) { +if (asus_has_report_id (hdev, asus_report_id_init[r])) { + ret =asus_kbd_init (hdev, asus_report_id_init[r]); +if (ret <0 ) +hid_warn (hdev,"Failed to initialize 0x%x: %d.\n" , + asus_report_id_init[r], ret); + } } }
Quoted 18 lines · Panz Dev
Commit
0919db9f3583("HID: asus: always fully initialize devices") added a loop duringasus_probe()to send keyboard feature report initializations (asus_kbd_init) to all ASUS HID devices.On ASUS laptops with I2C/HID touchpads (such as the ASUS E200HA), sending keyboard feature reports (
FEATURE_KBD_REPORT_ID) to touchpad endpoints sends invalid feature requests to touchpad hardware, corrupting probe state and causing the touchpad to become unresponsive.Wrap the
asus_report_id_initloop in anif (!drvdata->tp)check so keyboard feature initialization only runs for actual keyboards.Tested on ASUS E200HA (where touchpad functionality is fully restored) and ASUS VivoBook Flip 14 TP401MA (confirming zero regressions).
Fixes 0919db9f3583 ("HID: asus: always fully initialize devices")Signed-off-by Panz Dev <[email protected]>
Quoted 6 lines
---
v2:
- Keepasus_start_multitouch()inside theHID_CLAIMED_INPUTcheck to avoid any UAF risk if input registration fails (as pointed out by Denis Benato and automated review).
- Focus the fix on skipping keyboard report initialization for touchpads.
Applied to hid.git#for-7.4/asus, thanks.
Signature · 2 lines
Jiri Kosina SUSE Labs