From: Jonathan Cameron <jic23@kernel.org>
To: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Cc: Zheng Shuhao <viennaoffh@gmail.com>,
Jiri Kosina <jikos@kernel.org>,
Benjamin Tissoires <bentiss@kernel.org>,
Heiko Stuebner <heiko@sntech.de>, Lee Jones <lee@kernel.org>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
Ayaan Mirza Baig <ayaanmirzabaig85@gmail.com>,
syzbot+fb951970a334aaff00ba@syzkaller.appspotmail.com,
Zhang Lixu <lixu.zhang@intel.com>
Subject: Re: [PATCH v2] HID: sensor-hub: Avoid holding spinlock across child iteration
Date: Sat, 21 Nov 2026 20:04:30 +0000 [thread overview]
Message-ID: <20261121200430.311d4a4c@jic23-hlaptop> (raw)
In-Reply-To: <20261121200230.6b1ccffd@jic23-hlaptop>
On Sat, 21 Nov 2026 20:02:30 +0000
Jonathan Cameron <jic23@kernel.org> wrote:
> On Fri, 20 Nov 2026 09:56:41 -0800
> Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> wrote:
>
> > On Sat, 2026-11-21 at 01:05 +0800, Zheng Shuhao wrote:
> > > > 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.
> > >
> > > It might not be reachable after hid_hw_stop(). I may have
> > > misunderstood the
> > > lockdep report and overstated this as a possible deadlock. Sorry.
> > >
> > > > How come this is possible? The HID sensor hub is only deleting its
> > > > own
> > > > children. Can you give an example here?
> > >
> > > With CONFIG_HID_BATTERY_STRENGTH=y, this UHID device creates a Sensor
> > > Hub and
> > > a Joystick battery. The HID input layer registers the battery power
> > > supply as
> > > a child of the HID device, without platform_data.
> > >
> > > With the unpatched hid-sensor-hub module, UHID_DESTROY triggers a
> > > KASAN
> > > NULL-pointer dereference in sensor_hub_finalize_pending_fn():
> > >
> > > KASAN: null-ptr-deref in range [0x0000000000000028-
> > > 0x000000000000002f]
> > > RIP: sensor_hub_finalize_pending_fn+0x44/0x65 [hid_sensor_hub]
> > > Call trace: device_for_each_child -> sensor_hub_remove ->
> > > hid_device_remove
> > > -> hid_destroy_device -> uhid_dev_destroy ->
> > > uhid_char_write
> > >
> >
> > OK, Adding to commit description will help for others.
>
> Process thing. Zhang Lixu, please do not send a new version
Sorry! That was for Zheng Shuhao.
I realised a fraction of a second too late to hit the cancel button :(
> in reply to an older one. I only spotted this today because
> I was working for patchwork. Otherwise it would be way back
> in my email history and probably lost.
>
> New version, new email thread. Avoids breaking tools and
> keeps things in order for those reviewing patches.
> It seems the LLMs are following the suggested process for the
> git project itself. As far as I aware no part of the kernel
> has ever asked for this style of replying to an earlier commit
> and many actively oppose it because it makes a massive mess
> for large series.
>
> Thanks,
>
> Jonathan
>
> >
> > Thanks,
> > Srinivas
> >
> > > The reproducer is below:
> > >
> > > #define _GNU_SOURCE
> > > #include <dirent.h>
> > > #include <errno.h>
> > > #include <fcntl.h>
> > > #include <linux/input.h>
> > > #include <linux/uhid.h>
> > > #include <poll.h>
> > > #include <stdbool.h>
> > > #include <stdio.h>
> > > #include <string.h>
> > > #include <unistd.h>
> > >
> > > static const unsigned char sensor_battery_rdesc[] = {
> > > 0x05, 0x20, /* Usage Page (Sensors) */
> > > 0x09, 0x10, /* Usage (Sensor Hub) */
> > > 0xa1, 0x01, /* Collection (Application) */
> > > 0xc0, /* End Collection */
> > > 0x05, 0x01, /* Usage Page (Generic Desktop) */
> > > 0x09, 0x04, /* Usage (Joystick) */
> > > 0xa1, 0x01, /* Collection (Application) */
> > > 0x05, 0x06, /* Usage Page (Generic Device Controls) */
> > > 0x09, 0x20, /* Usage (Battery Strength) */
> > > 0x15, 0x00, /* Logical Minimum (0) */
> > > 0x25, 0x64, /* Logical Maximum (100) */
> > > 0x75, 0x08, /* Report Size (8) */
> > > 0x95, 0x01, /* Report Count (1) */
> > > 0x81, 0x02, /* Input (Data, Variable, Absolute) */
> > > 0xc0, /* End Collection */
> > > };
> > >
> > > static int send_event(int fd, struct uhid_event *event)
> > > {
> > > ssize_t written = write(fd, event, sizeof(*event));
> > >
> > > if (written == sizeof(*event))
> > > return 0;
> > > if (written < 0)
> > > perror("write /dev/uhid");
> > > else
> > > fprintf(stderr, "short UHID write: %zd\n", written);
> > > return -1;
> > > }
> > >
> > > static bool hid_battery_exists(void)
> > > {
> > > static const char prefix[] = "hid-0003:1234:5678.";
> > > DIR *dir = opendir("/sys/class/power_supply");
> > > struct dirent *entry;
> > > bool found = false;
> > >
> > > if (!dir)
> > > return false;
> > > while ((entry = readdir(dir))) {
> > > if (!strncmp(entry->d_name, prefix, sizeof(prefix) -
> > > 1)) {
> > > found = true;
> > > break;
> > > }
> > > }
> > > closedir(dir);
> > > return found;
> > > }
> > >
> > > int main(void)
> > > {
> > > struct uhid_event event = { 0 };
> > > struct pollfd pfd;
> > > int fd, attempt;
> > > bool started = false;
> > > bool battery_found = false;
> > >
> > > fd = open("/dev/uhid", O_RDWR | O_CLOEXEC);
> > > if (fd < 0) {
> > > perror("open /dev/uhid");
> > > return 1;
> > > }
> > >
> > > event.type = UHID_CREATE2;
> > > strcpy((char *)event.u.create2.name, "sensor-hub-battery-
> > > null-test");
> > > strcpy((char *)event.u.create2.phys, "hid-null-test");
> > > event.u.create2.rd_size = sizeof(sensor_battery_rdesc);
> > > event.u.create2.bus = BUS_USB;
> > > event.u.create2.vendor = 0x1234;
> > > event.u.create2.product = 0x5678;
> > > memcpy(event.u.create2.rd_data, sensor_battery_rdesc,
> > > sizeof(sensor_battery_rdesc));
> > > if (send_event(fd, &event))
> > > goto out_close;
> > >
> > > pfd.fd = fd;
> > > pfd.events = POLLIN;
> > > if (poll(&pfd, 1, 5000) <= 0) {
> > > fprintf(stderr, "timed out waiting for
> > > UHID_START\n");
> > > goto out_destroy;
> > > }
> > > memset(&event, 0, sizeof(event));
> > > if (read(fd, &event, sizeof(event)) != sizeof(event)) {
> > > perror("read UHID event");
> > > goto out_destroy;
> > > }
> > > started = event.type == UHID_START;
> > > if (!started) {
> > > fprintf(stderr, "unexpected UHID event: %u\n",
> > > event.type);
> > > goto out_destroy;
> > > }
> > >
> > > for (attempt = 0; attempt < 50 && !hid_battery_exists();
> > > attempt++)
> > > usleep(100000);
> > > if (!hid_battery_exists()) {
> > > fprintf(stderr, "HID battery power-supply child was
> > > not created\n");
> > > goto out_destroy;
> > > }
> > > battery_found = true;
> > > puts("HID battery power-supply child created");
> > >
> > > out_destroy:
> > > memset(&event, 0, sizeof(event));
> > > event.type = UHID_DESTROY;
> > > if (send_event(fd, &event))
> > > goto out_close;
> > > usleep(300000);
> > > if (!started)
> > > goto out_close;
> > > puts("UHID device destroyed without userspace error");
> > > close(fd);
> > > return battery_found ? 0 : 1;
> > >
> > > out_close:
> > > close(fd);
> > > return 1;
> > > }
> >
>
>
prev parent reply other threads:[~2026-11-21 20:04 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 7:56 [PATCH] " 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
2026-11-20 15:12 ` Srinivas Pandruvada
2026-11-20 15:30 ` Srinivas Pandruvada
2026-11-20 17:05 ` Zheng Shuhao
2026-11-20 17:56 ` Srinivas Pandruvada
2026-11-21 20:02 ` Jonathan Cameron
2026-11-21 20:04 ` Jonathan Cameron [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=20261121200430.311d4a4c@jic23-hlaptop \
--to=jic23@kernel.org \
--cc=ayaanmirzabaig85@gmail.com \
--cc=bentiss@kernel.org \
--cc=heiko@sntech.de \
--cc=jikos@kernel.org \
--cc=lee@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lixu.zhang@intel.com \
--cc=srinivas.pandruvada@linux.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
all inboxes | Powered by JetHome®