4e4400c
From a0edc539fda3f0a4a271f47a0fcf79d1305c1444 Mon Sep 17 00:00:00 2001
4e4400c
From: Vladis Dronov <vdronov@redhat.com>
4e4400c
Date: Wed, 25 Nov 2015 16:31:35 +0100
4e4400c
Subject: [PATCH] Input: aiptek: fix crash on detecting device without
4e4400c
 endpoints
4e4400c
4e4400c
The aiptek driver crashes in aiptek_probe() when a specially crafted usb device
4e4400c
without endpoints is detected. This fix adds a check that the device has proper
4e4400c
configuration expected by the driver. Also an error return value is changed to
4e4400c
more matching one in one of the error paths.
4e4400c
4e4400c
Reported-by: Ralf Spenneberg <ralf@spenneberg.net>
4e4400c
Signed-off-by: Vladis Dronov <vdronov@redhat.com>
4e4400c
---
4e4400c
 drivers/input/tablet/aiptek.c | 10 ++++++++++
4e4400c
 1 file changed, 10 insertions(+)
4e4400c
4e4400c
diff --git a/drivers/input/tablet/aiptek.c b/drivers/input/tablet/aiptek.c
4e4400c
index e7f966da6efa..78c0732fbb57 100644
4e4400c
--- a/drivers/input/tablet/aiptek.c
4e4400c
+++ b/drivers/input/tablet/aiptek.c
4e4400c
@@ -1819,6 +1819,15 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
4e4400c
 	input_set_abs_params(inputdev, ABS_TILT_Y, AIPTEK_TILT_MIN, AIPTEK_TILT_MAX, 0, 0);
4e4400c
 	input_set_abs_params(inputdev, ABS_WHEEL, AIPTEK_WHEEL_MIN, AIPTEK_WHEEL_MAX - 1, 0, 0);
4e4400c
 
4e4400c
+	/* Verify that a device really has an endpoint
4e4400c
+	 */
4e4400c
+	if (intf->altsetting[0].desc.bNumEndpoints < 1) {
4e4400c
+		dev_warn(&intf->dev,
4e4400c
+			"interface has %d endpoints, but must have minimum 1\n",
4e4400c
+			intf->altsetting[0].desc.bNumEndpoints);
4e4400c
+		err = -ENODEV;
4e4400c
+		goto fail3;
4e4400c
+	}
4e4400c
 	endpoint = &intf->altsetting[0].endpoint[0].desc;
4e4400c
 
4e4400c
 	/* Go set up our URB, which is called when the tablet receives
4e4400c
@@ -1861,6 +1870,7 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
4e4400c
 	if (i == ARRAY_SIZE(speeds)) {
4e4400c
 		dev_info(&intf->dev,
4e4400c
 			 "Aiptek tried all speeds, no sane response\n");
4e4400c
+		err = -ENODEV;
4e4400c
 		goto fail3;
4e4400c
 	}
4e4400c
 
4e4400c
-- 
4e4400c
2.5.0
4e4400c