hid: asus: asus_report_fixup: fix potential read out of bounds
authorAndrew Ballance <andrewjballance@gmail.com>
Sun, 2 Jun 2024 08:50:23 +0000 (03:50 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 27 Jun 2024 11:49:15 +0000 (13:49 +0200)
commit 89e1ee118d6f0ee6bd6e80d8fe08839875daa241 upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/hid/hid-asus.c

index d6d8a028623a7751662493a2c779394ea344f48a..88cbb2fe6ac8ccf91643ca7ea4eee8a7f12c6b16 100644 (file)
@@ -1235,8 +1235,8 @@ static __u8 *asus_report_fixup(struct hid_device *hdev, __u8 *rdesc,
        }
 
        /* match many more n-key devices */
-       if (drvdata->quirks & QUIRK_ROG_NKEY_KEYBOARD) {
-               for (int i = 0; i < *rsize + 1; i++) {
+       if (drvdata->quirks & QUIRK_ROG_NKEY_KEYBOARD && *rsize > 15) {
+               for (int i = 0; i < *rsize - 15; i++) {
                        /* offset to the count from 0x5a report part always 14 */
                        if (rdesc[i] == 0x85 && rdesc[i + 1] == 0x5a &&
                            rdesc[i + 14] == 0x95 && rdesc[i + 15] == 0x05) {