Re: [PATCH 1/2] HID: core: Mitigate potential OOB by removing bogus memset()

From: Benjamin Tissoires

Date: Mon Mar 02 2026 - 09:42:10 EST


On Feb 27 2026, Lee Jones wrote:
> The memset() in hid_report_raw_event() has the good intention of
> clearing out bogus data by zeroing the area from the end of the incoming
> data string to the assumed end of the buffer. However, as we have
> recently seen, the size of the report buffer isn't always correct which
> can culminate in OOB writes.
>
> The current suggestion from one of the HID maintainers is to remove the
> attempt completely. The subsequent handling should be able to simply
> use the data size provided to prevent any potential overruns.
>
> Suggested-by Benjamin Tissoires <bentiss@xxxxxxxxxx>
> Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
> ---
> drivers/hid/hid-core.c | 6 ------
> 1 file changed, 6 deletions(-)
>
> diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
> index a5b3a8ca2fcb..1d51042e4b1f 100644
> --- a/drivers/hid/hid-core.c
> +++ b/drivers/hid/hid-core.c
> @@ -2056,12 +2056,6 @@ int hid_report_raw_event(struct hid_device *hid, enum hid_report_type type, u8 *
> else if (rsize > max_buffer_size)
> rsize = max_buffer_size;
>
> - if (csize < rsize) {
> - dbg_hid("report %d is too short, (%d < %d)\n", report->id,
> - csize, rsize);
> - memset(cdata + csize, 0, rsize - csize);
> - }
> -

Simply removing this check is not enough.

later we have a call to `hid_process_report(hid, report, cdata,
interrupt);`` which loses the size information and which will make an
OOB read while calling hid_input_fetch_field().

I think we should drop here the processing with a warning (maybe rate
limnited), and hope for the best.

Cheers,
Benjamin

> if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event)
> hid->hiddev_report_event(hid, report);
> if (hid->claimed & HID_CLAIMED_HIDRAW) {
> --
> 2.53.0.473.g4a7958ca14-goog
>