Skip to contentSkip to conversation

HID: wacom: battery teardown races with input reports

DISCUSSION Jinmo Yang 1 participant 1 message Nov 28 HID

lore
Share & tools
lore

Jinmo Yang

author
#0 lore raw

Found by coverage-guided fuzzing of the HID subsystem through /dev/uhid. No patch is attached; I am reporting the lifetime issue first and can test candidate fixes with the standalone and syzkaller reproducers.

Kernel: mainline 7.2.0-g66498c75b4f8 (arm64, KASAN)
Files:  drivers/hid/wacom_sys.c, drivers/hid/wacom_wac.c
Impact: use-after-free write; kernel panic
Repro:  standalone C and syzkaller; also reproduced on a Pixel 9 Pro

## Report

The clearest report is a write into a freed struct power_supply:

  BUG: KASAN: slab-use-after-free in test_and_set_bit
  Write of size 8
   queue_work_on
   schedule_work
   power_supply_changed
   wacom_notify_battery
   wacom_status_irq
   wacom_wac_irq
   wacom_raw_event
   __hid_input_report
   uhid_char_write

The object was allocated by devm_power_supply_register() from wacom_battery_work(), and freed by power_supply_dev_release() through devres_release_group() in wacom_destroy_battery(). The freeing worker and the uhid writer were different tasks.

## Analysis

wacom_destroy_battery() releases the devres group before clearing the published pointer:

  if (wacom->battery.battery) {
          devres_release_group(&wacom->hdev->dev,
                               &wacom->battery.bat_desc);
          wacom->battery.battery = NULL;
  }

At the same time, the input-report path does:

  if (battery->battery)
          power_supply_changed(battery->battery);

This leaves an immediate freed-but-non-NULL window. Merely reversing the two statements is not sufficient: an input path can load the old pointer, be overtaken by teardown, and then call power_supply_changed() on the freed object. The create/destroy side and report side need lifetime serialization, for example using the same exclusion already held by the input-report path.

The reproducer alternates the wireless-module bit in Wacom status reports, causing battery creation and destruction while continuing to inject input. It requires only /dev/uhid. Besides the KASAN report, the standalone reproducer caused a Pixel 9 Pro kernel panic in power_supply_uevent() after about 11 seconds.

## Upstream status

Rechecked against mainline, linux-next, HID maintainer branches, and lore through 2026-11-28. The defect remains unpatched and I found no matching submission.