Skip to contentSkip to conversation

Input: fix NULL-derefs at probe

PATCH In review Johan Hovold 3 participants 14 messages Mar 13, 2017 – Mar 18, 2017

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover Input: fix NULL-derefs at probe

This series fixes a number of NULL-pointer dereferences due to missing endpoint sanity checks that can be triggered by a malicious USB device.

Johan

Johan Hovold (7):
Input: iforce - fix NULL-deref at probe
Input: cm109 - fix NULL-deref at probe
Input: ims-pcu - fix NULL-deref at probe
Input: yealink - fix NULL-deref at probe
Input: hanwang - fix NULL-deref at probe
Input: kbtab - fix NULL-deref at probe
Input: sur40 - fix NULL-deref at probe

 drivers/input/joystick/iforce/iforce-usb.c | 3 +++
 drivers/input/misc/cm109.c                 | 4 ++++
 drivers/input/misc/ims-pcu.c               | 4 ++++
 drivers/input/misc/yealink.c               | 4 ++++
 drivers/input/tablet/hanwang.c             | 3 +++
 drivers/input/tablet/kbtab.c               | 3 +++
 drivers/input/touchscreen/sur40.c          | 3 +++
 7 files changed, 24 insertions(+)
Signature · 1 line
2.12.0
#1 lore raw

PATCH 1/7 Input: iforce - fix NULL-deref at probe

Make sure to check the number of endpoints to avoid dereferencing a NULL-pointer or accessing memory that lie beyond the end of the endpoint array should a malicious device lack the expected endpoints.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc stable <[email protected]>
---
 drivers/input/joystick/iforce/iforce-usb.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/input/joystick/iforce/iforce-usb.c +3 -0
index d96aa27dfcdc..db64adfbe1af 100644
@@ -141,6 +141,9 @@ static int iforce_usb_probe(struct usb_interface *intf,
 
 	interface = intf->cur_altsetting;
 
+	if (interface->desc.bNumEndpoints < 2)
+		return -ENODEV;
+
 	epirq = &interface->endpoint[0].desc;
 	epout = &interface->endpoint[1].desc;
 
Signature · 1 line
2.12.0
#2 lore raw

PATCH 2/7 Input: cm109 - fix NULL-deref at probe

In reply to Johan Hovold

Make sure to check the number of endpoints to avoid dereferencing a NULL-pointer should a malicious device lack endpoints.

Fixes c04148f915e5 ("Input: add driver for USB VoIP phones with CM109

chipset")
Cc: stable <[email protected]> # 2.6.28
Cc: Alfred E. Heggestad <[email protected]>

---
 drivers/input/misc/cm109.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/input/misc/cm109.c +4 -0
index 9cc6d057c302..23c191a2a071 100644
@@ -700,6 +700,10 @@ static int cm109_usb_probe(struct usb_interface *intf,
 	int error = -ENOMEM;
 
 	interface = intf->cur_altsetting;
+
+	if (interface->desc.bNumEndpoints < 1)
+		return -ENODEV;
+
 	endpoint = &interface->endpoint[0].desc;
 
 	if (!usb_endpoint_is_int_in(endpoint))
Signature · 6 lines
2.12.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw

PATCH 3/7 Input: ims-pcu - fix NULL-deref at probe

In reply to Johan Hovold

Make sure to check the number of endpoints to avoid dereferencing a NULL-pointer should a malicious device lack control-interface endpoints.

Fixes 628329d52474 ("Input: add IMS Passenger Control Unit driver")
Cc stable <[email protected]> # 3.10
Cc Dmitry Torokhov <[email protected]>
---
 drivers/input/misc/ims-pcu.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/input/misc/ims-pcu.c +4 -0
index 9c0ea36913b4..f4e8fbec6a94 100644
@@ -1667,6 +1667,10 @@ static int ims_pcu_parse_cdc_data(struct usb_interface *intf, struct ims_pcu *pc
 		return -EINVAL;
 
 	alt = pcu->ctrl_intf->cur_altsetting;
+
+	if (alt->desc.bNumEndpoints < 1)
+		return -ENODEV;
+
 	pcu->ep_ctrl = &alt->endpoint[0].desc;
 	pcu->max_ctrl_size = usb_endpoint_maxp(pcu->ep_ctrl);
 
Signature · 1 line
2.12.0
#4 lore raw

PATCH 4/7 Input: yealink - fix NULL-deref at probe

In reply to Johan Hovold

Make sure to check the number of endpoints to avoid dereferencing a NULL-pointer should a malicious device lack endpoints.

Fixes aca951a22a1d ("[PATCH] input-driver-yealink-P1K-usb-phone")
Cc stable <[email protected]> # 2.6.14
---
 drivers/input/misc/yealink.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/input/misc/yealink.c +4 -0
index 79c964c075f1..6e7ff9561d92 100644
@@ -875,6 +875,10 @@ static int usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
 	int ret, pipe, i;
 
 	interface = intf->cur_altsetting;
+
+	if (interface->desc.bNumEndpoints < 1)
+		return -ENODEV;
+
 	endpoint = &interface->endpoint[0].desc;
 	if (!usb_endpoint_is_int_in(endpoint))
 		return -ENODEV;
Signature · 1 line
2.12.0
#5 lore raw

PATCH 5/7 Input: hanwang - fix NULL-deref at probe

In reply to Johan Hovold

Make sure to check the number of endpoints to avoid dereferencing a NULL-pointer should a malicious device lack endpoints.

Fixes bba5394ad3bd ("Input: add support for Hanwang tablets")
Cc stable <[email protected]> # 2.6.37
Cc Xing Wei <[email protected]>
Cc Jiri Kosina <[email protected]>
---
 drivers/input/tablet/hanwang.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/input/tablet/hanwang.c +3 -0
index cd852059b99e..df4bea96d7ed 100644
@@ -340,6 +340,9 @@ static int hanwang_probe(struct usb_interface *intf, const struct usb_device_id
 	int error;
 	int i;
 
+	if (intf->cur_altsetting->desc.bNumEndpoints < 1)
+		return -ENODEV;
+
 	hanwang = kzalloc(sizeof(struct hanwang), GFP_KERNEL);
 	input_dev = input_allocate_device();
 	if (!hanwang || !input_dev) {
Signature · 1 line
2.12.0
#6 lore raw

PATCH 6/7 Input: kbtab - fix NULL-deref at probe

In reply to Johan Hovold

Make sure to check the number of endpoints to avoid dereferencing a NULL-pointer should a malicious device lack endpoints.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc stable <[email protected]>
---
 drivers/input/tablet/kbtab.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/input/tablet/kbtab.c +3 -0
index e850d7e8afbc..4d9d64908b59 100644
@@ -122,6 +122,9 @@ static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *i
 	struct input_dev *input_dev;
 	int error = -ENOMEM;
 
+	if (intf->cur_altsetting->desc.bNumEndpoints < 1)
+		return -ENODEV;
+
 	kbtab = kzalloc(sizeof(struct kbtab), GFP_KERNEL);
 	input_dev = input_allocate_device();
 	if (!kbtab || !input_dev)
Signature · 1 line
2.12.0
#7 lore raw

PATCH 7/7 Input: sur40 - fix NULL-deref at probe

In reply to Johan Hovold

Make sure to check the number of endpoints to avoid dereferencing a NULL-pointer or accessing memory that lie beyond the end of the endpoint array should a malicious device lack the expected endpoints.

Fixes bdb5c57f209c ("Input: add sur40 driver for Samsung SUR40 (aka MS

Surface 2.0/Pixelsense)")
Cc: stable <[email protected]> # 3.13
Cc: Florian Echtler <[email protected]>
Cc: David Herrmann <[email protected]>
Cc: Henrik Rydberg <[email protected]>

---
 drivers/input/touchscreen/sur40.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/input/touchscreen/sur40.c +3 -0
index aefb6e11f88a..4c0eecae065c 100644
@@ -527,6 +527,9 @@ static int sur40_probe(struct usb_interface *interface,
 	if (iface_desc->desc.bInterfaceClass != 0xFF)
 		return -ENODEV;
 
+	if (iface_desc->desc.bNumEndpoints < 5)
+		return -ENODEV;
+
 	/* Use endpoint #4 (0x86). */
 	endpoint = &iface_desc->endpoint[4].desc;
 	if (endpoint->bEndpointAddress != TOUCH_ENDPOINT)
Signature · 1 line
2.12.0
#8 lore raw
In reply to Johan Hovold

Am Montag, den 13.03.2017, 13:35 +0100 schrieb Johan Hovold:

Quoted 5 lines

This series fixes a number of NULL-pointer dereferences due to missing
endpoint sanity checks that can be triggered by a malicious USB device.

At the risk of repeating myself, doesn't the sheer number of fixes demonstrate the need for a more centralized check?

Regards
Oliver

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#9 lore raw
Quoted 8 lines · Oliver Neukum

Am Montag, den 13.03.2017, 13:35 +0100 schrieb Johan Hovold:

Quoted 4 lines

This series fixes a number of NULL-pointer dereferences due to missing
endpoint sanity checks that can be triggered by a malicious USB device.

At the risk of repeating myself, doesn't the sheer number of fixes demonstrate the need for a more centralized check?

No, I don't think that follows. These are plain bugs that needs to be fixed (cf. not checking for allocation failures or whatever) and backported to the stable trees.

I think I may have surveyed just about every USB driver this last week, and there is no single pattern for how endpoints are verified and retrieved that could easily be refactored into USB core.

Now there are certain patterns that could benefit from a few helpers, and some obvious bugs could then be caught by declaring those helpers as __must_check. But specifically, you'd still be checking the return value from the helpers.

Then verifying the endpoint counts before calling driver probe, typically only saves a bit of time while probing *malicious* devices (and the occasional odd interface which cannot be matched on other attributes).

That being said, we could still add a centralised sanity check for a large class of drivers (e.g. that do not use altsettings and only need minimum constraints) but it's not going to obviate the need for careful driver implementations.

I'll be posting some more patches related to this shortly.

Thanks,
Johan

maintainer
#10 lore raw
Quoted 28 lines · Johan Hovold
Quoted 8 lines · Oliver Neukum

Am Montag, den 13.03.2017, 13:35 +0100 schrieb Johan Hovold:

Quoted 4 lines

This series fixes a number of NULL-pointer dereferences due to missing
endpoint sanity checks that can be triggered by a malicious USB device.

At the risk of repeating myself, doesn't the sheer number of fixes demonstrate the need for a more centralized check?

No, I don't think that follows. These are plain bugs that needs to be fixed (cf. not checking for allocation failures or whatever) and backported to the stable trees.

I think I may have surveyed just about every USB driver this last week, and there is no single pattern for how endpoints are verified and retrieved that could easily be refactored into USB core.

Now there are certain patterns that could benefit from a few helpers, and some obvious bugs could then be caught by declaring those helpers as __must_check. But specifically, you'd still be checking the return value from the helpers.

Then verifying the endpoint counts before calling driver probe, typically only saves a bit of time while probing *malicious* devices (and the occasional odd interface which cannot be matched on other attributes).

Quoted 6 lines

That being said, we could still add a centralised sanity check for a large class of drivers (e.g. that do not use altsettings and only need minimum constraints) but it's not going to obviate the need for careful driver implementations.

I'll be posting some more patches related to this shortly.

There were some discussions about making and that would allow drivers declare endpoints they want and have USB core ether fill them or not even try to bind, but nothing concrete.

Anyway, I do not think we should be blocking this patch series on it; if we come up with something clever we can always switch over.

Applied the lot.

Thanks.

Signature · 1 line
Dmitry
#11 lore raw
Quoted 8 lines · Dmitry Torokhov
Quoted 5 lines · Johan Hovold
Quoted 4 lines · Oliver Neukum

Am Montag, den 13.03.2017, 13:35 +0100 schrieb Johan Hovold:

Quoted 3 lines

This series fixes a number of NULL-pointer dereferences due to missing endpoint sanity checks that can be triggered by a malicious USB device.

Applied the lot.

I noticed you dropped the Fixes tag from the patches that fix bugs which predate git. While this is probably not much of an issue in this case, I think it's generally a bad idea since we're loosing information this way, and this specifically makes it harder for the stable maintainers to figure out which tree to backport a fix to.

Thanks,
Johan

maintainer
#12 lore raw
Quoted 8 lines · Johan Hovold
Quoted 6 lines · Dmitry Torokhov
Quoted 5 lines · Johan Hovold
Quoted 4 lines · Oliver Neukum

Am Montag, den 13.03.2017, 13:35 +0100 schrieb Johan Hovold:

Quoted 3 lines

This series fixes a number of NULL-pointer dereferences due to missing endpoint sanity checks that can be triggered by a malicious USB device.

Quoted 7 lines
Quoted 1 line

Applied the lot.

I noticed you dropped the Fixes tag from the patches that fix bugs which predate git. While this is probably not much of an issue in this case, I think it's generally a bad idea since we're loosing information this way, and this specifically makes it harder for the stable maintainers to figure out which tree to backport a fix to.

As far as I know the rule is: if no special markings then stable patch should be applied as far as it can go.

There is no reason to say specify 2.6.12 commit, as in fact the offending change is likely to be even earlier, so the annotation would be effectively wrong.

Thanks.

Signature · 1 line
Dmitry
#13 lore raw
Quoted 11 lines · Dmitry Torokhov
Quoted 10 lines · Johan Hovold
Quoted 8 lines · Dmitry Torokhov
Quoted 5 lines · Johan Hovold
Quoted 4 lines · Oliver Neukum

Am Montag, den 13.03.2017, 13:35 +0100 schrieb Johan Hovold:

Quoted 3 lines

This series fixes a number of NULL-pointer dereferences due to missing endpoint sanity checks that can be triggered by a malicious USB device.

Applied the lot.

Quoted 8 lines
Quoted 5 lines

I noticed you dropped the Fixes tag from the patches that fix bugs which predate git. While this is probably not much of an issue in this case, I think it's generally a bad idea since we're loosing information this way, and this specifically makes it harder for the stable maintainers to figure out which tree to backport a fix to.

As far as I know the rule is: if no special markings then stable patch should be applied as far as it can go.

That's true for the stable tag itself, yes.

Quoted 3 lines

There is no reason to say specify 2.6.12 commit, as in fact the offending change is likely to be even earlier, so the annotation would be effectively wrong.

It is still the first git commit which has the bug, and everyone (dealing with code forensics) knows that 1da177e4c3f4 ("Linux-2.6.12-rc2") is special.

Adding a Fixes-tag pointing to that initial commit, makes it clear that bug has indeed been tracked as far back as reasonable. Omission of a Fixes-tag could on the other hand be due to the submitter not bothering to track the offending commit, thereby leaving it up to a stable maintainer to do so (if only just be sure).

Thanks,
Johan
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html