Linux-USB Archive on lore.kernel.org
 help / color / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: syzbot <syzbot+1b2449b7b5dc240d107a@syzkaller.appspotmail.com>
Cc: andreyknvl@google.com, <linux-kernel@vger.kernel.org>,
	<linux-usb@vger.kernel.org>, <oneukum@suse.com>,
	<syzkaller-bugs@googlegroups.com>
Subject: Re: KASAN: use-after-free Read in device_release_driver_internal
Date: Wed, 7 Aug 2019 14:05:42 -0400 (EDT)
Message-ID: <Pine.LNX.4.44L0.1908071402160.1514-100000@iolanthe.rowland.org> (raw)
In-Reply-To: <00000000000085d6b4058f8a957a@google.com>

On Wed, 7 Aug 2019, syzbot wrote:

> Hello,
> 
> syzbot has tested the proposed patch but the reproducer still triggered  
> crash:
> KASAN: use-after-free Read in device_release_driver_internal

> Tested on:
> 
> commit:         6a3599ce usb-fuzzer: main usb gadget fuzzer driver
> git tree:       https://github.com/google/kasan.git
> console output: https://syzkaller.appspot.com/x/log.txt?x=142eec8c600000
> kernel config:  https://syzkaller.appspot.com/x/.config?x=700ca426ab83faae
> compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
> patch:          https://syzkaller.appspot.com/x/patch.diff?x=15d95bf6600000

The kernel log is pretty definite here:

[   40.270346][   T89] cdc_acm 5-1:0.234: Refcount before probe: 3
[   40.284514][   T89] cdc_acm 5-1:0.234: invalid descriptor buffer length
[   40.284523][   T89] cdc_acm 5-1:0.234: No union descriptor, testing for castrated device
[   40.285322][   T89] cdc_acm 5-1:0.234: Refcount after probe: 2

2 < 3.  So let's combine the diagnostic patch with Oliver's proposed 
solution.

Alan Stern

#syz test: https://github.com/google/kasan.git 6a3599ce

Index: usb-devel/drivers/usb/core/driver.c
===================================================================
--- usb-devel.orig/drivers/usb/core/driver.c
+++ usb-devel/drivers/usb/core/driver.c
@@ -358,7 +358,11 @@ static int usb_probe_interface(struct de
 		intf->needs_altsetting0 = 0;
 	}
 
+	dev_info(&intf->dev, "Refcount before probe: %d\n",
+			refcount_read(&intf->dev.kobj.kref.refcount));
 	error = driver->probe(intf, id);
+	dev_info(&intf->dev, "Refcount after probe: %d\n",
+			refcount_read(&intf->dev.kobj.kref.refcount));
 	if (error)
 		goto err;
 
Index: usb-devel/drivers/usb/class/cdc-acm.c
===================================================================
--- usb-devel.orig/drivers/usb/class/cdc-acm.c
+++ usb-devel/drivers/usb/class/cdc-acm.c
@@ -1301,10 +1301,6 @@ made_compressed_probe:
 	tty_port_init(&acm->port);
 	acm->port.ops = &acm_port_ops;
 
-	minor = acm_alloc_minor(acm);
-	if (minor < 0)
-		goto alloc_fail1;
-
 	ctrlsize = usb_endpoint_maxp(epctrl);
 	readsize = usb_endpoint_maxp(epread) *
 				(quirks == SINGLE_RX_URB ? 1 : 2);
@@ -1312,6 +1308,13 @@ made_compressed_probe:
 	acm->writesize = usb_endpoint_maxp(epwrite) * 20;
 	acm->control = control_interface;
 	acm->data = data_interface;
+
+	usb_get_intf(acm->control); /* undone in destroy() */
+
+	minor = acm_alloc_minor(acm);
+	if (minor < 0)
+		goto alloc_fail1;
+
 	acm->minor = minor;
 	acm->dev = usb_dev;
 	if (h.usb_cdc_acm_descriptor)
@@ -1458,7 +1461,6 @@ skip_countries:
 	usb_driver_claim_interface(&acm_driver, data_interface, acm);
 	usb_set_intfdata(data_interface, acm);
 
-	usb_get_intf(control_interface);
 	tty_dev = tty_port_register_device(&acm->port, acm_tty_driver, minor,
 			&control_interface->dev);
 	if (IS_ERR(tty_dev)) {


  reply index

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-23 14:28 syzbot
2019-08-01 16:01 ` Andrey Konovalov
2019-08-01 18:47   ` Alan Stern
2019-08-06 12:36     ` Oliver Neukum
2019-08-06 12:50       ` Andrey Konovalov
2019-08-07 13:38         ` Oliver Neukum
2019-08-07 13:44           ` Andrey Konovalov
2019-08-07 13:44             ` Andrey Konovalov
2019-08-07 13:45               ` Andrey Konovalov
2019-08-07 14:13                 ` syzbot
2019-08-07 13:56               ` syzbot
2019-08-07 17:40                 ` Alan Stern
2019-08-07 17:51                   ` syzbot
2019-08-07 18:05                     ` Alan Stern [this message]
2019-08-07 18:23                       ` syzbot
2019-08-07 18:31                         ` Alan Stern
2019-08-08 12:27                           ` Andrey Konovalov
2019-08-08 12:43                             ` Dmitry Vyukov
2019-08-08 13:03                               ` Andrey Konovalov
2019-08-08 13:59                                 ` Alan Stern
2019-08-13 12:42                                   ` Andrey Konovalov
2019-08-13 13:22                                     ` Oliver Neukum
2019-08-13 13:24                                       ` Andrey Konovalov
2019-08-13 15:16                                       ` Greg KH
2019-08-13 13:59               ` Andrey Konovalov
2019-08-06 14:19       ` Alan Stern
2019-08-06 14:25         ` Oliver Neukum
2019-08-06 15:33         ` Oliver Neukum
2019-08-07 13:46           ` Andrey Konovalov

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.44L0.1908071402160.1514-100000@iolanthe.rowland.org \
    --to=stern@rowland.harvard.edu \
    --cc=andreyknvl@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=oneukum@suse.com \
    --cc=syzbot+1b2449b7b5dc240d107a@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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 linux-usb@archiver.kernel.org
	public-inbox-index linux-usb


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