Linux-USB Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/4] staging: gigaset: fix crashes on probe
@ 2019-11-29 10:17 Johan Hovold
  2019-11-29 10:17 ` [PATCH 1/4] staging: gigaset: fix general protection fault " Johan Hovold
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Johan Hovold @ 2019-11-29 10:17 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: devel, linux-kernel, linux-usb, 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.

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(-)

-- 
2.24.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/4] staging: gigaset: fix general protection fault on probe
  2019-11-29 10:17 [PATCH 0/4] staging: gigaset: fix crashes on probe Johan Hovold
@ 2019-11-29 10:17 ` " Johan Hovold
  2019-11-29 10:17 ` [PATCH 2/4] staging: gigaset: fix illegal free on probe errors Johan Hovold
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Johan Hovold @ 2019-11-29 10:17 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, linux-kernel, linux-usb, Johan Hovold,
	syzbot+35b1c403a14f5c89eba7, stable, Hansjoerg Lipp,
	Tilman Schmidt

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: syzbot+35b1c403a14f5c89eba7@syzkaller.appspotmail.com
Fixes: 07dc1f9f2f80 ("[PATCH] isdn4linux: Siemens Gigaset drivers - M105 USB DECT adapter")
Cc: stable <stable@vger.kernel.org>     # 2.6.17
Cc: Hansjoerg Lipp <hjlipp@web.de>
Cc: Tilman Schmidt <tilman@imap.cc>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/staging/isdn/gigaset/usb-gigaset.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/staging/isdn/gigaset/usb-gigaset.c b/drivers/staging/isdn/gigaset/usb-gigaset.c
index 1b9b43659bdf..5e393e7dde45 100644
--- a/drivers/staging/isdn/gigaset/usb-gigaset.c
+++ b/drivers/staging/isdn/gigaset/usb-gigaset.c
@@ -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 */
-- 
2.24.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/4] staging: gigaset: fix illegal free on probe errors
  2019-11-29 10:17 [PATCH 0/4] staging: gigaset: fix crashes on probe Johan Hovold
  2019-11-29 10:17 ` [PATCH 1/4] staging: gigaset: fix general protection fault " Johan Hovold
@ 2019-11-29 10:17 ` Johan Hovold
  2019-11-29 10:17 ` [PATCH 3/4] staging: gigaset: add endpoint-type sanity check Johan Hovold
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Johan Hovold @ 2019-11-29 10:17 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, linux-kernel, linux-usb, Johan Hovold, stable, Tilman Schmidt

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 <stable@vger.kernel.org>     # 2.6.33
Cc: Tilman Schmidt <tilman@imap.cc>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/staging/isdn/gigaset/usb-gigaset.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/staging/isdn/gigaset/usb-gigaset.c b/drivers/staging/isdn/gigaset/usb-gigaset.c
index 5e393e7dde45..a84722d83bc6 100644
--- a/drivers/staging/isdn/gigaset/usb-gigaset.c
+++ b/drivers/staging/isdn/gigaset/usb-gigaset.c
@@ -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);
 
-- 
2.24.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 3/4] staging: gigaset: add endpoint-type sanity check
  2019-11-29 10:17 [PATCH 0/4] staging: gigaset: fix crashes on probe Johan Hovold
  2019-11-29 10:17 ` [PATCH 1/4] staging: gigaset: fix general protection fault " Johan Hovold
  2019-11-29 10:17 ` [PATCH 2/4] staging: gigaset: fix illegal free on probe errors Johan Hovold
@ 2019-11-29 10:17 ` Johan Hovold
  2019-11-29 10:17 ` [PATCH 4/4] staging: gigaset: rename endpoint-descriptor identifier Johan Hovold
  2019-11-29 13:32 ` [PATCH 0/4] staging: gigaset: fix crashes on probe Greg Kroah-Hartman
  4 siblings, 0 replies; 8+ messages in thread
From: Johan Hovold @ 2019-11-29 10:17 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: devel, linux-kernel, linux-usb, Johan Hovold

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

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/staging/isdn/gigaset/usb-gigaset.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/staging/isdn/gigaset/usb-gigaset.c b/drivers/staging/isdn/gigaset/usb-gigaset.c
index a84722d83bc6..6c07c8379711 100644
--- a/drivers/staging/isdn/gigaset/usb-gigaset.c
+++ b/drivers/staging/isdn/gigaset/usb-gigaset.c
@@ -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);
-- 
2.24.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 4/4] staging: gigaset: rename endpoint-descriptor identifier
  2019-11-29 10:17 [PATCH 0/4] staging: gigaset: fix crashes on probe Johan Hovold
                   ` (2 preceding siblings ...)
  2019-11-29 10:17 ` [PATCH 3/4] staging: gigaset: add endpoint-type sanity check Johan Hovold
@ 2019-11-29 10:17 ` Johan Hovold
  2019-11-29 13:32 ` [PATCH 0/4] staging: gigaset: fix crashes on probe Greg Kroah-Hartman
  4 siblings, 0 replies; 8+ messages in thread
From: Johan Hovold @ 2019-11-29 10:17 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: devel, linux-kernel, linux-usb, 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.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/staging/isdn/gigaset/usb-gigaset.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/isdn/gigaset/usb-gigaset.c b/drivers/staging/isdn/gigaset/usb-gigaset.c
index 6c07c8379711..d5fab2ea25b4 100644
--- a/drivers/staging/isdn/gigaset/usb-gigaset.c
+++ b/drivers/staging/isdn/gigaset/usb-gigaset.c
@@ -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) {
-- 
2.24.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/4] staging: gigaset: fix crashes on probe
  2019-11-29 10:17 [PATCH 0/4] staging: gigaset: fix crashes on probe Johan Hovold
                   ` (3 preceding siblings ...)
  2019-11-29 10:17 ` [PATCH 4/4] staging: gigaset: rename endpoint-descriptor identifier Johan Hovold
@ 2019-11-29 13:32 ` Greg Kroah-Hartman
  2019-11-29 13:51   ` Johan Hovold
  4 siblings, 1 reply; 8+ messages in thread
From: Greg Kroah-Hartman @ 2019-11-29 13:32 UTC (permalink / raw)
  To: Johan Hovold; +Cc: devel, linux-kernel, linux-usb

On Fri, Nov 29, 2019 at 11:17:49AM +0100, Johan Hovold wrote:
> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/4] staging: gigaset: fix crashes on probe
  2019-11-29 13:32 ` [PATCH 0/4] staging: gigaset: fix crashes on probe Greg Kroah-Hartman
@ 2019-11-29 13:51   ` Johan Hovold
  2019-11-29 14:23     ` Greg Kroah-Hartman
  0 siblings, 1 reply; 8+ messages in thread
From: Johan Hovold @ 2019-11-29 13:51 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Johan Hovold, devel, linux-kernel, linux-usb

On Fri, Nov 29, 2019 at 02:32:39PM +0100, Greg Kroah-Hartman wrote: > On Fri, Nov 29, 2019 at 11:17:49AM +0100, Johan Hovold wrote:
> > 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
> :)

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/4] staging: gigaset: fix crashes on probe
  2019-11-29 13:51   ` Johan Hovold
@ 2019-11-29 14:23     ` Greg Kroah-Hartman
  0 siblings, 0 replies; 8+ messages in thread
From: Greg Kroah-Hartman @ 2019-11-29 14:23 UTC (permalink / raw)
  To: Johan Hovold; +Cc: devel, linux-kernel, linux-usb

On Fri, Nov 29, 2019 at 02:51:45PM +0100, Johan Hovold wrote:
> On Fri, Nov 29, 2019 at 02:32:39PM +0100, Greg Kroah-Hartman wrote: > On Fri, Nov 29, 2019 at 11:17:49AM +0100, Johan Hovold wrote:
> > > 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
> > :)
> 
> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, back to index

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-29 10:17 [PATCH 0/4] staging: gigaset: fix crashes on probe Johan Hovold
2019-11-29 10:17 ` [PATCH 1/4] staging: gigaset: fix general protection fault " Johan Hovold
2019-11-29 10:17 ` [PATCH 2/4] staging: gigaset: fix illegal free on probe errors Johan Hovold
2019-11-29 10:17 ` [PATCH 3/4] staging: gigaset: add endpoint-type sanity check Johan Hovold
2019-11-29 10:17 ` [PATCH 4/4] staging: gigaset: rename endpoint-descriptor identifier Johan Hovold
2019-11-29 13:32 ` [PATCH 0/4] staging: gigaset: fix crashes on probe Greg Kroah-Hartman
2019-11-29 13:51   ` Johan Hovold
2019-11-29 14:23     ` Greg Kroah-Hartman

Linux-USB Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-usb/0 linux-usb/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-usb linux-usb/ https://lore.kernel.org/linux-usb \
		linux-usb@vger.kernel.org
	public-inbox-index linux-usb

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-usb


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git