From: sashiko-bot@kernel.org
To: "Sechang Lim" <rhkrqnwk98@gmail.com>
Cc: linux-input@vger.kernel.org, bpf@vger.kernel.org,
dmitry.torokhov@gmail.com
Subject: Re: [PATCH] HID: bpf: fix use-after-free in hid_bpf_reg()
Date: Wed, 25 Nov 2026 17:07:59 +0000 [thread overview]
Message-ID: <sashiko-outbox-233806@kernel.org> (raw)
In-Reply-To: <20261125164728.24914-1-rhkrqnwk98@gmail.com>
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] HID: bpf: use-after-free on struct hid_device in
hid_bpf_unreg() [1]
--
commit 8a1a1e9fd3f55ee6ffdf0b624cf6f20fd17120ed
Author: Sechang Lim <rhkrqnwk98@gmail.com>
HID: bpf: fix use-after-free in hid_bpf_reg()
This commit holds an extra device reference across hid_bpf_reg() so that
concurrent device destruction cannot free struct hid_device before
hid_bpf_reconnect() runs.
> diff --git a/drivers/hid/bpf/hid_bpf_struct_ops.c b/drivers/hid/bpf/hid_bpf_struct_ops.c
> index c90b68956cb3b..e2512bd6e6b29 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;
> }
[Severity: Critical]
This problem wasn't introduced by this patch, but can the paired
hid_bpf_unreg() hit a similar use-after-free on struct hid_device
[1]?
drivers/hid/bpf/hid_bpf_struct_ops.c:hid_bpf_unreg() {
...
hdev = ops->hdev;
/* check if __hid_bpf_ops_destroy_device() has been called */
if (!hdev)
return;
mutex_lock(&hdev->bpf.prog_list_lock);
...
}
hid_bpf_unreg() reads ops->hdev without a lock or reference before locking
hdev->bpf.prog_list_lock:
CPU0 CPU1
hid_bpf_unreg()
hdev = ops->hdev;
hid_destroy_device()
hid_bpf_destroy_device()
__hid_bpf_ops_destroy_device()
mutex_lock(&hdev->bpf.prog_list_lock)
e->hdev = NULL
mutex_unlock(&hdev->bpf.prog_list_lock)
hid_put_device(hdev)
put_device(&hdev->dev)
kfree(hdev)
mutex_lock(&hdev->bpf.prog_list_lock)
<-- use-after-free
In addition, if hid_bpf_unreg() takes prog_list_lock after
hid_bpf_destroy_device() sets hdev->bpf.destroyed to true but before
__hid_bpf_ops_destroy_device() clears e->hdev, hid_bpf_unreg() still sees
a non-NULL ops->hdev and calls hid_bpf_reconnect() on a device being
destroyed.
[1] https://sashiko.dev/#/bug/linux-6599bf1d-e091-4b20-bab0-cb93dd34be79
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125164728.24914-1-rhkrqnwk98@gmail.com?part=1
prev parent reply other threads:[~2026-11-25 17:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
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=sashiko-outbox-233806@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=rhkrqnwk98@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.