Skip to content

Commit 0bc4cf1

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 df870e1 commit 0bc4cf1

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
@@ -2200,7 +2200,8 @@ static int dualshock4_parse_report(struct ps_device *ps_dev, struct hid_report *
22002200
struct dualshock4_input_report_usb *usb = (struct dualshock4_input_report_usb *)data;
22012201

22022202
ds4_report = &usb->common;
2203-
num_touch_reports = usb->num_touch_reports;
2203+
num_touch_reports = min_t(u8, usb->num_touch_reports,
2204+
ARRAY_SIZE(usb->touch_reports));
22042205
touch_reports = usb->touch_reports;
22052206
} else if (hdev->bus == BUS_BLUETOOTH && report->id == DS4_INPUT_REPORT_BT &&
22062207
size == DS4_INPUT_REPORT_BT_SIZE) {
@@ -2214,7 +2215,8 @@ static int dualshock4_parse_report(struct ps_device *ps_dev, struct hid_report *
22142215
}
22152216

22162217
ds4_report = &bt->common;
2217-
num_touch_reports = bt->num_touch_reports;
2218+
num_touch_reports = min_t(u8, bt->num_touch_reports,
2219+
ARRAY_SIZE(bt->touch_reports));
22182220
touch_reports = bt->touch_reports;
22192221
} else {
22202222
hid_err(hdev, "Unhandled reportID=%d\n", report->id);

0 commit comments

Comments
 (0)