From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: John Garry <john.garry@huawei.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>
Subject: Re: [Report]: BUG: KASAN: use-after-free in usb_hcd_pci_remove
Date: Fri, 14 Aug 2020 21:07:20 +0300 [thread overview]
Message-ID: <20200814180720.GE1891694@smile.fi.intel.com> (raw)
In-Reply-To: <30a8c4ca-64c2-863b-cfcd-0970599c0ba3@huawei.com>
On Fri, Aug 14, 2020 at 06:18:16PM +0100, John Garry wrote:
Thanks for notifying me, my comments below.
...
> From a3b9e1b405d1efdfee2ee672bbf7dc1c7de62d66 Mon Sep 17 00:00:00 2001
> From: John Garry <john.garry@huawei.com>
> Date: Fri, 14 Aug 2020 18:14:51 +0100
> Subject: [PATCH] usb: hcd: Fix use-after-free in usb_hcd_pci_remove()
>
> KASAN reports when CONFIG_DEBUG_TEST_DRIVER_REMOVE is enabled:
Please, reduce these huge trace backs, they have a lot of unneeded bulk.
> ==================================================================
> [58.095667] BUG: KASAN: use-after-free in usb_hcd_pci_remove+0xbc/0x168
> [58.102272] Read of size 8 at addr ffff002a0b6e8120 by task swapper/0/1
...
> [58.497758] ffff002a0b6e8200: fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> fb fb
> [58.504968]
> ==================================================================
>
> Fix by relocating the usb_put_hcd() call until after the hcd->driver->flags
> check.
>
> Signed-off-by: John Garry <john.garry@huawei.com>
>
> diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
> index 4dc443aaef5c..44a8d3644973 100644
> --- a/drivers/usb/core/hcd-pci.c
> +++ b/drivers/usb/core/hcd-pci.c
> @@ -346,9 +346,9 @@ void usb_hcd_pci_remove(struct pci_dev *dev)
> dev_set_drvdata(&dev->dev, NULL);
> up_read(&companions_rwsem);
> }
> - usb_put_hcd(hcd);
> if ((hcd->driver->flags & HCD_MASK) < HCD_USB3)
> pci_free_irq_vectors(dev);
> + usb_put_hcd(hcd);
It's not correct approach.
We need to copy flags to a temporary variable.
I will send a new patch soon to test, thanks!
> pci_disable_device(dev);
> }
> EXPORT_SYMBOL_GPL(usb_hcd_pci_remove);
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2020-08-14 18:13 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-13 15:29 [Report]: BUG: KASAN: use-after-free in usb_hcd_pci_remove John Garry
2020-08-13 18:28 ` Greg Kroah-Hartman
2020-08-14 7:26 ` John Garry
2020-08-14 17:18 ` John Garry
2020-08-14 18:07 ` Andy Shevchenko [this message]
2020-08-14 19:51 ` Alan Stern
[not found] ` <CAHp75VdMXd3LWLM5ooBsWGZnSXnJBW3R5gH9Cpux0EHmcxjTvQ@mail.gmail.com>
2020-08-15 1:50 ` Alan Stern
2020-08-16 8:33 ` Andy Shevchenko
2020-08-16 16:05 ` Alan Stern
2020-08-17 11:35 ` Andy Shevchenko
2020-08-18 8:41 ` John Garry
2020-08-18 9:43 ` Andy Shevchenko
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=20200814180720.GE1891694@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=john.garry@huawei.com \
--cc=linux-usb@vger.kernel.org \
/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).