Linux Input/HID development
 help / color / mirror / Atom feed
From: Sechang Lim <rhkrqnwk98@gmail.com>
To: Jiri Kosina <jikos@kernel.org>, Benjamin Tissoires <bentiss@kernel.org>
Cc: linux-input@vger.kernel.org, bpf@vger.kernel.org,
	Alexei Starovoitov <ast@kernel.org>,
	Shen Yongchao <grayhat@foxmail.com>,
	stable@vger.kernel.org
Subject: [PATCH] HID: bpf: fix use-after-free in hid_bpf_reg()
Date: Wed, 25 Nov 2026 16:47:18 +0000	[thread overview]
Message-ID: <20261125164728.24914-1-rhkrqnwk98@gmail.com> (raw)

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


             reply	other threads:[~2026-11-25 16:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 16:47 Sechang Lim [this message]
2026-11-25 17:07 ` [PATCH] HID: bpf: fix use-after-free in hid_bpf_reg() 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=20261125164728.24914-1-rhkrqnwk98@gmail.com \
    --to=rhkrqnwk98@gmail.com \
    --cc=ast@kernel.org \
    --cc=bentiss@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=grayhat@foxmail.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=stable@vger.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