From: sashiko-bot@kernel.org
To: "Yassine Ouamer" <yassine.ouamer@proton.me>
Cc: linux-input@vger.kernel.org, bpf@vger.kernel.org,
dmitry.torokhov@gmail.com
Subject: Re: [PATCH v2 2/4] selftests/hid: test a device event on a refused report descriptor
Date: Fri, 04 Dec 2026 20:52:07 +0000 [thread overview]
Message-ID: <sashiko-outbox-250642@kernel.org> (raw)
In-Reply-To: <20261204-hid-bpf-event-buffer-v2-2-188e8e960231@proton.me>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Low] selftests/hid: double pthread_join() in FIXTURE_TEARDOWN() on
test failure
- [Low] selftests/hid: race between uhid device_add() and
LOAD_PROGRAMS()
- [Low] selftests/hid: fixture misuse and early-fail double
pthread_join()
- [Low] selftests/hid: hid_refused_event() duplicates hid_first_event()
--
commit 24965259c6874c1e527e7846a0a8da3ce17f15d1
Author: Yassine Ouamer <yassine.ouamer@proton.me>
selftests/hid: test a device event on a refused report descriptor
This commit adds a HID-BPF selftest that creates a uhid device with a
report descriptor refused by the HID core, attaches a struct_ops program
with both a report descriptor fixup and a hid_device_event hook, and
verifies that an injected event is seen and modified by the program.
> diff --git a/tools/testing/selftests/hid/hid_bpf.c b/tools/testing/selftests/hid/hid_bpf.c
> index 8c41ebfb85e42..568d84e0eeaa5 100644
> --- a/tools/testing/selftests/hid/hid_bpf.c
> +++ b/tools/testing/selftests/hid/hid_bpf.c
> @@ -1010,6 +1010,79 @@ TEST_F(hid_bpf, test_rdesc_fixup_change_uniq_name_phys)
[ ... ]
> +TEST_F(hid_bpf, test_rdesc_fixup_refused_device_event)
> +{
> + const struct test_program progs[] = {
> + { .name = "hid_rdesc_fixup_refused" },
> + };
> + __u8 buf[MAX_BUF_SIZE] = {0};
> + void *uhid_err;
> + int err;
> +
> + if (variant->rdesc != rdesc)
> + SKIP(return, "not compatible report descriptor");
> +
> + /*
> + * The fixture's device replaced with one the kernel refuses. It starts
> + * only once the program fixed its descriptor, so the uhid events are
> + * listened to after that.
> + */
> + uhid_destroy(_metadata, &self->hid);
> + pthread_join(self->hid.tid, &uhid_err);
> + close(self->hid.uhid_fd);
> + self->hid.pid = 0x0a37;
[Severity: Low]
Should this test use its own fixture instead of reusing hid_bpf?
Neither hid_bpf variant uses variant->rdesc here: unnumbered emits a
spurious skip, and numbered creates a throwaway uhid device only to tear
it down and open-code device creation. Hardcoding 0x0a37 also collides
with the product ID already used in tools/testing/selftests/hid/hidraw.c.
A dedicated fixture or helper for creating a uhid device without starting
the listener would avoid the throwaway setup, skip, and ID collision.
> + self->hid.uhid_fd = open("/dev/uhid", O_RDWR | O_CLOEXEC);
> + ASSERT_GE(self->hid.uhid_fd, 0) TH_LOG("open uhid-cdev failed");
[Severity: Low]
Can an assertion failure before uhid_start_listener() trigger a double
pthread_join() in FIXTURE_TEARDOWN(hid_bpf)?
pthread_join(self->hid.tid, &uhid_err) has already joined the fixture's
listener thread, but self->hid.tid still holds that thread ID until
uhid_start_listener() overwrites it. If any assertion fails in between
(such as open() or LOAD_PROGRAMS()), kselftest_harness __bail() invokes
FIXTURE_TEARDOWN(hid_bpf), which unconditionally calls uhid_destroy() and
pthread_join(self->hid.tid, &uhid_err) a second time, risking a crash or
hang in teardown (and writing to fd -1 if open() failed) that masks the
original failure.
> + err = uhid_create(_metadata, self->hid.uhid_fd, self->hid.dev_id, self->hid.bus,
> + self->hid.vid, self->hid.pid, refused_rdesc, sizeof(refused_rdesc));
> + ASSERT_OK(err) TH_LOG("create uhid device failed");
> + self->hid.hid_id = get_hid_id(&self->hid);
> + ASSERT_GT(self->hid.hid_id, 0) TH_LOG("Could not locate uhid device id");
> +
> + LOAD_PROGRAMS(progs);
> +
> + err = uhid_start_listener(_metadata, &self->hid.tid, self->hid.uhid_fd);
[Severity: Low]
Can LOAD_PROGRAMS(progs) race with asynchronous uhid device registration?
uhid_create() schedules uhid_device_add_worker() on system_wq and returns
immediately. Unlike setup_uhid(), which waits for UHID_START first, this
test proceeds straight from get_hid_id() into LOAD_PROGRAMS(progs) as soon
as the sysfs uevent file appears, before device_add() finishes:
test thread kworker (uhid_device_add_worker)
uhid_create() -> UHID_CREATE2
hid_add_device() -> device_add()
kobject_add()
device_create_file(...uevent)
get_hid_id() (reads uevent)
LOAD_PROGRAMS(progs)
bpf_map__attach_struct_ops()
hid_bpf_reg()
hid_get_device()
bus_find_device() <-- -EINVAL, not on bus yet
bus_add_device()
dev_set_ready_to_probe()
bus_probe_device()
If hid_bpf_reg() runs between bus_add_device() and
dev_set_ready_to_probe(), hid_bpf_reconnect() hits -EPROBE_DEFER and
open_hidraw() can time out before the hidraw node appears. If it sets
rdesc_ops before bus_probe_device(), the initial probe plus reprobe can
queue UHID_START, UHID_STOP, UHID_START, causing uhid_event() to set
uhid_stopped and exit the listener thread prematurely once
uhid_start_listener() starts.
> diff --git a/tools/testing/selftests/hid/progs/hid.c b/tools/testing/selftests/hid/progs/hid.c
> index 48aa8088cc53e..88aa122f4d94f 100644
> --- a/tools/testing/selftests/hid/progs/hid.c
> +++ b/tools/testing/selftests/hid/progs/hid.c
> @@ -639,3 +639,56 @@ SEC(".struct_ops.link")
[ ... ]
> +SEC("?struct_ops/hid_device_event")
> +int BPF_PROG(hid_refused_event, struct hid_bpf_ctx *hid_ctx, enum hid_report_type type)
> +{
> + __u8 *rw_data = hid_bpf_get_data(hid_ctx, 0 /* offset */, 3 /* size */);
> +
> + if (!rw_data)
> + return 0; /* EPERM check */
> +
> + callback_check = rw_data[1];
> +
> + rw_data[2] = rw_data[1] + 5;
> +
> + return hid_ctx->size;
> +}
> +
> +SEC(".struct_ops.link")
> +struct hid_bpf_ops rdesc_fixup_refused = {
> + .hid_rdesc_fixup = (void *)hid_rdesc_fixup_refused,
> + .hid_device_event = (void *)hid_refused_event,
> +};
[Severity: Low]
Can rdesc_fixup_refused reuse hid_first_event instead of adding
hid_refused_event?
hid_refused_event() is identical to the existing hid_first_event() in this
file, and libbpf supports referencing the same struct_ops program from
multiple .struct_ops.link maps.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-hid-bpf-event-buffer-v2-0-188e8e960231@proton.me?part=2
next prev parent reply other threads:[~2026-12-04 20:52 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 20:36 [PATCH v2 0/4] HID: bpf: two fixes for the device event buffer Yassine Ouamer via B4 Relay
2026-12-04 20:36 ` Yassine Ouamer
2026-12-04 20:36 ` [PATCH v2 1/4] HID: bpf: don't allocate an empty " Yassine Ouamer via B4 Relay
2026-12-04 20:36 ` Yassine Ouamer
2026-12-04 20:51 ` sashiko-bot
2026-12-04 20:36 ` [PATCH v2 2/4] selftests/hid: test a device event on a refused report descriptor Yassine Ouamer
2026-12-04 20:36 ` Yassine Ouamer via B4 Relay
2026-12-04 20:52 ` sashiko-bot [this message]
2026-12-04 20:36 ` [PATCH v2 3/4] HID: bpf: don't copy a report longer than the device event buffer Yassine Ouamer via B4 Relay
2026-12-04 20:36 ` Yassine Ouamer
2026-12-04 20:36 ` [PATCH v2 4/4] selftests/hid: test a report longer than its descriptor declares Yassine Ouamer
2026-12-04 20:36 ` Yassine Ouamer via B4 Relay
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=sashiko-outbox-250642@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=yassine.ouamer@proton.me \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.