mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] HID: bpf: fix stale device_event buffer reuse
@ 2026-11-30 22:03 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:03 ` [PATCH 2/2] HID: bpf: don't allocate the event buffer for an unbound device Xiang Mei
  0 siblings, 2 replies; 3+ messages in thread
From: Xiang Mei @ 2026-11-30 22:03 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires
  Cc: linux-input, bpf, linux-kernel, Sashiko, co+86678873d3803945,
	co+9a1ebd50dd939705, Xiang Mei

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


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

end of thread, other threads:[~2026-11-30 22:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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:03 ` [PATCH 2/2] HID: bpf: don't allocate the event buffer for an unbound device Xiang Mei

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

all inboxes | Powered by JetHome®