From: sashiko-bot@kernel.org
To: "Bill Wendling" <morbo@google.com>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org,
bpf@vger.kernel.org
Subject: Re: [PATCH] HID: bpf: add __counted_by_ptr attribute to device_data
Date: Wed, 23 Sep 2026 06:46:22 +0000 [thread overview]
Message-ID: <20260923064622.90D881F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260923063114.2683575-1-morbo@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] hid-bpf: false-positive bounds check panic via data race in __hid_bpf_allocate_data()
--
commit 4a962db9c72042e7d956ca752f9439fb64fe5e37
Author: Bill Wendling <morbo@google.com>
HID: bpf: add __counted_by_ptr attribute to device_data
The 'struct hid_bpf' contains a 'device_data' pointer field and an
'allocated_data' field that specifies the size in bytes. This commit
adds the '__counted_by_ptr' attribute to 'device_data' to enable bounds
checking sanitizers.
> diff --git a/include/linux/hid_bpf.h b/include/linux/hid_bpf.h
> index 19fffa4574a47..f45fb9cccece8 100644
> --- a/include/linux/hid_bpf.h
> +++ b/include/linux/hid_bpf.h
> @@ -185,10 +185,12 @@ struct hid_bpf_ops {
>
> /* stored in each device */
> struct hid_bpf {
> - u8 *device_data; /* allocated when a bpf program of type
> - * SEC(f.../hid_bpf_device_event) has been attached
> - * to this HID device
> - */
> + /*
> + * allocated when a bpf program of type
> + * SEC(f.../hid_bpf_device_event) has been attached
> + * to this HID device
> + */
> + u8 *device_data __counted_by_ptr(allocated_data);
[Severity: High]
Does this newly added attribute introduce a false-positive bounds check panic?
The commit message mentions that allocated_data is always set before any
access, but looking at __hid_bpf_allocate_data() in
drivers/hid/bpf/hid_bpf_dispatch.c, it appears the pointer is assigned before
the count without memory barriers:
*data = alloc_data;
*size = alloc_size;
Concurrently, if an incoming HID report triggers
dispatch_hid_bpf_device_event() (which holds driver_input_lock but not
prog_list_lock), could it observe a non-NULL device_data pointer while the
allocated_data count still evaluates to 0?
If so, would the new __counted_by_ptr() attribute cause sanitizers to evaluate
the buffer size as 0 while device_data is active, triggering a false-positive
kernel panic when memcpy(ctx_kern.data, data, *size) is called?
> u32 allocated_data;
> bool destroyed; /* prevents the assignment of any progs */
>
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260923063114.2683575-1-morbo@google.com?part=1
next prev parent reply other threads:[~2026-09-23 6:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-23 6:31 [PATCH] HID: bpf: add __counted_by_ptr attribute to device_data Bill Wendling
2026-09-23 6:46 ` sashiko-bot [this message]
2026-09-23 6:56 ` Bill Wendling
2026-09-23 6:56 ` [PATCH v2] " Bill Wendling
2026-09-23 7:12 ` 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=20260923064622.90D881F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=morbo@google.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.