BPF List
 help / color / mirror / Atom feed
* [PATCH] HID: bpf: fix use-after-free in hid_bpf_reg()
@ 2026-11-25 16:47 Sechang Lim
  2026-11-25 17:07 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Sechang Lim @ 2026-11-25 16:47 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires
  Cc: linux-input, bpf, Alexei Starovoitov, Shen Yongchao, stable

hid_bpf_reg() keeps the reference from hid_get_device() in ops->hdev
and adds ops to prog_list. After prog_list_lock is dropped, a concurrent
hid_destroy_device() can put that reference and free the device. With
hid_rdesc_fixup set, hid_bpf_reconnect() then runs on a freed device:

  BUG: KASAN: use-after-free in device_reprobe+0x111/0x1c0
  Call Trace:
   device_reprobe+0x111/0x1c0
   hid_bpf_reg+0x3ce/0x420
   bpf_struct_ops_link_create+0x39b/0x4e0
   __sys_bpf+0xaca/0xc30

Hold an extra device reference until hid_bpf_reg() returns.

Fixes: ebc0d8093e8c ("HID: bpf: implement HID-BPF through bpf_struct_ops")
Cc: stable@vger.kernel.org
Signed-off-by: Sechang Lim <rhkrqnwk98@gmail.com>
---
 drivers/hid/bpf/hid_bpf_struct_ops.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/hid/bpf/hid_bpf_struct_ops.c b/drivers/hid/bpf/hid_bpf_struct_ops.c
index c90b68956cb3..e2512bd6e6b2 100644
--- a/drivers/hid/bpf/hid_bpf_struct_ops.c
+++ b/drivers/hid/bpf/hid_bpf_struct_ops.c
@@ -198,6 +198,7 @@ static int hid_bpf_reg(void *kdata, struct bpf_link *link)
 		return PTR_ERR(hdev);
 
 	ops->hdev = hdev;
+	get_device(&hdev->dev);
 
 	mutex_lock(&hdev->bpf.prog_list_lock);
 
@@ -239,6 +240,7 @@ static int hid_bpf_reg(void *kdata, struct bpf_link *link)
 		hid_bpf_reconnect(hdev);
 	}
 
+	put_device(&hdev->dev);
 	return err;
 }
 
-- 
2.56.1


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

end of thread, other threads:[~2026-11-25 17:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 16:47 [PATCH] HID: bpf: fix use-after-free in hid_bpf_reg() Sechang Lim
2026-11-25 17:07 ` sashiko-bot

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