From: Xiang Mei <xmei5@asu.edu>
To: Jiri Kosina <jikos@kernel.org>, Benjamin Tissoires <bentiss@kernel.org>
Cc: linux-input@vger.kernel.org, bpf@vger.kernel.org,
linux-kernel@vger.kernel.org, Sashiko <sashiko-bot@kernel.org>,
co+86678873d3803945@bugs.sh, co+9a1ebd50dd939705@bugs.sh,
Xiang Mei <xmei5@asu.edu>
Subject: [PATCH 0/2] HID: bpf: fix stale device_event buffer reuse
Date: Mon, 30 Nov 2026 15:03:13 -0700 [thread overview]
Message-ID: <20261130220315.659533-1-xmei5@asu.edu> (raw)
hdev->bpf.device_data is allocated once, sized from the report descriptor
parsed at that moment, and then reused: hid_bpf_allocate_event_data()
returns early whenever the pointer is already set. If the buffer
outlives the descriptor it was sized for, the next probe binds with a
larger descriptor and dispatch_hid_bpf_device_event() copies a full
report into the stale buffer.
Two paths leave such a buffer behind:
1/2 hid_connect()'s "no listeners" exit returns without freeing the
buffer it just allocated (KASAN slab-out-of-bounds write of 1024
bytes into kmalloc-64). The leak was also pointed out by the
sashiko review in [1].
2/2 hid_bpf_reg() allocates for an unbound device, whose report enums
are empty, so the buffer is ZERO_SIZE_PTR with allocated_data 0
(NULL-pointer write at 0x10).
Both are reachable from userspace with a uhid device and HID-BPF
struct_ops programs using ->hid_rdesc_fixup and ->hid_device_event.
Each patch was tested against its own reproducer on a KASAN kernel: the
crash fires without the patch and does not with it.
These fix the buffer lifetime and are independent of the pending
change that bounds the memcpy() itself [2]; that one is still needed
for uhid reports larger than the descriptor allows.
[1] https://lore.kernel.org/all/20260908202056.698371F00A3A@smtp.kernel.org/
[2] https://lore.kernel.org/all/20261102112630.53400-1-alon@botanica.software/
Xiang Mei (2):
HID: core: release the HID-BPF event buffer on hid_connect()'s
no-listeners exit
HID: bpf: don't allocate the event buffer for an unbound device
drivers/hid/bpf/hid_bpf_struct_ops.c | 2 +-
drivers/hid/hid-core.c | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
--
2.43.0
next reply other threads:[~2026-11-30 22:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 22:03 Xiang Mei [this message]
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
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=20261130220315.659533-1-xmei5@asu.edu \
--to=xmei5@asu.edu \
--cc=bentiss@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=co+86678873d3803945@bugs.sh \
--cc=co+9a1ebd50dd939705@bugs.sh \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sashiko-bot@kernel.org \
/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