]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
HID: magicmouse: Prevent out-of-bounds (OOB) read during DOUBLE_REPORT_ID
authorLee Jones <lee@kernel.org>
Thu, 16 Apr 2026 13:16:54 +0000 (14:16 +0100)
committerJiri Kosina <jkosina@suse.com>
Tue, 12 May 2026 15:49:18 +0000 (17:49 +0200)
It is currently possible for a malicious or misconfigured USB device to
cause an out-of-bounds (OOB) read when submitting reports using
DOUBLE_REPORT_ID by specifying a large report length and providing a
smaller one.

Let's prevent that by comparing the specified report length with the
actual size of the data read in from userspace.  If the actual data
length ends up being smaller than specified, we'll politely warn the
user and prevent any further processing.

Signed-off-by: Lee Jones <lee@kernel.org>
Reviewed-by: Günther Noack <gnoack@google.com>
Signed-off-by: Jiri Kosina <jkosina@suse.com>
drivers/hid/hid-magicmouse.c

index e70bd3dc07ab72f19b49b62c75966e70c1fe29a0..802a3479e24b92669d6fd0b664b47c15274be466 100644 (file)
@@ -390,6 +390,10 @@ static int magicmouse_raw_event(struct hid_device *hdev,
        struct input_dev *input = msc->input;
        int x = 0, y = 0, ii, clicks = 0, npoints;
 
+       /* Protect against zero sized recursive calls from DOUBLE_REPORT_ID */
+       if (size < 1)
+               return 0;
+
        switch (data[0]) {
        case TRACKPAD_REPORT_ID:
        case TRACKPAD2_BT_REPORT_ID:
@@ -490,6 +494,18 @@ static int magicmouse_raw_event(struct hid_device *hdev,
                /* Sometimes the trackpad sends two touch reports in one
                 * packet.
                 */
+
+               /* Ensure that we have at least 2 elements (report type and size) */
+               if (size < 2)
+                       return 0;
+
+               if (size < data[1] + 2) {
+                       hid_warn(hdev,
+                                "received report length (%d) was smaller than specified (%d)",
+                                size, data[1] + 2);
+                       return 0;
+               }
+
                magicmouse_raw_event(hdev, report, data + 2, data[1]);
                magicmouse_raw_event(hdev, report, data + 2 + data[1],
                        size - 2 - data[1]);