HID: uhid: convert to hid_safe_input_report()
Subsystems (2)
PATCH 1/1 HID: uhid: convert to hid_safe_input_report()
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.
--- drivers/hid/uhid.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/hid/uhid.c +4 -4
@@ -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 ; }
Signature · 1 line
2.55.0.897.gb25b4bd76c-goog
Quoted 3 lines
Convert uhid to use
hid_safe_input_report()and passUHID_DATA_MAXas 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.
Signature · 2 lines
Thanks, Sasha
Quoted 4 lines · Sasha Levin
Quoted 3 lines
Convert uhid to use
hid_safe_input_report()and passUHID_DATA_MAXas the buffer size. This prevents the reported regressions [1], allowing hid core to zero-pad the shorter reports safely as expected.
Quoted 9 lines
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.
Signature · 2 lines
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?
---
drivers/hid/hid-core.c +20 -14
@@ -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 *dataup (&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,