linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johan Korsnes <jkorsnes@cisco.com>
To: linux-usb@vger.kernel.org
Cc: Johan Korsnes <jkorsnes@cisco.com>,
	Armando Visconti <armando.visconti@st.com>,
	Jiri Kosina <jkosina@suse.cz>,
	Alan Stern <stern@rowland.harvard.edu>
Subject: [PATCH 1/2] HID: core: fix off-by-one memset in hid_report_raw_event()
Date: Wed, 15 Jan 2020 13:33:43 +0100	[thread overview]
Message-ID: <20200115123344.4650-1-jkorsnes@cisco.com> (raw)

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. I still believe this is worth fixing though, as
hid_report_raw_event() should have its logic correct. But if we fail at
probe for too large reports, a better solution might be to remove this
truncation logic entirely.

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>
---
 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


             reply	other threads:[~2020-01-15 12:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-15 12:33 Johan Korsnes [this message]
2020-01-15 12:33 ` [PATCH 2/2] HID: core: increase HID report buffer size to 8KiB Johan Korsnes
2020-01-15 15:21   ` Alan Stern
2020-01-15 15:50     ` Johan Korsnes (jkorsnes)
2020-01-17 10:15       ` Jiri Kosina

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200115123344.4650-1-jkorsnes@cisco.com \
    --to=jkorsnes@cisco.com \
    --cc=armando.visconti@st.com \
    --cc=jkosina@suse.cz \
    --cc=linux-usb@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).