linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: Oliver Neukum <oneukum@suse.com>
Cc: syzbot <syzbot+ef5de9c4f99c4edb4e49@syzkaller.appspotmail.com>,
	<andreyknvl@google.com>, <syzkaller-bugs@googlegroups.com>,
	<linux-usb@vger.kernel.org>
Subject: Re: KASAN: use-after-free Read in usbhid_power
Date: Wed, 24 Jul 2019 17:02:17 -0400 (EDT)	[thread overview]
Message-ID: <Pine.LNX.4.44L0.1907241659410.10248-100000@netrider.rowland.org> (raw)
In-Reply-To: <1564001709.4670.10.camel@suse.com>

On Wed, 24 Jul 2019, Oliver Neukum wrote:

> Am Dienstag, den 23.07.2019, 05:48 -0700 schrieb syzbot:
> > Hello,
> > 
> > syzbot found the following crash on:
> > 
> > HEAD commit:    6a3599ce usb-fuzzer: main usb gadget fuzzer driver
> > git tree:       https://github.com/google/kasan.git usb-fuzzer
> > console output: https://syzkaller.appspot.com/x/log.txt?x=11b13e78600000
> > kernel config:  https://syzkaller.appspot.com/x/.config?x=700ca426ab83faae
> > dashboard link: https://syzkaller.appspot.com/bug?extid=ef5de9c4f99c4edb4e49
> > compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
> > syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=15482210600000
> > C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=1139b07c600000
> > 
> > IMPORTANT: if you fix the bug, please add the following tag to the commit:
> > Reported-by: syzbot+ef5de9c4f99c4edb4e49@syzkaller.appspotmail.com
> > 
> > ==================================================================
> > BUG: KASAN: use-after-free in usbhid_power+0xca/0xe0  
> > /drivers/hid/usbhid/hid-core.c:1234
> > Read of size 8 at addr ffff8881ce8a4008 by task syz-executor373/1763
> 
> #syz test: https://github.com/google/kasan.git usb-fuzzer
> 
> From a3455c4527bdfe86536856ea96288b7dcc36590b Mon Sep 17 00:00:00 2001
> From: Oliver Neukum <oneukum@suse.com>
> Date: Wed, 24 Jul 2019 22:49:57 +0200
> Subject: [PATCH] usbhid: test for disconnected state in raw opening
> 
> If the device has been disconnected, we should not proceed to use
> runtime PM on it.
> 
> Reported-by: syzbot+ef5de9c4f99c4edb4e49@syzkaller.appspotmail.com
> Signed-off-by: Oliver Neukum <oneukum@suse.de>
> ---
>  drivers/hid/usbhid/hid-core.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
> index c7bc9db5b192..98b996ecf4d3 100644
> --- a/drivers/hid/usbhid/hid-core.c
> +++ b/drivers/hid/usbhid/hid-core.c
> @@ -1229,6 +1229,17 @@ static int usbhid_power(struct hid_device *hid, int lvl)
>  	struct usbhid_device *usbhid = hid->driver_data;
>  	int r = 0;
>  
> +	spin_lock_irq(&usbhid->lock);
> +	if (test_bit(HID_DISCONNECTED, &usbhid->iofl)) {
> +		r = -ENODEV;
> +		spin_unlock_irq(&usbhid->lock);
> +		goto bail_out;
> +	} else {
> +		/* protect against disconnect */
> +		usb_get_dev(interface_to_usbdev(usbhid->intf));
> +		spin_unlock_irq(&usbhid->lock);
> +	}
> +
>  	switch (lvl) {
>  	case PM_HINT_FULLON:
>  		r = usb_autopm_get_interface(usbhid->intf);
> @@ -1238,7 +1249,9 @@ static int usbhid_power(struct hid_device *hid, int lvl)
>  		usb_autopm_put_interface(usbhid->intf);
>  		break;
>  	}
> +	usb_put_dev(interface_to_usbdev(usbhid->intf));
>  
> +bail_out:
>  	return r;
>  }

Isn't this treating the symptom instead of the cause?

Shouldn't the hid_device hold a reference to usbhid->intf throughout 
its lifetime?  That way this sort of problem wouldn't arise in any 
routine, not just usbhid_power().

Alan Stern


  reply	other threads:[~2019-07-24 21:02 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-23 12:48 KASAN: use-after-free Read in usbhid_power syzbot
2019-07-24 14:17 ` Oliver Neukum
2019-07-24 14:24   ` Andrey Konovalov
2019-07-24 20:55 ` Oliver Neukum
2019-07-24 21:02   ` Alan Stern [this message]
2019-07-25  9:33     ` Oliver Neukum
2019-07-25 15:09       ` Alan Stern
2019-08-08 18:54         ` Andrey Konovalov
2019-08-08 19:37           ` Alan Stern
2019-08-09  7:35             ` AW: " Schmid, Carsten
2019-08-09  7:55               ` Greg KH
2019-08-09  9:34                 ` AW: " Schmid, Carsten
2019-08-09 10:20                   ` Hans de Goede
2019-08-09 10:47                     ` AW: " Schmid, Carsten
2019-08-09 10:53                       ` Hans de Goede
2019-08-09 12:38                         ` AW: " Schmid, Carsten
2019-08-09 12:54                           ` Greg KH
2019-08-09 13:00                             ` AW: " Schmid, Carsten
2019-08-09 13:38                               ` Greg KH
2019-08-10 11:12                           ` AW: " Hans de Goede
2019-08-09 17:36             ` Andrey Konovalov
2019-08-09 18:12               ` syzbot
2019-08-12 14:29                 ` Andrey Konovalov
2019-08-09 20:26           ` Oliver Neukum
2019-07-24 21:16   ` syzbot
2019-07-25 11:22     ` Andrey Konovalov
2019-07-25 12:15 ` Oliver Neukum
2019-07-25 12:27   ` syzbot

Reply instructions:

You may reply publicly 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.1907241659410.10248-100000@netrider.rowland.org \
    --to=stern@rowland.harvard.edu \
    --cc=andreyknvl@google.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=oneukum@suse.com \
    --cc=syzbot+ef5de9c4f99c4edb4e49@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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).