linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] HID: core: fix off-by-one memset in hid_report_raw_event()
@ 2020-01-17 12:08 Johan Korsnes
  2020-01-17 12:08 ` [PATCH v2 2/2] HID: core: increase HID report buffer size to 8KiB Johan Korsnes
  2020-02-12 13:19 ` [PATCH v2 1/2] HID: core: fix off-by-one memset in hid_report_raw_event() Jiri Kosina
  0 siblings, 2 replies; 4+ messages in thread
From: Johan Korsnes @ 2020-01-17 12:08 UTC (permalink / raw)
  To: linux-usb; +Cc: Johan Korsnes, Armando Visconti, Jiri Kosina, Alan Stern

In case a report is greater than HID_MAX_BUFFER_SIZE, it is truncated,
but the report-number byte is not correctly handled. This results in a
off-by-one in the following memset, causing a kernel Oops and ensuing
system crash.

Note: With commit 8ec321e96e05 ("HID: Fix slab-out-of-bounds read in
hid_field_extract") I no longer hit the kernel Oops as we instead fail
"controlled" at probe if there is a report too long in the HID
report-descriptor. hid_report_raw_event() is an exported symbol, so
presumabely we cannot always rely on this being the case.

Fixes: 966922f26c7f ("HID: fix a crash in hid_report_raw_event()
                     function.")
Signed-off-by: Johan Korsnes <jkorsnes@cisco.com>
Cc: Armando Visconti <armando.visconti@st.com>
Cc: Jiri Kosina <jkosina@suse.cz>
Cc: Alan Stern <stern@rowland.harvard.edu>

---
v1 -> v2:
 * Clean-up of patch description (commit message)
---
 drivers/hid/hid-core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 851fe54ea59e..359616e3efbb 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1741,7 +1741,9 @@ int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, u32 size,
 
 	rsize = ((report->size - 1) >> 3) + 1;
 
-	if (rsize > HID_MAX_BUFFER_SIZE)
+	if (report_enum->numbered && rsize >= HID_MAX_BUFFER_SIZE)
+		rsize = HID_MAX_BUFFER_SIZE - 1;
+	else if (rsize > HID_MAX_BUFFER_SIZE)
 		rsize = HID_MAX_BUFFER_SIZE;
 
 	if (csize < rsize) {
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-02-12 13:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-17 12:08 [PATCH v2 1/2] HID: core: fix off-by-one memset in hid_report_raw_event() Johan Korsnes
2020-01-17 12:08 ` [PATCH v2 2/2] HID: core: increase HID report buffer size to 8KiB Johan Korsnes
2020-02-12 13:19 ` [PATCH v2 1/2] HID: core: fix off-by-one memset in hid_report_raw_event() Jiri Kosina
2020-02-12 13:26   ` Johan Korsnes (jkorsnes)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).