Skip to contentSkip to conversation

staging: gigaset: fix crashes on probe

PATCH Superseded Johan Hovold 3 participants 11 messages Nov 29, 2019 – Dec 1, 2019 1 message not in the archive

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover staging: gigaset: fix crashes on probe

Syzbot has been reporting a GPF on probe in the gigaset ISDN driver, which have since been moved to staging.

The first patch fixes that issue, and the next one fixes a second crash found during testing.

The third patch addresses a benign warning in USB core which syzbot is bound to report once the crashes have been fixed.

And while I hate playing checkpatch games, the final patch addresses a checkpatch warning introduced on purpose by the third patch.

Johan

Johan Hovold (4):
staging: gigaset: fix general protection fault on probe
staging: gigaset: fix illegal free on probe errors
staging: gigaset: add endpoint-type sanity check
staging: gigaset: rename endpoint-descriptor identifier

 drivers/staging/isdn/gigaset/usb-gigaset.c | 39 ++++++++++++++--------
 1 file changed, 26 insertions(+), 13 deletions(-)
Signature · 1 line
2.24.0
#1 lore raw

PATCH 1/4 staging: gigaset: fix general protection fault on probe

Fix a general protection fault when accessing the endpoint descriptors which could be triggered by a malicious device due to missing sanity checks on the number of endpoints.

Reported-by [email protected]
Fixes 07dc1f9f2f80 ("[PATCH] isdn4linux: Siemens Gigaset drivers - M105 USB DECT adapter")
Cc stable <[email protected]> # 2.6.17
Cc Hansjoerg Lipp <[email protected]>
Cc Tilman Schmidt <[email protected]>
---
 drivers/staging/isdn/gigaset/usb-gigaset.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/staging/isdn/gigaset/usb-gigaset.c +5 -0
index 1b9b43659bdf..5e393e7dde45 100644
@@ -685,6 +685,11 @@ static int gigaset_probe(struct usb_interface *interface,
 		return -ENODEV;
 	}
 
+	if (hostif->desc.bNumEndpoints < 2) {
+		dev_err(&interface->dev, "missing endpoints\n");
+		return -ENODEV;
+	}
+
 	dev_info(&udev->dev, "%s: Device matched ... !\n", __func__);
 
 	/* allocate memory for our device state and initialize it */
Signature · 1 line
2.24.0

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw

Re: [PATCH 1/4] staging: gigaset: fix general protection fault on probe

Hi Johan,

this is probably caused by the move of the driver to staging in kernel release 5.3 half a year ago. If you want your patches to apply to pre-5.3 stable releases you'll have to submit a version with the paths changed from drivers/staging/isdn/gigaset to drivers/isdn/gigaset.

HTH
Tilman

Am 01.12.2019 um 01:15 schrieb Sasha Levin:

Quoted 28 lines

Hi,

[This is an automated email]

This commit has been processed because it contains a "Fixes:" tag,
fixing commit: 07dc1f9f2f80 ("[PATCH] isdn4linux: Siemens Gigaset drivers - M105 USB DECT adapter").

The bot has tested the following trees: v5.4.1, v5.3.14, v4.19.86, v4.14.156, v4.9.205, v4.4.205.

v5.4.1: Build OK!
v5.3.14: Build OK!
v4.19.86: Failed to apply! Possible dependencies:
Unable to calculate

v4.14.156: Failed to apply! Possible dependencies:
Unable to calculate

v4.9.205: Failed to apply! Possible dependencies:
Unable to calculate

v4.4.205: Failed to apply! Possible dependencies:
Unable to calculate

NOTE: The patch will not be queued to stable trees until it is upstream.

How should we proceed with this patch?

#4 lore raw

Re: [PATCH 1/4] staging: gigaset: fix general protection fault on probe

Quoted 7 lines · Tilman Schmidt

Hi Johan,

this is probably caused by the move of the driver to staging in kernel release 5.3 half a year ago. If you want your patches to apply to pre-5.3 stable releases you'll have to submit a version with the paths changed from drivers/staging/isdn/gigaset to drivers/isdn/gigaset.

That's trivial for me to do when they get added to the stable tree(s), no need to worry about it.

thanks,

greg k-h

#5 lore raw

Re: [PATCH 1/4] staging: gigaset: fix general protection fault on probe

Quoted 11 lines · Greg Kroah-Hartman
Quoted 7 lines · Tilman Schmidt

Hi Johan,

this is probably caused by the move of the driver to staging in kernel release 5.3 half a year ago. If you want your patches to apply to pre-5.3 stable releases you'll have to submit a version with the paths changed from drivers/staging/isdn/gigaset to drivers/isdn/gigaset.

That's trivial for me to do when they get added to the stable tree(s), no need to worry about it.

I'll be sending a v2 of this series shortly. Somehow I managed to overlook usb_endpoint_is_bulk_in() and friends so patch 4/4 should no longer be needed either.

Johan

#6 lore raw

PATCH 2/4 staging: gigaset: fix illegal free on probe errors

In reply to Johan Hovold

The driver failed to initialise its receive-buffer pointer, something which could lead to an illegal free on late probe errors.

Fix this by making sure to clear all driver data at allocation.

Fixes 2032e2c2309d ("usb_gigaset: code cleanup")
Cc stable <[email protected]> # 2.6.33
Cc Tilman Schmidt <[email protected]>
---
 drivers/staging/isdn/gigaset/usb-gigaset.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/staging/isdn/gigaset/usb-gigaset.c +1 -5
index 5e393e7dde45..a84722d83bc6 100644
@@ -571,8 +571,7 @@ static int gigaset_initcshw(struct cardstate *cs)
 {
 	struct usb_cardstate *ucs;
 
-	cs->hw.usb = ucs =
-		kmalloc(sizeof(struct usb_cardstate), GFP_KERNEL);
+	cs->hw.usb = ucs = kzalloc(sizeof(struct usb_cardstate), GFP_KERNEL);
 	if (!ucs) {
 		pr_err("out of memory\n");
 		return -ENOMEM;
@@ -584,9 +583,6 @@ static int gigaset_initcshw(struct cardstate *cs)
 	ucs->bchars[3] = 0;
 	ucs->bchars[4] = 0x11;
 	ucs->bchars[5] = 0x13;
-	ucs->bulk_out_buffer = NULL;
-	ucs->bulk_out_urb = NULL;
-	ucs->read_urb = NULL;
 	tasklet_init(&cs->write_tasklet,
 		     gigaset_modem_fill, (unsigned long) cs);
 
Signature · 1 line
2.24.0
#7 lore raw

PATCH 3/4 staging: gigaset: add endpoint-type sanity check

In reply to Johan Hovold

Add endpoint type-sanity checks to prevent a warning in USB core on URB submission.

---
 drivers/staging/isdn/gigaset/usb-gigaset.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/staging/isdn/gigaset/usb-gigaset.c +12 -0
index a84722d83bc6..6c07c8379711 100644
@@ -705,6 +705,12 @@ static int gigaset_probe(struct usb_interface *interface,
 
 	endpoint = &hostif->endpoint[0].desc;
 
+	if (!usb_endpoint_dir_out(endpoint) || !usb_endpoint_xfer_bulk(endpoint)) {
+		dev_err(&interface->dev, "missing bulk-out endpoint\n");
+		retval = -ENODEV;
+		goto error;
+	}
+
 	buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
 	ucs->bulk_out_size = buffer_size;
 	ucs->bulk_out_epnum = usb_endpoint_num(endpoint);
@@ -724,6 +730,12 @@ static int gigaset_probe(struct usb_interface *interface,
 
 	endpoint = &hostif->endpoint[1].desc;
 
+	if (!usb_endpoint_dir_in(endpoint) || !usb_endpoint_xfer_int(endpoint)) {
+		dev_err(&interface->dev, "missing int-in endpoint\n");
+		retval = -ENODEV;
+		goto error;
+	}
+
 	ucs->busy = 0;
 
 	ucs->read_urb = usb_alloc_urb(0, GFP_KERNEL);
Signature · 1 line
2.24.0
#8 lore raw

PATCH 4/4 staging: gigaset: rename endpoint-descriptor identifier

In reply to Johan Hovold

Rename an endpoint-descriptor pointer to shut up a checkpatch warning about a line being over 80 columns, which is bound to generate a bunch of clean up patches otherwise.

---
 drivers/staging/isdn/gigaset/usb-gigaset.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/staging/isdn/gigaset/usb-gigaset.c +10 -10
index 6c07c8379711..d5fab2ea25b4 100644
@@ -652,7 +652,7 @@ static int gigaset_probe(struct usb_interface *interface,
 	struct usb_host_interface *hostif = interface->cur_altsetting;
 	struct cardstate *cs = NULL;
 	struct usb_cardstate *ucs = NULL;
-	struct usb_endpoint_descriptor *endpoint;
+	struct usb_endpoint_descriptor *epd;
 	int buffer_size;
 
 	gig_dbg(DEBUG_ANY, "%s: Check if device matches ...", __func__);
@@ -703,17 +703,17 @@ static int gigaset_probe(struct usb_interface *interface,
 	/* save address of controller structure */
 	usb_set_intfdata(interface, cs);
 
-	endpoint = &hostif->endpoint[0].desc;
+	epd = &hostif->endpoint[0].desc;
 
-	if (!usb_endpoint_dir_out(endpoint) || !usb_endpoint_xfer_bulk(endpoint)) {
+	if (!usb_endpoint_dir_out(epd) || !usb_endpoint_xfer_bulk(epd)) {
 		dev_err(&interface->dev, "missing bulk-out endpoint\n");
 		retval = -ENODEV;
 		goto error;
 	}
 
-	buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
+	buffer_size = le16_to_cpu(epd->wMaxPacketSize);
 	ucs->bulk_out_size = buffer_size;
-	ucs->bulk_out_epnum = usb_endpoint_num(endpoint);
+	ucs->bulk_out_epnum = usb_endpoint_num(epd);
 	ucs->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL);
 	if (!ucs->bulk_out_buffer) {
 		dev_err(cs->dev, "Couldn't allocate bulk_out_buffer\n");
@@ -728,9 +728,9 @@ static int gigaset_probe(struct usb_interface *interface,
 		goto error;
 	}
 
-	endpoint = &hostif->endpoint[1].desc;
+	epd = &hostif->endpoint[1].desc;
 
-	if (!usb_endpoint_dir_in(endpoint) || !usb_endpoint_xfer_int(endpoint)) {
+	if (!usb_endpoint_dir_in(epd) || !usb_endpoint_xfer_int(epd)) {
 		dev_err(&interface->dev, "missing int-in endpoint\n");
 		retval = -ENODEV;
 		goto error;
@@ -744,7 +744,7 @@ static int gigaset_probe(struct usb_interface *interface,
 		retval = -ENOMEM;
 		goto error;
 	}
-	buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
+	buffer_size = le16_to_cpu(epd->wMaxPacketSize);
 	ucs->rcvbuf_size = buffer_size;
 	ucs->rcvbuf = kmalloc(buffer_size, GFP_KERNEL);
 	if (!ucs->rcvbuf) {
@@ -754,10 +754,10 @@ static int gigaset_probe(struct usb_interface *interface,
 	}
 	/* Fill the interrupt urb and send it to the core */
 	usb_fill_int_urb(ucs->read_urb, udev,
-			 usb_rcvintpipe(udev, usb_endpoint_num(endpoint)),
+			 usb_rcvintpipe(udev, usb_endpoint_num(epd)),
 			 ucs->rcvbuf, buffer_size,
 			 gigaset_read_int_callback,
-			 cs, endpoint->bInterval);
+			 cs, epd->bInterval);
 
 	retval = usb_submit_urb(ucs->read_urb, GFP_KERNEL);
 	if (retval) {
Signature · 1 line
2.24.0
#9 lore raw
In reply to Johan Hovold
Quoted 11 lines · Johan Hovold

Syzbot has been reporting a GPF on probe in the gigaset ISDN driver, which have since been moved to staging.

The first patch fixes that issue, and the next one fixes a second crash found during testing.

The third patch addresses a benign warning in USB core which syzbot is bound to report once the crashes have been fixed.

And while I hate playing checkpatch games, the final patch addresses a checkpatch warning introduced on purpose by the third patch.

I'll take these after 5.5-rc1, but then it is time to just delete all of drivers/staging/isdn/ from my tree, so don't worry about them after that :)

thanks,

greg k-h

#10 lore raw
Quoted 9 lines · Johan Hovold
Quoted 9 lines

Syzbot has been reporting a GPF on probe in the gigaset ISDN driver, which have since been moved to staging.

The first patch fixes that issue, and the next one fixes a second crash found during testing.

The third patch addresses a benign warning in USB core which syzbot is bound to report once the crashes have been fixed.

Quoted 6 lines
Quoted 2 lines

And while I hate playing checkpatch games, the final patch addresses a checkpatch warning introduced on purpose by the third patch.

I'll take these after 5.5-rc1, but then it is time to just delete all of drivers/staging/isdn/ from my tree, so don't worry about them after that :)

Sounds good to me. :)

But we should probably get these backported before dropping staging/isdn. Not sure if syzbot is run against older stable trees as well, but if so, you may want to consider adding a stable-tag also to patch 3/4.

Johan

#11 lore raw
Quoted 17 lines · Johan Hovold
Quoted 9 lines · Johan Hovold
Quoted 9 lines

Syzbot has been reporting a GPF on probe in the gigaset ISDN driver, which have since been moved to staging.

The first patch fixes that issue, and the next one fixes a second crash found during testing.

The third patch addresses a benign warning in USB core which syzbot is bound to report once the crashes have been fixed.

Quoted 6 lines
Quoted 2 lines

And while I hate playing checkpatch games, the final patch addresses a checkpatch warning introduced on purpose by the third patch.

I'll take these after 5.5-rc1, but then it is time to just delete all of drivers/staging/isdn/ from my tree, so don't worry about them after that :)

Quoted 6 lines

Sounds good to me. :)

But we should probably get these backported before dropping staging/isdn. Not sure if syzbot is run against older stable trees as well, but if so, you may want to consider adding a stable-tag also to patch 3/4.

Yes, I will backport them, it's a good idea to do that.

thanks,

greg k-h