Re: [PATCH 1/1] HID: uhid: Fix out-of-bounds write caused by raw events mismanagement

From: Benjamin Tissoires

Date: Sat Feb 21 2026 - 08:03:47 EST


On Feb 11 2026, Lee Jones wrote:
> Since the report ID is located within the data buffer, overwriting it
> would mean that any subsequent matching could cause a disparity in
> assumed allocated buffer size. This in turn could trivially result in
> an out-of-bounds condition. To mitigate this issue, let's refuse to
> overwrite a given report's data area if the ID in get_report_reply
> doesn't match.

That's a strong assumption and a breakage of the userspace FWIW. The CI
is now full of errors:
https://gitlab.freedesktop.org/bentiss/hid/-/commits/for-7.0/upstream-fixes

It is pretty common to allocate the buffer and not initialize it in
get_report operations.

It was a bad API choice to have rnum and data[0] for all HID requests
(internally, externally), but we should stick to it. The CI breakage in
itself is not a big issue TBH, but if it breaks here, it will probably
break existing users.

Cheers,
Benjamin

>
> Cc: stable@xxxxxxxxxxxxxxx
> Fixes: fcfcf0deb89ec ("HID: uhid: implement feature requests")
> Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
> ---
> drivers/hid/uhid.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
> index 21a70420151e..a0ee4e86656f 100644
> --- a/drivers/hid/uhid.c
> +++ b/drivers/hid/uhid.c
> @@ -262,6 +262,10 @@ static int uhid_hid_get_report(struct hid_device *hid, unsigned char rnum,
> req = &uhid->report_buf.u.get_report_reply;
> if (req->err) {
> ret = -EIO;
> + } else if (rnum != req->data[0]) {
> + hid_err(hid, "Report ID mismatch - refusing to overwrite the data buffer\n");
> + ret = -EINVAL;
> + goto unlock;
> } else {
> ret = min3(count, (size_t)req->size, (size_t)UHID_DATA_MAX);
> memcpy(buf, req->data, ret);
> --
> 2.53.0.273.g2a3d683680-goog
>