From: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
To: Zheng Shuhao <viennaoffh@gmail.com>,
linux-input@vger.kernel.org, Zhang Lixu <lixu.zhang@intel.com>
Cc: jikos@kernel.org, jic23@kernel.org, bentiss@kernel.org,
heiko@sntech.de, lee@kernel.org, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org, ayaanmirzabaig85@gmail.com,
syzbot+fb951970a334aaff00ba@syzkaller.appspotmail.com
Subject: Re: [PATCH v2] HID: sensor-hub: Avoid holding spinlock across child iteration
Date: Fri, 20 Nov 2026 07:30:44 -0800 [thread overview]
Message-ID: <0165ee623890e4d3778390e46ad955956c512812.camel@linux.intel.com> (raw)
In-Reply-To: <573f3eb75601c17d6e766fc47a7cce1bc2274998.camel@linux.intel.com>
On Fri, 2026-11-20 at 07:12 -0800, Srinivas Pandruvada wrote:
> +Lixu
>
> On Fri, 2026-11-20 at 21:50 +0800, Zheng Shuhao wrote:
> > 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.
> >
In reality this can't happen as the
hid_hw_close() and hid_hw_stop() is called before, so there can't be
any raw_event.
> > 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.
> >
How come this is possible? The HID sensor hub is only deleting its own
children. Can you give an example here?
Thanks,
Srinivas
> > 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.
>
> None of the above tested devices are HID SENSOR HUB related, so need
> some tests.
> Hi Lixu,
>
> Please give a try.
>
> Thanks,
> Srinivas
>
> >
> > 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);
prev parent reply other threads:[~2026-11-20 15:30 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 7:56 [PATCH] HID: sensor-hub: Avoid holding spinlock across child iteration Zheng Shuhao
2026-11-20 9:34 ` sashiko-bot
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
2026-11-20 15:12 ` Srinivas Pandruvada
2026-11-20 15:30 ` Srinivas Pandruvada [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0165ee623890e4d3778390e46ad955956c512812.camel@linux.intel.com \
--to=srinivas.pandruvada@linux.intel.com \
--cc=ayaanmirzabaig85@gmail.com \
--cc=bentiss@kernel.org \
--cc=heiko@sntech.de \
--cc=jic23@kernel.org \
--cc=jikos@kernel.org \
--cc=lee@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lixu.zhang@intel.com \
--cc=syzbot+fb951970a334aaff00ba@syzkaller.appspotmail.com \
--cc=viennaoffh@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox