Re: [PATCH v2] HID: bpf: add __counted_by_ptr attribute to device_data

From: bentiss

Date: Fri Oct 16 2026 - 12:49:27 EST


> The 'struct hid_bpf' contains a 'device_data' pointer field (of type
> 'u8 *') and an 'allocated_data' field (of type 'u32') that specifies the
> size in bytes of the allocated memory for 'device_data'. Since
> 'device_data' is a pointer to 'u8' (elements of size 1 byte),
> 'allocated_data' represents the exact count of elements allocated for
> 'device_data'.
>
> Annotate the 'device_data' field of 'struct hid_bpf' with the
> '__counted_by_ptr' attribute, pointing to 'allocated_data'. This enables
> bounds-checking sanitizers (like KASAN and UBSAN) to detect
> out-of-bounds accesses to 'device_data'.
>
> Because the count 'allocated_data' is always set before any access and
> accurately tracks the allocated buffer size at all times, adding
> '__counted_by_ptr' will not cause runtime panics or false-positive
> bounds checks.

I've applied your other patch touching the same area (please always
regroup patches touching the same area into a single series). Is this
patch still required? If so, can you respin it on top of for-7.4/bpf?

Cheers,
Benjamin

--
Benjamin Tissoires <bentiss@xxxxxxxxxx>