Linux-USB Archive on lore.kernel.org
 help / color / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: Oliver Neukum <oneukum@suse.com>
Cc: Kyungtae Kim <kt0755@gmail.com>, <linux-usb@vger.kernel.org>
Subject: Re: Fwd: BUG: KASAN: use-after-free in usb_hcd_unlink_urb+0x5f/0x170 drivers/usb/core/hcd.c
Date: Tue, 24 Mar 2020 09:29:25 -0400 (EDT)
Message-ID: <Pine.LNX.4.44L0.2003240928240.4640-100000@netrider.rowland.org> (raw)
In-Reply-To: <1585046753.7151.18.camel@suse.com>

On Tue, 24 Mar 2020, Oliver Neukum wrote:

> Am Montag, den 23.03.2020, 02:18 -0400 schrieb Kyungtae Kim:
> > We report a bug (in linux-5.5.11) found by FuzzUSB (a modified version
> > of syzkaller)
> 
> Hi,
> 
> thank you for the report. Is this a reproducible bug?
> 
> > In function usb_hcd_unlink_urb (driver/usb/core/hcd.c:1607), it tries to
> > read "urb->use_count". But it seems the instance "urb" was
> > already freed (right after urb->dev at line 1597) by the function "urb_destroy"
> > in a different thread, which caused memory access violation.
> 
> Yes.
> 
> > To solve, it may need to check if urb is valid before urb->use_count,
> > to avoid such freed memory access.
> 
> Difficult to do as the URB itself would be invalid.
> 
> I am afraid there is a race in here:
> 
> 
>         if (test_bit(US_FLIDX_ABORTING, &us->dflags)) {
>                 /* cancel the request, if it hasn't been cancelled already */
>                 if (test_and_clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags)) {
>                         usb_stor_dbg(us, "-- cancelling sg request\n");
>                         usb_sg_cancel(&us->current_sg);
>                 }
>         }
> 
>         /* wait for the completion of the transfer */
>         usb_sg_wait(&us->current_sg);
>         clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags);
> 
> 
> What keeps the request alive while usb_sg_wait() is running?

It's a bug in the SG library code.  I'll post a patch later on, 
although it's not clear whether anyone will be able to test it 
properly.

Alan Stern


  reply index

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAEAjamtb2Kbn0He5O++=d_HCG1eQvLnGGbcVUOQ76+NfDiNybQ@mail.gmail.com>
2020-03-23  6:18 ` Kyungtae Kim
2020-03-24 10:45   ` Oliver Neukum
2020-03-24 13:29     ` Alan Stern [this message]
2020-03-24 14:14   ` Alan Stern
2020-03-24 14:37     ` Kyungtae Kim
2020-03-26 14:49   ` Alan Stern
2020-03-28 14:11     ` Kyungtae Kim
2020-03-28 15:31       ` Alan Stern
2020-03-28 15:39         ` Kyungtae Kim
2020-03-28 20:18       ` [PATCH] USB: core: Fix free-while-in-use bug in the USB S-Glibrary Alan Stern

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.2003240928240.4640-100000@netrider.rowland.org \
    --to=stern@rowland.harvard.edu \
    --cc=kt0755@gmail.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=oneukum@suse.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
	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