Skip to content

Commit 2c99438

Browse files
dtorgregkh
authored andcommitted
Input: gtco - fix potential out-of-bound access
commit a50829479f58416a013a4ccca791336af3c584c7 upstream. parse_hid_report_descriptor() has a while (i < length) loop, which only guarantees that there's at least 1 byte in the buffer, but the loop body can read multiple bytes which causes out-of-bounds access. Reported-by: Andrey Konovalov <andreyknvl@google.com> Reviewed-by: Andrey Konovalov <andreyknvl@google.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 31d770a commit 2c99438

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

drivers/input/tablet/gtco.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,22 +231,25 @@ static void parse_hid_report_descriptor(struct gtco *device, char * report,
231231

232232
/* Walk this report and pull out the info we need */
233233
while (i < length) {
234-
prefix = report[i];
235-
236-
/* Skip over prefix */
237-
i++;
234+
prefix = report[i++];
238235

239236
/* Determine data size and save the data in the proper variable */
240-
size = PREF_SIZE(prefix);
237+
size = (1U << PREF_SIZE(prefix)) >> 1;
238+
if (i + size > length) {
239+
dev_err(ddev,
240+
"Not enough data (need %d, have %d)\n",
241+
i + size, length);
242+
break;
243+
}
244+
241245
switch (size) {
242246
case 1:
243247
data = report[i];
244248
break;
245249
case 2:
246250
data16 = get_unaligned_le16(&report[i]);
247251
break;
248-
case 3:
249-
size = 4;
252+
case 4:
250253
data32 = get_unaligned_le32(&report[i]);
251254
break;
252255
}

0 commit comments

Comments
 (0)