Skip to content

Commit 9c031b2

Browse files
tweejgregkh
authored andcommitted
HID: playstation: Clamp num_touch_reports
commit cac61b5 upstream. A device would never lie about the number of touch reports would it? If it does the loop in dualshock4_parse_report will read off the end of the touch_reports array, up to about 2 KiB for the maximum number of 256 loop iteraions. The data that is read is emitted via evdev if the DS4_TOUCH_POINT_INACTIVE bit happens to be set. Protect against this by clamping the num_touch_reports value provided by the device to the maximum size of the touch_reports array. Fixes: 7520382 ("HID: playstation: add DualShock4 touchpad support.") Cc: stable@vger.kernel.org Reported-by: Xingyu Jin <xingyuj@google.com> Signed-off-by: T.J. Mercier <tjmercier@google.com> Signed-off-by: Jiri Kosina <jkosina@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 51eba7e commit 9c031b2

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

drivers/hid/hid-playstation.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,7 +2248,8 @@ static int dualshock4_parse_report(struct ps_device *ps_dev, struct hid_report *
22482248
struct dualshock4_input_report_usb *usb = (struct dualshock4_input_report_usb *)data;
22492249

22502250
ds4_report = &usb->common;
2251-
num_touch_reports = usb->num_touch_reports;
2251+
num_touch_reports = min_t(u8, usb->num_touch_reports,
2252+
ARRAY_SIZE(usb->touch_reports));
22522253
touch_reports = usb->touch_reports;
22532254
} else if (hdev->bus == BUS_BLUETOOTH && report->id == DS4_INPUT_REPORT_BT &&
22542255
size == DS4_INPUT_REPORT_BT_SIZE) {
@@ -2262,7 +2263,8 @@ static int dualshock4_parse_report(struct ps_device *ps_dev, struct hid_report *
22622263
}
22632264

22642265
ds4_report = &bt->common;
2265-
num_touch_reports = bt->num_touch_reports;
2266+
num_touch_reports = min_t(u8, bt->num_touch_reports,
2267+
ARRAY_SIZE(bt->touch_reports));
22662268
touch_reports = bt->touch_reports;
22672269
} else if (hdev->bus == BUS_BLUETOOTH &&
22682270
report->id == DS4_INPUT_REPORT_BT_MINIMAL &&

0 commit comments

Comments
 (0)