Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hid: asus: asus_report_fixup: fix potential read out of bounds

syzbot reported a potential read out of bounds in asus_report_fixup.

this patch adds checks so that a read out of bounds will not occur

Signed-off-by: Andrew Ballance <andrewjballance@gmail.com>
Reported-by: <syzbot+07762f019fd03d01f04c@syzkaller.appspotmail.com>
Closes: https://syzkaller.appspot.com/bug?extid=07762f019fd03d01f04c
Fixes: 59d2f5b7392e ("HID: asus: fix more n-key report descriptors if n-key quirked")
Link: https://lore.kernel.org/r/20240602085023.1720492-1-andrewjballance@gmail.com
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>

authored by

Andrew Ballance and committed by
Benjamin Tissoires
89e1ee11 9c8f05cf

+2 -2
+2 -2
drivers/hid/hid-asus.c
··· 1204 1204 } 1205 1205 1206 1206 /* match many more n-key devices */ 1207 - if (drvdata->quirks & QUIRK_ROG_NKEY_KEYBOARD) { 1208 - for (int i = 0; i < *rsize + 1; i++) { 1207 + if (drvdata->quirks & QUIRK_ROG_NKEY_KEYBOARD && *rsize > 15) { 1208 + for (int i = 0; i < *rsize - 15; i++) { 1209 1209 /* offset to the count from 0x5a report part always 14 */ 1210 1210 if (rdesc[i] == 0x85 && rdesc[i + 1] == 0x5a && 1211 1211 rdesc[i + 14] == 0x95 && rdesc[i + 15] == 0x05) {