* [PATCH] HID: sensor-hub: Avoid holding spinlock across child iteration
@ 2026-11-20 7:56 Zheng Shuhao
2026-11-20 10:50 ` Joshua Crofts
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Zheng Shuhao @ 2026-11-20 7:56 UTC (permalink / raw)
To: Jiri Kosina
Cc: Jonathan Cameron, Srinivas Pandruvada, Benjamin Tissoires,
linux-input, linux-iio, linux-kernel,
syzbot+c7c429f6851638ece81338f90c5b29ac9c0dea1f
syzbot reports a SOFTIRQ-safe -> SOFTIRQ-unsafe lock order warning during
sensor hub removal.
sensor_hub_remove() currently holds sensor_data->lock while calling
device_for_each_child(). The child iteration enters the device core and may
acquire the klist lock. Since sensor_data->lock is also acquired with
interrupts disabled by sensor_hub_raw_event(), lockdep reports a possible
lock-order inversion.
The callback only needs sensor_data->lock while checking pending.status and
completing pending.ready. Pass sensor_data to the callback and take the lock
only around that short critical section instead of holding it across
device_for_each_child().
This preserves synchronization of pending.status while avoiding the lock-order
dependency between sensor_data->lock and the device core's klist lock.
The syzbot report is available at:
https://syzkaller.appspot.com/bug?id=c7c429f6851638ece81338f90c5b29ac9c0dea1f
Testing:
- Reproduced the target lockdep warning with the unmodified kernel in 3/3
two-CPU QEMU runs.
- The warning was absent with this patch in 3/3 equivalent runs.
- Ran the HID selftests against both baseline and patched kernels:
hid_bpf: 45 passed, 1 skipped, 0 failed
hidraw: 27 passed, 0 failed
hid-core, hid-apple, hid-gamepad, hid-ite, hid-keyboard, hid-mouse,
hid-multitouch, hid-sony, and hid-tablet all passed in both runs.
- hid-usb_crash.sh and hid-wacom.sh produced TAP 1..0 / rc=2 in both
kernels because no executable test cases were collected in this minimal
QEMU environment.
- No KASAN report, use-after-free, Oops, BUG, panic, or general protection
fault was observed.
- checkpatch.pl --strict --no-signoff reports 0 errors and 0 warnings.
Reported-by: syzbot+c7c429f6851638ece81338f90c5b29ac9c0dea1f@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?id=c7c429f6851638ece81338f90c5b29ac9c0dea1f
Signed-off-by: Zheng Shuhao <viennaoffh@gmail.com>
Tested-by: Zheng Shuhao <viennaoffh@gmail.com>
---
drivers/hid/hid-sensor-hub.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
index 6470a290ebfc5..62799c26e6ec3 100644
--- a/drivers/hid/hid-sensor-hub.c
+++ b/drivers/hid/hid-sensor-hub.c
@@ -804,9 +804,13 @@ static int sensor_hub_probe(struct hid_device *hdev,
static int sensor_hub_finalize_pending_fn(struct device *dev, void *data)
{
struct hid_sensor_hub_device *hsdev = dev->platform_data;
+ struct sensor_hub_data *sensor_data = data;
+ unsigned long flags;
+ spin_lock_irqsave(&sensor_data->lock, flags);
if (hsdev->pending.status)
complete(&hsdev->pending.ready);
+ spin_unlock_irqrestore(&sensor_data->lock, flags);
return 0;
}
@@ -814,16 +818,13 @@ static int sensor_hub_finalize_pending_fn(struct device *dev, void *data)
static void sensor_hub_remove(struct hid_device *hdev)
{
struct sensor_hub_data *data = hid_get_drvdata(hdev);
- unsigned long flags;
hid_dbg(hdev, " hardware removed\n");
hid_hw_close(hdev);
hid_hw_stop(hdev);
- spin_lock_irqsave(&data->lock, flags);
- device_for_each_child(&hdev->dev, NULL,
+ device_for_each_child(&hdev->dev, data,
sensor_hub_finalize_pending_fn);
- spin_unlock_irqrestore(&data->lock, flags);
mfd_remove_devices(&hdev->dev);
mutex_destroy(&data->mutex);
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] HID: sensor-hub: Avoid holding spinlock across child iteration
2026-11-20 7:56 [PATCH] HID: sensor-hub: Avoid holding spinlock across child iteration Zheng Shuhao
@ 2026-11-20 10:50 ` Joshua Crofts
2026-11-20 10:50 ` syzbot
2026-11-20 11:09 ` Joshua Crofts
2026-11-20 12:14 ` Srinivas Pandruvada
2026-11-20 13:50 ` [PATCH v2] " Zheng Shuhao
2 siblings, 2 replies; 8+ messages in thread
From: Joshua Crofts @ 2026-11-20 10:50 UTC (permalink / raw)
To: Zheng Shuhao, Jiri Kosina
Cc: Jonathan Cameron, Srinivas Pandruvada, Benjamin Tissoires,
linux-input, linux-iio, linux-kernel,
syzbot+c7c429f6851638ece81338f90c5b29ac9c0dea1f
On 20/11/2026 08:56, Zheng Shuhao wrote:
> syzbot reports a SOFTIRQ-safe -> SOFTIRQ-unsafe lock order warning during
> sensor hub removal.
>
> sensor_hub_remove() currently holds sensor_data->lock while calling
> device_for_each_child(). The child iteration enters the device core and may
> acquire the klist lock. Since sensor_data->lock is also acquired with
> interrupts disabled by sensor_hub_raw_event(), lockdep reports a possible
> lock-order inversion.
>
> The callback only needs sensor_data->lock while checking pending.status and
> completing pending.ready. Pass sensor_data to the callback and take the lock
> only around that short critical section instead of holding it across
> device_for_each_child().
>
> This preserves synchronization of pending.status while avoiding the lock-order
> dependency between sensor_data->lock and the device core's klist lock.
>
> The syzbot report is available at:
> https://syzkaller.appspot.com/bug?id=c7c429f6851638ece81338f90c5b29ac9c0dea1f
>
> Testing:
> - Reproduced the target lockdep warning with the unmodified kernel in 3/3
> two-CPU QEMU runs.
> - The warning was absent with this patch in 3/3 equivalent runs.
> - Ran the HID selftests against both baseline and patched kernels:
> hid_bpf: 45 passed, 1 skipped, 0 failed
> hidraw: 27 passed, 0 failed
> hid-core, hid-apple, hid-gamepad, hid-ite, hid-keyboard, hid-mouse,
> hid-multitouch, hid-sony, and hid-tablet all passed in both runs.
> - hid-usb_crash.sh and hid-wacom.sh produced TAP 1..0 / rc=2 in both
> kernels because no executable test cases were collected in this minimal
> QEMU environment.
> - No KASAN report, use-after-free, Oops, BUG, panic, or general protection
> fault was observed.
> - checkpatch.pl --strict --no-signoff reports 0 errors and 0 warnings.
>
> Reported-by: syzbot+c7c429f6851638ece81338f90c5b29ac9c0dea1f@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?id=c7c429f6851638ece81338f90c5b29ac9c0dea1f
> Signed-off-by: Zheng Shuhao <viennaoffh@gmail.com>
> Tested-by: Zheng Shuhao <viennaoffh@gmail.com>
You cannot add a Tested-by tag with your name. This is reserved for when
someone independent of you tests your patch. Looking at the syzbot report
there is a reproducer, so syzbot should test it. You can make syzbot test
a patch by sending the following (note, this will trigger a test):
#syz test
--
Kind regards,
Joshua Crofts
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] HID: sensor-hub: Avoid holding spinlock across child iteration
2026-11-20 10:50 ` Joshua Crofts
@ 2026-11-20 10:50 ` syzbot
2026-11-20 11:09 ` Joshua Crofts
1 sibling, 0 replies; 8+ messages in thread
From: syzbot @ 2026-11-20 10:50 UTC (permalink / raw)
To: crofts
Cc: bentiss, crofts, jic23, jikos, linux-iio, linux-input,
linux-kernel, srinivas.pandruvada, viennaoffh
> On 20/11/2026 08:56, Zheng Shuhao wrote:
>> syzbot reports a SOFTIRQ-safe -> SOFTIRQ-unsafe lock order warning during
>> sensor hub removal.
>>
>> sensor_hub_remove() currently holds sensor_data->lock while calling
>> device_for_each_child(). The child iteration enters the device core and may
>> acquire the klist lock. Since sensor_data->lock is also acquired with
>> interrupts disabled by sensor_hub_raw_event(), lockdep reports a possible
>> lock-order inversion.
>>
>> The callback only needs sensor_data->lock while checking pending.status and
>> completing pending.ready. Pass sensor_data to the callback and take the lock
>> only around that short critical section instead of holding it across
>> device_for_each_child().
>>
>> This preserves synchronization of pending.status while avoiding the lock-order
>> dependency between sensor_data->lock and the device core's klist lock.
>>
>> The syzbot report is available at:
>> https://syzkaller.appspot.com/bug?id=c7c429f6851638ece81338f90c5b29ac9c0dea1f
>>
>> Testing:
>> - Reproduced the target lockdep warning with the unmodified kernel in 3/3
>> two-CPU QEMU runs.
>> - The warning was absent with this patch in 3/3 equivalent runs.
>> - Ran the HID selftests against both baseline and patched kernels:
>> hid_bpf: 45 passed, 1 skipped, 0 failed
>> hidraw: 27 passed, 0 failed
>> hid-core, hid-apple, hid-gamepad, hid-ite, hid-keyboard, hid-mouse,
>> hid-multitouch, hid-sony, and hid-tablet all passed in both runs.
>> - hid-usb_crash.sh and hid-wacom.sh produced TAP 1..0 / rc=2 in both
>> kernels because no executable test cases were collected in this minimal
>> QEMU environment.
>> - No KASAN report, use-after-free, Oops, BUG, panic, or general protection
>> fault was observed.
>> - checkpatch.pl --strict --no-signoff reports 0 errors and 0 warnings.
>>
>> Reported-by: syzbot+c7c429f6851638ece81338f90c5b29ac9c0dea1f@syzkaller.appspotmail.com
>> Closes: https://syzkaller.appspot.com/bug?id=c7c429f6851638ece81338f90c5b29ac9c0dea1f
>> Signed-off-by: Zheng Shuhao <viennaoffh@gmail.com>
>> Tested-by: Zheng Shuhao <viennaoffh@gmail.com>
> You cannot add a Tested-by tag with your name. This is reserved for when
> someone independent of you tests your patch. Looking at the syzbot report
> there is a reproducer, so syzbot should test it. You can make syzbot test
> a patch by sending the following (note, this will trigger a test):
>
> #syz test
I see the command but can't find the corresponding bug.
The email is sent to syzbot+HASH@syzkaller.appspotmail.com address
but the HASH does not correspond to any known bug.
Please double check the address.
>
> --
> Kind regards,
> Joshua Crofts
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] HID: sensor-hub: Avoid holding spinlock across child iteration
2026-11-20 10:50 ` Joshua Crofts
2026-11-20 10:50 ` syzbot
@ 2026-11-20 11:09 ` Joshua Crofts
2026-11-20 11:09 ` syzbot
1 sibling, 1 reply; 8+ messages in thread
From: Joshua Crofts @ 2026-11-20 11:09 UTC (permalink / raw)
To: Zheng Shuhao, Jiri Kosina
Cc: Jonathan Cameron, Srinivas Pandruvada, Benjamin Tissoires,
linux-input, linux-iio, linux-kernel,
syzbot+fb951970a334aaff00ba
On 20/11/2026 11:50, Joshua Crofts wrote:
> On 20/11/2026 08:56, Zheng Shuhao wrote:
>> syzbot reports a SOFTIRQ-safe -> SOFTIRQ-unsafe lock order warning during
>> sensor hub removal.
>>
>> sensor_hub_remove() currently holds sensor_data->lock while calling
>> device_for_each_child(). The child iteration enters the device core and may
>> acquire the klist lock. Since sensor_data->lock is also acquired with
>> interrupts disabled by sensor_hub_raw_event(), lockdep reports a possible
>> lock-order inversion.
>>
>> The callback only needs sensor_data->lock while checking pending.status and
>> completing pending.ready. Pass sensor_data to the callback and take the lock
>> only around that short critical section instead of holding it across
>> device_for_each_child().
>>
>> This preserves synchronization of pending.status while avoiding the lock-order
>> dependency between sensor_data->lock and the device core's klist lock.
>>
>> The syzbot report is available at:
>> https://syzkaller.appspot.com/bug?id=c7c429f6851638ece81338f90c5b29ac9c0dea1f
>>
>> Testing:
>> - Reproduced the target lockdep warning with the unmodified kernel in 3/3
>> two-CPU QEMU runs.
>> - The warning was absent with this patch in 3/3 equivalent runs.
>> - Ran the HID selftests against both baseline and patched kernels:
>> hid_bpf: 45 passed, 1 skipped, 0 failed
>> hidraw: 27 passed, 0 failed
>> hid-core, hid-apple, hid-gamepad, hid-ite, hid-keyboard, hid-mouse,
>> hid-multitouch, hid-sony, and hid-tablet all passed in both runs.
>> - hid-usb_crash.sh and hid-wacom.sh produced TAP 1..0 / rc=2 in both
>> kernels because no executable test cases were collected in this minimal
>> QEMU environment.
>> - No KASAN report, use-after-free, Oops, BUG, panic, or general protection
>> fault was observed.
>> - checkpatch.pl --strict --no-signoff reports 0 errors and 0 warnings.
>>
>> Reported-by: syzbot+c7c429f6851638ece81338f90c5b29ac9c0dea1f@syzkaller.appspotmail.com
>> Closes: https://syzkaller.appspot.com/bug?id=c7c429f6851638ece81338f90c5b29ac9c0dea1f
>> Signed-off-by: Zheng Shuhao <viennaoffh@gmail.com>
>> Tested-by: Zheng Shuhao <viennaoffh@gmail.com>
> You cannot add a Tested-by tag with your name. This is reserved for when
> someone independent of you tests your patch. Looking at the syzbot report
> there is a reproducer, so syzbot should test it. You can make syzbot test
> a patch by sending the following (note, this will trigger a test):
Ah, did some digging and the syzbot email is incorrect, it should be:
syzbot+fb951970a334aaff00ba@syzkaller.appspotmail.com
Cc'd the right syzbot and triggering the test.
#syz test
--
Kind regards,
Joshua Crofts
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] HID: sensor-hub: Avoid holding spinlock across child iteration
2026-11-20 11:09 ` Joshua Crofts
@ 2026-11-20 11:09 ` syzbot
0 siblings, 0 replies; 8+ messages in thread
From: syzbot @ 2026-11-20 11:09 UTC (permalink / raw)
To: crofts
Cc: bentiss, crofts, jic23, jikos, linux-iio, linux-input,
linux-kernel, srinivas.pandruvada, viennaoffh, syzkaller-bugs
>
>
> On 20/11/2026 11:50, Joshua Crofts wrote:
>> On 20/11/2026 08:56, Zheng Shuhao wrote:
>>> syzbot reports a SOFTIRQ-safe -> SOFTIRQ-unsafe lock order warning during
>>> sensor hub removal.
>>>
>>> sensor_hub_remove() currently holds sensor_data->lock while calling
>>> device_for_each_child(). The child iteration enters the device core and may
>>> acquire the klist lock. Since sensor_data->lock is also acquired with
>>> interrupts disabled by sensor_hub_raw_event(), lockdep reports a possible
>>> lock-order inversion.
>>>
>>> The callback only needs sensor_data->lock while checking pending.status and
>>> completing pending.ready. Pass sensor_data to the callback and take the lock
>>> only around that short critical section instead of holding it across
>>> device_for_each_child().
>>>
>>> This preserves synchronization of pending.status while avoiding the lock-order
>>> dependency between sensor_data->lock and the device core's klist lock.
>>>
>>> The syzbot report is available at:
>>> https://syzkaller.appspot.com/bug?id=c7c429f6851638ece81338f90c5b29ac9c0dea1f
>>>
>>> Testing:
>>> - Reproduced the target lockdep warning with the unmodified kernel in 3/3
>>> two-CPU QEMU runs.
>>> - The warning was absent with this patch in 3/3 equivalent runs.
>>> - Ran the HID selftests against both baseline and patched kernels:
>>> hid_bpf: 45 passed, 1 skipped, 0 failed
>>> hidraw: 27 passed, 0 failed
>>> hid-core, hid-apple, hid-gamepad, hid-ite, hid-keyboard, hid-mouse,
>>> hid-multitouch, hid-sony, and hid-tablet all passed in both runs.
>>> - hid-usb_crash.sh and hid-wacom.sh produced TAP 1..0 / rc=2 in both
>>> kernels because no executable test cases were collected in this minimal
>>> QEMU environment.
>>> - No KASAN report, use-after-free, Oops, BUG, panic, or general protection
>>> fault was observed.
>>> - checkpatch.pl --strict --no-signoff reports 0 errors and 0 warnings.
>>>
>>> Reported-by: syzbot+c7c429f6851638ece81338f90c5b29ac9c0dea1f@syzkaller.appspotmail.com
>>> Closes: https://syzkaller.appspot.com/bug?id=c7c429f6851638ece81338f90c5b29ac9c0dea1f
>>> Signed-off-by: Zheng Shuhao <viennaoffh@gmail.com>
>>> Tested-by: Zheng Shuhao <viennaoffh@gmail.com>
>> You cannot add a Tested-by tag with your name. This is reserved for when
>> someone independent of you tests your patch. Looking at the syzbot report
>> there is a reproducer, so syzbot should test it. You can make syzbot test
>> a patch by sending the following (note, this will trigger a test):
>
> Ah, did some digging and the syzbot email is incorrect, it should be:
>
> syzbot+fb951970a334aaff00ba@syzkaller.appspotmail.com
>
> Cc'd the right syzbot and triggering the test.
>
> #syz test
Patch testing via #syz test is temporarily disabled.
See https://github.com/google/syzkaller/issues/8122 for details.
>
> --
> Kind regards,
> Joshua Crofts
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] HID: sensor-hub: Avoid holding spinlock across child iteration
2026-11-20 7:56 [PATCH] HID: sensor-hub: Avoid holding spinlock across child iteration Zheng Shuhao
2026-11-20 10:50 ` Joshua Crofts
@ 2026-11-20 12:14 ` Srinivas Pandruvada
2026-11-20 13:49 ` Zheng Shuhao
2026-11-20 13:50 ` [PATCH v2] " Zheng Shuhao
2 siblings, 1 reply; 8+ messages in thread
From: Srinivas Pandruvada @ 2026-11-20 12:14 UTC (permalink / raw)
To: Zheng Shuhao, Jiri Kosina, ayaanmirzabaig85
Cc: Jonathan Cameron, Benjamin Tissoires, linux-input, linux-iio,
linux-kernel, syzbot+c7c429f6851638ece81338f90c5b29ac9c0dea1f
On Fri, 2026-11-20 at 15:56 +0800, Zheng Shuhao wrote:
> syzbot reports a SOFTIRQ-safe -> SOFTIRQ-unsafe lock order warning
> during
> sensor hub removal.
>
> sensor_hub_remove() currently holds sensor_data->lock while calling
> device_for_each_child(). The child iteration enters the device core
> and may
> acquire the klist lock. Since sensor_data->lock is also acquired with
> interrupts disabled by sensor_hub_raw_event(), lockdep reports a
> possible
> lock-order inversion.
>
> The callback only needs sensor_data->lock while checking
> pending.status and
> completing pending.ready. Pass sensor_data to the callback and take
> the lock
> only around that short critical section instead of holding it across
> device_for_each_child().
>
> This preserves synchronization of pending.status while avoiding the
> lock-order
> dependency between sensor_data->lock and the device core's klist
> lock.
>
> The syzbot report is available at:
> https://syzkaller.appspot.com/bug?id=c7c429f6851638ece81338f90c5b29ac9c0dea1f
>
Ayaan posted a similar patch yesterday.
Thanks,
Srinivas
> Testing:
> - Reproduced the target lockdep warning with the unmodified kernel in
> 3/3
> two-CPU QEMU runs.
> - The warning was absent with this patch in 3/3 equivalent runs.
> - Ran the HID selftests against both baseline and patched kernels:
> hid_bpf: 45 passed, 1 skipped, 0 failed
> hidraw: 27 passed, 0 failed
> hid-core, hid-apple, hid-gamepad, hid-ite, hid-keyboard, hid-mouse,
> hid-multitouch, hid-sony, and hid-tablet all passed in both runs.
> - hid-usb_crash.sh and hid-wacom.sh produced TAP 1..0 / rc=2 in both
> kernels because no executable test cases were collected in this
> minimal
> QEMU environment.
> - No KASAN report, use-after-free, Oops, BUG, panic, or general
> protection
> fault was observed.
> - checkpatch.pl --strict --no-signoff reports 0 errors and 0
> warnings.
>
> Reported-by:
> syzbot+c7c429f6851638ece81338f90c5b29ac9c0dea1f@syzkaller.appspotmail.com
> Closes:
> https://syzkaller.appspot.com/bug?id=c7c429f6851638ece81338f90c5b29ac9c0dea1f
> Signed-off-by: Zheng Shuhao <viennaoffh@gmail.com>
> Tested-by: Zheng Shuhao <viennaoffh@gmail.com>
> ---
> drivers/hid/hid-sensor-hub.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
> diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-
> hub.c
> index 6470a290ebfc5..62799c26e6ec3 100644
> --- a/drivers/hid/hid-sensor-hub.c
> +++ b/drivers/hid/hid-sensor-hub.c
> @@ -804,9 +804,13 @@ static int sensor_hub_probe(struct hid_device
> *hdev,
> static int sensor_hub_finalize_pending_fn(struct device *dev, void
> *data)
> {
> struct hid_sensor_hub_device *hsdev = dev->platform_data;
> + struct sensor_hub_data *sensor_data = data;
> + unsigned long flags;
>
> + spin_lock_irqsave(&sensor_data->lock, flags);
> if (hsdev->pending.status)
> complete(&hsdev->pending.ready);
> + spin_unlock_irqrestore(&sensor_data->lock, flags);
>
> return 0;
> }
> @@ -814,16 +818,13 @@ static int
> sensor_hub_finalize_pending_fn(struct device *dev, void *data)
> static void sensor_hub_remove(struct hid_device *hdev)
> {
> struct sensor_hub_data *data = hid_get_drvdata(hdev);
> - unsigned long flags;
>
> hid_dbg(hdev, " hardware removed\n");
> hid_hw_close(hdev);
> hid_hw_stop(hdev);
>
> - spin_lock_irqsave(&data->lock, flags);
> - device_for_each_child(&hdev->dev, NULL,
> + device_for_each_child(&hdev->dev, data,
> sensor_hub_finalize_pending_fn);
> - spin_unlock_irqrestore(&data->lock, flags);
>
> mfd_remove_devices(&hdev->dev);
> mutex_destroy(&data->mutex);
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] HID: sensor-hub: Avoid holding spinlock across child iteration
2026-11-20 12:14 ` Srinivas Pandruvada
@ 2026-11-20 13:49 ` Zheng Shuhao
0 siblings, 0 replies; 8+ messages in thread
From: Zheng Shuhao @ 2026-11-20 13:49 UTC (permalink / raw)
To: Srinivas Pandruvada, Jiri Kosina, Ayaan Mirza Baig
Cc: Jonathan Cameron, Benjamin Tissoires, linux-input, linux-iio,
linux-kernel
> Ayaan Mirza Baig posted a similar patch yesterday.
Sorry, I missed Ayaan's earlier patch. I've refined the fix to pass the
callback data and skip children without Sensor Hub platform_data, and am
sending v2 separately. The #syz test request was rejected because syzbot's
automated patch testing is temporarily unavailable.
Thanks,
Zheng
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2] HID: sensor-hub: Avoid holding spinlock across child iteration
2026-11-20 7:56 [PATCH] HID: sensor-hub: Avoid holding spinlock across child iteration Zheng Shuhao
2026-11-20 10:50 ` Joshua Crofts
2026-11-20 12:14 ` Srinivas Pandruvada
@ 2026-11-20 13:50 ` Zheng Shuhao
2 siblings, 0 replies; 8+ messages in thread
From: Zheng Shuhao @ 2026-11-20 13:50 UTC (permalink / raw)
To: linux-input
Cc: jikos, jic23, srinivas.pandruvada, bentiss, heiko, lee,
linux-iio, linux-kernel, ayaanmirzabaig85,
syzbot+fb951970a334aaff00ba
sensor_hub_remove() holds sensor_data->lock while walking the HID device's
children with device_for_each_child(). The child iteration takes the device
core's klist lock, while sensor_hub_raw_event() takes
sensor_data->lock with interrupts disabled. This creates a lock-order
inversion.
Pass sensor_data to the callback and take the lock only while examining
pending.status and completing pending.ready.
The callback also visits non-Sensor Hub children. When HID battery strength
support is enabled, the HID input layer may register a power-supply child
without platform_data. Skip children without Sensor Hub data before
dereferencing it.
Testing:
- With CONFIG_HID_BATTERY_STRENGTH=y, ran a UHID Sensor Hub/Joystick device
exposing Battery Strength through 15 create/destroy cycles across three
QEMU boots. The power-supply child was found each time; no Oops, BUG, or
KASAN report occurred.
- In the same configuration, hid_bpf passed 45 tests with 1 skip, hidraw
passed 27 tests, and hid-core, hid-apple, hid-gamepad, hid-ite,
hid-keyboard, and hid-mouse passed.
- The full HID suite was not completed; it stopped during hid-multitouch.
- The #syz test request was rejected because syzbot's automated patch
testing is temporarily unavailable.
Fixes: 8a5b38c3fd70 ("HID: hid-sensor-hub: don't use stale platform-data on remove")
Reported-by: syzbot+fb951970a334aaff00ba@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=fb951970a334aaff00ba
Signed-off-by: Zheng Shuhao <viennaoffh@gmail.com>
---
Changes in v2:
- Pass sensor_data to the callback instead of NULL.
- Skip children without Sensor Hub platform_data; add a battery-child test.
- Add Fixes and correct the syzbot address; remove the self-added Tested-by.
drivers/hid/hid-sensor-hub.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
index 6470a290ebfc5..4c447f62480b5 100644
--- a/drivers/hid/hid-sensor-hub.c
+++ b/drivers/hid/hid-sensor-hub.c
@@ -804,9 +804,16 @@ static int sensor_hub_probe(struct hid_device *hdev,
static int sensor_hub_finalize_pending_fn(struct device *dev, void *data)
{
struct hid_sensor_hub_device *hsdev = dev->platform_data;
+ struct sensor_hub_data *sensor_data = data;
+ unsigned long flags;
+
+ if (!hsdev)
+ return 0;
+ spin_lock_irqsave(&sensor_data->lock, flags);
if (hsdev->pending.status)
complete(&hsdev->pending.ready);
+ spin_unlock_irqrestore(&sensor_data->lock, flags);
return 0;
}
@@ -814,16 +821,13 @@ static int sensor_hub_finalize_pending_fn(struct device *dev, void *data)
static void sensor_hub_remove(struct hid_device *hdev)
{
struct sensor_hub_data *data = hid_get_drvdata(hdev);
- unsigned long flags;
hid_dbg(hdev, " hardware removed\n");
hid_hw_close(hdev);
hid_hw_stop(hdev);
- spin_lock_irqsave(&data->lock, flags);
- device_for_each_child(&hdev->dev, NULL,
+ device_for_each_child(&hdev->dev, data,
sensor_hub_finalize_pending_fn);
- spin_unlock_irqrestore(&data->lock, flags);
mfd_remove_devices(&hdev->dev);
mutex_destroy(&data->mutex);
--
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-11-20 13:50 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20 7:56 [PATCH] HID: sensor-hub: Avoid holding spinlock across child iteration Zheng Shuhao
2026-11-20 10:50 ` Joshua Crofts
2026-11-20 10:50 ` syzbot
2026-11-20 11:09 ` Joshua Crofts
2026-11-20 11:09 ` syzbot
2026-11-20 12:14 ` Srinivas Pandruvada
2026-11-20 13:49 ` Zheng Shuhao
2026-11-20 13:50 ` [PATCH v2] " Zheng Shuhao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®