* [PATCH] xhci: Cancel cmd_timer before cleanup the command queue in xhci_hc_died()
@ 2017-09-29 9:12 Jeffy Chen
2017-11-01 16:03 ` Greg Kroah-Hartman
0 siblings, 1 reply; 4+ messages in thread
From: Jeffy Chen @ 2017-09-29 9:12 UTC (permalink / raw)
To: linux-kernel; +Cc: Jeffy Chen, Greg Kroah-Hartman, linux-usb, Mathias Nyman
When the cmd_timer fired, it would try to access the command struct.
So cancel it before cleanup the command queue in xhci_hc_died(), to
avoid use-after-free reported by KASAN:
[ 176.952537] BUG: KASAN: use-after-free in xhci_handle_command_timeout+0x68/0x224
[ 176.960846] Write of size 4 at addr ffffffc0cbb01608 by task kworker/3:3/1680
...
[ 177.180644] Freed by task 0:
[ 177.183882] kasan_slab_free+0x90/0x15c
[ 177.188194] kfree+0x114/0x28c
[ 177.191630] xhci_cleanup_command_queue+0xc8/0xf8
[ 177.196916] xhci_hc_died+0x84/0x358
Fixes: d9f11ba9f107 ("xhci: Rework how we handle unresponsive or hoptlug removed hosts")
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
---
drivers/usb/host/xhci-ring.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index a9443651ce0f..69ac3deffb7b 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -914,6 +914,7 @@ void xhci_hc_died(struct xhci_hcd *xhci)
xhci_err(xhci, "xHCI host controller not responding, assume dead\n");
xhci->xhc_state |= XHCI_STATE_DYING;
+ cancel_delayed_work_sync(&xhci->cmd_timer);
xhci_cleanup_command_queue(xhci);
/* return any pending urbs, remove may be waiting for them */
--
2.11.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] xhci: Cancel cmd_timer before cleanup the command queue in xhci_hc_died()
2017-09-29 9:12 [PATCH] xhci: Cancel cmd_timer before cleanup the command queue in xhci_hc_died() Jeffy Chen
@ 2017-11-01 16:03 ` Greg Kroah-Hartman
2017-11-01 16:28 ` Mathias Nyman
0 siblings, 1 reply; 4+ messages in thread
From: Greg Kroah-Hartman @ 2017-11-01 16:03 UTC (permalink / raw)
To: Jeffy Chen; +Cc: linux-kernel, linux-usb, Mathias Nyman
On Fri, Sep 29, 2017 at 05:12:47PM +0800, Jeffy Chen wrote:
> When the cmd_timer fired, it would try to access the command struct.
> So cancel it before cleanup the command queue in xhci_hc_died(), to
> avoid use-after-free reported by KASAN:
> [ 176.952537] BUG: KASAN: use-after-free in xhci_handle_command_timeout+0x68/0x224
> [ 176.960846] Write of size 4 at addr ffffffc0cbb01608 by task kworker/3:3/1680
> ...
> [ 177.180644] Freed by task 0:
> [ 177.183882] kasan_slab_free+0x90/0x15c
> [ 177.188194] kfree+0x114/0x28c
> [ 177.191630] xhci_cleanup_command_queue+0xc8/0xf8
> [ 177.196916] xhci_hc_died+0x84/0x358
>
> Fixes: d9f11ba9f107 ("xhci: Rework how we handle unresponsive or hoptlug removed hosts")
> Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
> ---
Mathias, did you miss this one? Want me to queue it up?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] xhci: Cancel cmd_timer before cleanup the command queue in xhci_hc_died()
2017-11-01 16:03 ` Greg Kroah-Hartman
@ 2017-11-01 16:28 ` Mathias Nyman
2017-11-01 16:39 ` Greg Kroah-Hartman
0 siblings, 1 reply; 4+ messages in thread
From: Mathias Nyman @ 2017-11-01 16:28 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jeffy Chen; +Cc: linux-kernel, linux-usb
On 01.11.2017 18:03, Greg Kroah-Hartman wrote:
> On Fri, Sep 29, 2017 at 05:12:47PM +0800, Jeffy Chen wrote:
>> When the cmd_timer fired, it would try to access the command struct.
>> So cancel it before cleanup the command queue in xhci_hc_died(), to
>> avoid use-after-free reported by KASAN:
>> [ 176.952537] BUG: KASAN: use-after-free in xhci_handle_command_timeout+0x68/0x224
>> [ 176.960846] Write of size 4 at addr ffffffc0cbb01608 by task kworker/3:3/1680
>> ...
>> [ 177.180644] Freed by task 0:
>> [ 177.183882] kasan_slab_free+0x90/0x15c
>> [ 177.188194] kfree+0x114/0x28c
>> [ 177.191630] xhci_cleanup_command_queue+0xc8/0xf8
>> [ 177.196916] xhci_hc_died+0x84/0x358
>>
>> Fixes: d9f11ba9f107 ("xhci: Rework how we handle unresponsive or hoptlug removed hosts")
>> Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
>> ---
>
> Mathias, did you miss this one? Want me to queue it up?
>
There is a v2 of that patch already upstreamed.
d1aad52 xhci: Cleanup current_cmd in xhci_cleanup_command_queue()
https://marc.info/?l=linux-usb&m=150668331802206&w=2
A bit confusing as patch subject changed as well in v2
-Mathias
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] xhci: Cancel cmd_timer before cleanup the command queue in xhci_hc_died()
2017-11-01 16:28 ` Mathias Nyman
@ 2017-11-01 16:39 ` Greg Kroah-Hartman
0 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2017-11-01 16:39 UTC (permalink / raw)
To: Mathias Nyman; +Cc: Jeffy Chen, linux-kernel, linux-usb
On Wed, Nov 01, 2017 at 06:28:01PM +0200, Mathias Nyman wrote:
> On 01.11.2017 18:03, Greg Kroah-Hartman wrote:
> > On Fri, Sep 29, 2017 at 05:12:47PM +0800, Jeffy Chen wrote:
> > > When the cmd_timer fired, it would try to access the command struct.
> > > So cancel it before cleanup the command queue in xhci_hc_died(), to
> > > avoid use-after-free reported by KASAN:
> > > [ 176.952537] BUG: KASAN: use-after-free in xhci_handle_command_timeout+0x68/0x224
> > > [ 176.960846] Write of size 4 at addr ffffffc0cbb01608 by task kworker/3:3/1680
> > > ...
> > > [ 177.180644] Freed by task 0:
> > > [ 177.183882] kasan_slab_free+0x90/0x15c
> > > [ 177.188194] kfree+0x114/0x28c
> > > [ 177.191630] xhci_cleanup_command_queue+0xc8/0xf8
> > > [ 177.196916] xhci_hc_died+0x84/0x358
> > >
> > > Fixes: d9f11ba9f107 ("xhci: Rework how we handle unresponsive or hoptlug removed hosts")
> > > Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
> > > ---
> >
> > Mathias, did you miss this one? Want me to queue it up?
> >
>
> There is a v2 of that patch already upstreamed.
>
> d1aad52 xhci: Cleanup current_cmd in xhci_cleanup_command_queue()
>
> https://marc.info/?l=linux-usb&m=150668331802206&w=2
>
> A bit confusing as patch subject changed as well in v2
Ah, thanks, missed that.
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-11-01 16:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-29 9:12 [PATCH] xhci: Cancel cmd_timer before cleanup the command queue in xhci_hc_died() Jeffy Chen
2017-11-01 16:03 ` Greg Kroah-Hartman
2017-11-01 16:28 ` Mathias Nyman
2017-11-01 16:39 ` Greg Kroah-Hartman
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.