HID: magicmouse: battery timer makes a sleeping HID request

From: Jinmo Yang

Date: Sat Nov 28 2026 - 06:06:26 EST


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

Kernel: mainline 7.2.0-ge46c86b19f4b (arm64, KASAN)
File: drivers/hid/hid-magicmouse.c
Impact: scheduling while atomic and subsequent scheduler corruption; DoS
Repro: standalone C, approximately 62 seconds

## Report

BUG: scheduling while atomic: swapper/1/0/0x00000102
schedule_timeout
__uhid_report_queue_and_wait
uhid_hid_get_report
uhid_hid_raw_request
hid_hw_raw_request
hid_hw_request
magicmouse_fetch_battery
magicmouse_battery_timer_tick
call_timer_fn
run_timer_softirq

The preempt count 0x102 and PID 0 show that the request slept while a timer
softirq was running in the idle task.

## Analysis

magicmouse_battery_timer_tick() is a timer callback and therefore runs in
atomic context. It directly calls magicmouse_fetch_battery(), which issues:

hid_hw_request(hdev, report, HID_REQ_GET_REPORT);

Whether this sleeps depends on the transport. With uhid,
uhid_hid_raw_request() waits for a userspace UHID_GET_REPORT_REPLY through
__uhid_report_queue_and_wait(), which uses schedule_timeout(). hid_hw_request
therefore cannot be assumed atomic-safe.

The standalone reproducer creates a USB Magic Trackpad 2 uhid device with a
battery feature report, permits the probe-time request to finish, then keeps
the fd open without replying to the request made by the 60-second battery
timer. It reproduced the warning at about 62 seconds. Subsequent reports in
the same runs showed failures in __schedule and unrelated task stacks, so I
classify the impact as denial of service rather than a harmless warning.

The usual shape of a fix would be to have the timer schedule work and perform
the HID request in process context, with teardown synchronously cancelling
both timer and work.

## Upstream status

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