Skip to content

Commit 43565b6

Browse files
endriftJiri Kosina
authored andcommitted
HID: hid-steam: Better handling of serial number length
The second byte of the GET_STRING_ATTRIB report is a length, so we should set the size of the buffer to be the size we're actually requesting, and only reject the reply if the length out is nonsensical. Signed-off-by: Vicki Pfau <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 4f9a5a9 commit 43565b6

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

drivers/hid/hid-steam.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ enum {
274274
};
275275

276276
/* Other random constants */
277-
#define STEAM_SERIAL_LEN 10
277+
#define STEAM_SERIAL_LEN 0x15
278278

279279
struct steam_device {
280280
struct list_head list;
@@ -421,10 +421,10 @@ static int steam_get_serial(struct steam_device *steam)
421421
{
422422
/*
423423
* Send: 0xae 0x15 0x01
424-
* Recv: 0xae 0x15 0x01 serialnumber (10 chars)
424+
* Recv: 0xae 0x15 0x01 serialnumber
425425
*/
426426
int ret = 0;
427-
u8 cmd[] = {ID_GET_STRING_ATTRIBUTE, 0x15, ATTRIB_STR_UNIT_SERIAL};
427+
u8 cmd[] = {ID_GET_STRING_ATTRIBUTE, sizeof(steam->serial_no), ATTRIB_STR_UNIT_SERIAL};
428428
u8 reply[3 + STEAM_SERIAL_LEN + 1];
429429

430430
mutex_lock(&steam->report_mutex);
@@ -434,12 +434,13 @@ static int steam_get_serial(struct steam_device *steam)
434434
ret = steam_recv_report(steam, reply, sizeof(reply));
435435
if (ret < 0)
436436
goto out;
437-
if (reply[0] != ID_GET_STRING_ATTRIBUTE || reply[1] != 0x15 || reply[2] != ATTRIB_STR_UNIT_SERIAL) {
437+
if (reply[0] != ID_GET_STRING_ATTRIBUTE || reply[1] < 1 ||
438+
reply[1] > sizeof(steam->serial_no) || reply[2] != ATTRIB_STR_UNIT_SERIAL) {
438439
ret = -EIO;
439440
goto out;
440441
}
441442
reply[3 + STEAM_SERIAL_LEN] = 0;
442-
strscpy(steam->serial_no, reply + 3, sizeof(steam->serial_no));
443+
strscpy(steam->serial_no, reply + 3, reply[1]);
443444
out:
444445
mutex_unlock(&steam->report_mutex);
445446
return ret;

0 commit comments

Comments
 (0)