From: sashiko-bot@kernel.org
To: "Xiang Mei" <xmei5@asu.edu>
Cc: linux-input@vger.kernel.org, bpf@vger.kernel.org,
dmitry.torokhov@gmail.com
Subject: Re: [PATCH 1/2] HID: core: release the HID-BPF event buffer on hid_connect()'s no-listeners exit
Date: Mon, 30 Nov 2026 22:21:35 +0000 [thread overview]
Message-ID: <sashiko-outbox-242098@kernel.org> (raw)
In-Reply-To: <20261130220315.659533-2-xmei5@asu.edu>
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] HID: bpf: out-of-bounds read in
dispatch_hid_bpf_device_event() [1]
--
commit c402dbbc172b7dd281582dc06c3550cedb6797b3
Author: Xiang Mei <xmei5@asu.edu>
HID: core: release the HID-BPF event buffer on hid_connect()'s no-listeners exit
This commit calls hid_bpf_disconnect_device() on hid_connect()'s
no-listeners error path so that a stale hdev->bpf.device_data buffer is
not retained across a subsequent reprobe.
> diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
> index 4a47deb9d833f..3f93b0d485376 100644
> --- a/drivers/hid/hid-core.c
> +++ b/drivers/hid/hid-core.c
> @@ -2339,6 +2339,7 @@ int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
> * to any other listener. */
> if (!hdev->claimed && !hdev->driver->raw_event) {
> hid_err(hdev, "device has no listeners, quitting\n");
> + hid_bpf_disconnect_device(hdev);
> return -ENODEV;
> }
[Severity: Critical]
This problem wasn't introduced by this patch, but can
dispatch_hid_bpf_device_event() still read past the end of data (or write
past the end of ctx_kern.data) [1] when *size exceeds *buf_size or
hdev->bpf.allocated_data?
__hid_input_report() calls dispatch_hid_bpf_device_event() before
hid_report_raw_event() checks the report length against bufsize:
drivers/hid/bpf/hid_bpf_dispatch.c:dispatch_hid_bpf_device_event() {
...
if (!hdev->bpf.device_data)
return data;
memset(ctx_kern.data, 0, hdev->bpf.allocated_data);
memcpy(ctx_kern.data, data, *size);
...
*buf_size = ctx_kern.ctx.allocated_size;
return ctx_kern.data;
}
When hdev->bpf.device_data is allocated, memcpy() copies *size bytes from
data into ctx_kern.data without checking that *size fits within either
*buf_size or hdev->bpf.allocated_data, and then overwrites *buf_size with
ctx_kern.ctx.allocated_size so the later bounds check in
hid_report_raw_event() cannot reject a report where *size exceeded the
caller's source buffer. If a caller of hid_safe_input_report() passes a
report length larger than its transport buffer capacity, memcpy() reads out
of bounds from data into the BPF context buffer and downstream hidraw
listeners, or overflows ctx_kern.data if *size also exceeds
hdev->bpf.allocated_data.
[1] https://sashiko.dev/#/bug/linux-5fe97c31-7531-4aca-913a-1d4f5712eb64
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130220315.659533-1-xmei5@asu.edu?part=1
next prev parent reply other threads:[~2026-11-30 22:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 22:03 [PATCH 0/2] HID: bpf: fix stale device_event buffer reuse Xiang Mei
2026-11-30 22:03 ` [PATCH 1/2] HID: core: release the HID-BPF event buffer on hid_connect()'s no-listeners exit Xiang Mei
2026-11-30 22:21 ` sashiko-bot [this message]
2026-11-30 22:03 ` [PATCH 2/2] HID: bpf: don't allocate the event buffer for an unbound device Xiang Mei
2026-11-30 22:21 ` sashiko-bot
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-242098@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=xmei5@asu.edu \
/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