Linux Input/HID development
 help / color / mirror / Atom feed
* [PATCH 0/4] HID: bpf: two fixes for the device event buffer
@ 2026-12-02 21:22 Yassine Ouamer via B4 Relay
  2026-12-02 21:22 ` [PATCH 1/4] HID: bpf: don't allocate an empty " Yassine Ouamer via B4 Relay
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Yassine Ouamer via B4 Relay @ 2026-12-02 21:22 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires, Greg Kroah-Hartman, Shuah Khan
  Cc: linux-input, bpf, linux-kselftest, Yassine Ouamer, stable

Two bugs in how dispatch_hid_bpf_device_event() uses device_data, both
from 658ee5a64fcf ("HID: bpf: allocate data memory for device_event BPF
programs"), each fixed with a selftest that fails without it:

- a device whose own report descriptor is refused gets a 0-byte buffer
  (ZERO_SIZE_PTR) when a struct_ops with both a report descriptor fixup
  and a hid_device_event hook is attached, kept after the fixup's
  reprobe, so its first input report oopses (patches 1-2). Found with
  the Apple Siri Remote (4th generation) over Bluetooth LE.

- a report longer than the device's report descriptor declares is
  copied whole into a buffer sized from the descriptor: a slab
  out-of-bounds write with the device's data (patches 3-4).

Tested in a virtme-ng VM (QEMU, x86_64) on hid/for-next 47d0d5ce3cfc,
with the HID selftests' config and KASAN: tools/testing/selftests/hid/
hid_bpf passes 50/50 (2 skips, as before) with /sys/fs/bpf mounted;
without the fixes, the new tests oops and trigger the KASAN report
quoted in patch 3. Not tested: the hid-tools test suite, and the
patched kernel with the real device (its HID-BPF program avoids the
first bug by attaching the report descriptor fixup before its other
hooks).

The analysis, the patches and their commit messages were written with
an AI coding assistant (Claude, by Anthropic).

Signed-off-by: Yassine Ouamer <yassine.ouamer@proton.me>
---
Yassine Ouamer (4):
      HID: bpf: don't allocate an empty device event buffer
      selftests/hid: test a device event on a refused report descriptor
      HID: bpf: don't copy a report longer than the device event buffer
      selftests/hid: test a report longer than its descriptor declares

 drivers/hid/bpf/hid_bpf_dispatch.c      |  18 +++++-
 tools/testing/selftests/hid/hid_bpf.c   | 107 ++++++++++++++++++++++++++++++++
 tools/testing/selftests/hid/progs/hid.c |  53 ++++++++++++++++
 3 files changed, 177 insertions(+), 1 deletion(-)
---
base-commit: 47d0d5ce3cfca63a04eabcbeef7086d06240ff97
change-id: 20261202-hid-bpf-event-buffer-40948476084c

Best regards,
--  
Yassine Ouamer <yassine.ouamer@proton.me>



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-12-02 21:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 21:22 [PATCH 0/4] HID: bpf: two fixes for the device event buffer Yassine Ouamer via B4 Relay
2026-12-02 21:22 ` [PATCH 1/4] HID: bpf: don't allocate an empty " Yassine Ouamer via B4 Relay
2026-12-02 21:22 ` [PATCH 2/4] selftests/hid: test a device event on a refused report descriptor Yassine Ouamer via B4 Relay
2026-12-02 21:22 ` [PATCH 3/4] HID: bpf: don't copy a report longer than the device event buffer Yassine Ouamer via B4 Relay
2026-12-02 21:40   ` sashiko-bot
2026-12-02 21:22 ` [PATCH 4/4] selftests/hid: test a report longer than its descriptor declares Yassine Ouamer via B4 Relay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox