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 1/4] HID: bpf: don't allocate an empty device event buffer
Date: Fri, 04 Dec 2026 20:51:31 +0000 [thread overview]
Message-ID: <sashiko-outbox-250641@kernel.org> (raw)
In-Reply-To: <20261204-hid-bpf-event-buffer-v2-1-188e8e960231@proton.me>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] HID: bpf: race between hid_bpf_reg() and
hid_bpf_connect_device() skips hooks
--
commit 0479a84986d87f27a71dc589c8c74d25d8357acb
Author: Yassine Ouamer <yassine.ouamer@proton.me>
HID: bpf: don't allocate an empty device event buffer
This patch skips allocating the HID-BPF device event buffer in
__hid_bpf_allocate_data() when the device currently has no parsed
reports, leaving allocation to hid_bpf_connect_device() after a
subsequent probe.
> diff --git a/drivers/hid/bpf/hid_bpf_dispatch.c b/drivers/hid/bpf/hid_bpf_dispatch.c
> index 6b467c74601cb..714014560fb8d 100644
> --- a/drivers/hid/bpf/hid_bpf_dispatch.c
> +++ b/drivers/hid/bpf/hid_bpf_dispatch.c
> @@ -243,6 +243,15 @@ static int __hid_bpf_allocate_data(struct hid_device *hdev, u8 **data, u32 *size
> }
> }
>
> + /*
> + * A device whose own report descriptor was refused has no reports
> + * until a report descriptor fixup makes them and the device is probed
> + * again: nothing to allocate before, hid_bpf_connect_device() does it
> + * then. kzalloc(0) would give ZERO_SIZE_PTR, which looks allocated.
> + */
> + if (!max_report_len)
> + return 0;
[Severity: Medium]
Can this deferred allocation race with hid_bpf_connect_device() and leave
hdev->bpf.device_data NULL even after a hid_device_event program is
attached?
hid_bpf_reg() calls hid_bpf_allocate_event_data() before adding ops to
hdev->bpf.prog_list, while holding only hdev->bpf.prog_list_lock.
hid_bpf_connect_device() scans hdev->bpf.prog_list under rcu_read_lock()
without taking hdev->bpf.prog_list_lock.
When a program attaches concurrently with device probing (for example
triggered by KOBJ_ADD from device_add() before bus_probe_device()
finishes), the two paths can interleave:
CPU0 CPU1
hid_device_probe() hid_bpf_reg()
mutex_lock(&hdev->bpf.prog_list_lock)
hid_bpf_allocate_event_data(hdev)
max_report_len == 0 -> returns 0
hid_open_report()
hid_hw_start() -> hid_connect()
hid_bpf_connect_device()
scans prog_list (empty) <-- misses ops, skips allocation
list_add_rcu(&ops->list, ...prog_list)
mutex_unlock(&hdev->bpf.prog_list_lock)
The device ends up connected with ops on prog_list while
hdev->bpf.device_data remains NULL. Every subsequent input report then
hits the early NULL check in dispatch_hid_bpf_device_event() and silently
skips all attached hid_device_event programs.
Taking hdev->bpf.prog_list_lock in hid_bpf_connect_device() would
serialize the list check against hid_bpf_reg().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-hid-bpf-event-buffer-v2-0-188e8e960231@proton.me?part=1
next prev parent reply other threads:[~2026-12-04 20:51 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 [this message]
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
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-250641@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.