* [PATCH 6.12.y] HID: uhid: convert to hid_safe_input_report()
@ 2026-08-27 22:04 Carlos Llamas
2026-08-29 3:34 ` Sasha Levin
0 siblings, 1 reply; 3+ messages in thread
From: Carlos Llamas @ 2026-08-27 22:04 UTC (permalink / raw)
To: stable
Cc: kernel-team, Carlos Llamas, Lee Jones, Jiri Kosina,
Benjamin Tissoires, open list:UHID USERSPACE HID IO DRIVER,
open list
commit 63a694c51bf120a37550890b8e7736b4888985e9 upstream.
Commit 0a3fe972a7cb ("HID: core: Mitigate potential OOB by removing
bogus memset()"), added a check in hid_report_raw_event() to reject
reports if the received data size is smaller than expected. This was
intended to prevent OOB errors by no longer allowing zeroing-out of
shorter reports due to the lack of buffer size information.
However, this leads to regressions in hid_report_raw_event(), where
shorter than expected reports are rejected, even though their buffers
are sufficiently large to be zero-padded.
To solve this issue, Benjamin introduced a safer alternative in commit
206342541fc8 ("HID: core: introduce hid_safe_input_report()"), which
forwards the buffer size and allows hid_report_raw_event() to safely
zero-pad the data.
Convert uhid to use hid_safe_input_report() and pass UHID_DATA_MAX as
the buffer size. This prevents the reported regressions [1], allowing
hid core to zero-pad the shorter reports safely as expected.
Cc: stable@vger.kernel.org
Fixes: 0a3fe972a7cb ("HID: core: Mitigate potential OOB by removing bogus memset()")
Closes: https://lore.kernel.org/all/ahsh0UtTX6e0ZeHa@google.com/ [1]
Signed-off-by: Carlos Llamas <cmllamas@google.com>
Reviewed-by: Lee Jones <lee@kernel.org>
Closes: https://lore.kernel.org/all/ahsh0UtTX6e0ZeHa@google.com/
Signed-off-by: Jiri Kosina <jkosina@suse.com>
Signed-off-by: Carlos Llamas <cmllamas@google.com>
---
drivers/hid/uhid.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
index 21a70420151e..d16667207b9f 100644
--- a/drivers/hid/uhid.c
+++ b/drivers/hid/uhid.c
@@ -595,8 +595,8 @@ static int uhid_dev_input(struct uhid_device *uhid, struct uhid_event *ev)
if (!READ_ONCE(uhid->running))
return -EINVAL;
- hid_input_report(uhid->hid, HID_INPUT_REPORT, ev->u.input.data,
- min_t(size_t, ev->u.input.size, UHID_DATA_MAX), 0);
+ hid_safe_input_report(uhid->hid, HID_INPUT_REPORT, ev->u.input.data, UHID_DATA_MAX,
+ min_t(size_t, ev->u.input.size, UHID_DATA_MAX), 0);
return 0;
}
@@ -606,8 +606,8 @@ static int uhid_dev_input2(struct uhid_device *uhid, struct uhid_event *ev)
if (!READ_ONCE(uhid->running))
return -EINVAL;
- hid_input_report(uhid->hid, HID_INPUT_REPORT, ev->u.input2.data,
- min_t(size_t, ev->u.input2.size, UHID_DATA_MAX), 0);
+ hid_safe_input_report(uhid->hid, HID_INPUT_REPORT, ev->u.input2.data, UHID_DATA_MAX,
+ min_t(size_t, ev->u.input2.size, UHID_DATA_MAX), 0);
return 0;
}
--
2.55.0.897.gb25b4bd76c-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 6.12.y] HID: uhid: convert to hid_safe_input_report()
2026-08-27 22:04 [PATCH 6.12.y] HID: uhid: convert to hid_safe_input_report() Carlos Llamas
@ 2026-08-29 3:34 ` Sasha Levin
2026-08-29 16:48 ` Carlos Llamas
0 siblings, 1 reply; 3+ messages in thread
From: Sasha Levin @ 2026-08-29 3:34 UTC (permalink / raw)
To: stable
Cc: Sasha Levin, kernel-team, Carlos Llamas, Lee Jones, Jiri Kosina,
Benjamin Tissoires, open list:UHID USERSPACE HID IO DRIVER,
open list
> Convert uhid to use hid_safe_input_report() and pass UHID_DATA_MAX as
> the buffer size. This prevents the reported regressions [1], allowing
> hid core to zero-pad the shorter reports safely as expected.
Queued for 6.12, thanks.
Could one of you send adapted backports of the pair for 6.6, 6.1, 5.15 and
5.10? I would rather have them from people who know the HID core than
do it myself.
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 6.12.y] HID: uhid: convert to hid_safe_input_report()
2026-08-29 3:34 ` Sasha Levin
@ 2026-08-29 16:48 ` Carlos Llamas
0 siblings, 0 replies; 3+ messages in thread
From: Carlos Llamas @ 2026-08-29 16:48 UTC (permalink / raw)
To: Sasha Levin
Cc: stable, kernel-team, Lee Jones, Jiri Kosina, Benjamin Tissoires,
open list:UHID USERSPACE HID IO DRIVER, open list
On Fri, Aug 28, 2026 at 11:34:35PM -0400, Sasha Levin wrote:
> > Convert uhid to use hid_safe_input_report() and pass UHID_DATA_MAX as
> > the buffer size. This prevents the reported regressions [1], allowing
> > hid core to zero-pad the shorter reports safely as expected.
>
> Queued for 6.12, thanks.
>
> Could one of you send adapted backports of the pair for 6.6, 6.1, 5.15 and
> 5.10? I would rather have them from people who know the HID core than
> do it myself.
>
> --
> Thanks,
> Sasha
Lucky for us Lee has already backported all the bufsize plumbing into
older stable branches. The only missing piece to backport the remaining
fixes would be adding the __hid_input_report() bits. We could extract
the following sections from mainline making these backports trivial.
Benjamin, Lee, wdyt?
---
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index b924980b5783..154f0ff8021f 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -2072,24 +2072,13 @@ int hid_report_raw_event(struct hid_device *hid, enum hid_report_type type, u8 *
}
EXPORT_SYMBOL_GPL(hid_report_raw_event);
-/**
- * hid_input_report - report data from lower layer (usb, bt...)
- *
- * @hid: hid device
- * @type: HID report type (HID_*_REPORT)
- * @data: report contents
- * @size: size of data parameter
- * @interrupt: distinguish between interrupt and control transfers
- *
- * This is data entry for lower layers.
- */
-int hid_input_report(struct hid_device *hid, enum hid_report_type type, u8 *data,
- u32 size, int interrupt)
+
+static int __hid_input_report(struct hid_device *hid, enum hid_report_type type,
+ u8 *data, size_t bufsize, u32 size, int interrupt)
{
struct hid_report_enum *report_enum;
struct hid_driver *hdrv;
struct hid_report *report;
- size_t bufsize = size;
int ret = 0;
if (!hid)
@@ -2140,6 +2129,23 @@ int hid_input_report(struct hid_device *hid, enum hid_report_type type, u8 *data
up(&hid->driver_input_lock);
return ret;
}
+
+/**
+ * hid_input_report - report data from lower layer (usb, bt...)
+ *
+ * @hid: hid device
+ * @type: HID report type (HID_*_REPORT)
+ * @data: report contents
+ * @size: size of data parameter
+ * @interrupt: distinguish between interrupt and control transfers
+ *
+ * This is data entry for lower layers.
+ */
+int hid_input_report(struct hid_device *hid, enum hid_report_type type, u8 *data, u32 size,
+ int interrupt)
+{
+ return __hid_input_report(hid, type, data, size, size, interrupt);
+}
EXPORT_SYMBOL_GPL(hid_input_report);
bool hid_match_one_id(const struct hid_device *hdev,
--
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-08-29 16:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-27 22:04 [PATCH 6.12.y] HID: uhid: convert to hid_safe_input_report() Carlos Llamas
2026-08-29 3:34 ` Sasha Levin
2026-08-29 16:48 ` Carlos Llamas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®