* [PATCH v3] usb:xhci fix panic in xhci_free_virt_devices_depth_first
@ 2017-11-07 2:01 Yu Chen
2017-11-07 14:36 ` Mathias Nyman
2017-11-07 15:49 ` Guenter Roeck
0 siblings, 2 replies; 3+ messages in thread
From: Yu Chen @ 2017-11-07 2:01 UTC (permalink / raw)
To: mathias.nyman, gregkh, linux-usb, linux-kernel
Cc: fanning4, lirui39, yangdi10, wangbinghui, groeck, john.stultz
From: Yu Chen <chenyu56@huawei.com>
Check vdev->real_port 0 to avoid panic
[ 9.261347] [<ffffff800884a390>] xhci_free_virt_devices_depth_first+0x58/0x108
[ 9.261352] [<ffffff800884a814>] xhci_mem_cleanup+0x1bc/0x570
[ 9.261355] [<ffffff8008842de8>] xhci_stop+0x140/0x1c8
[ 9.261365] [<ffffff80087ed304>] usb_remove_hcd+0xfc/0x1d0
[ 9.261369] [<ffffff80088551c4>] xhci_plat_remove+0x6c/0xa8
[ 9.261377] [<ffffff80086e928c>] platform_drv_remove+0x2c/0x70
[ 9.261384] [<ffffff80086e6ea0>] __device_release_driver+0x80/0x108
[ 9.261387] [<ffffff80086e7a1c>] device_release_driver+0x2c/0x40
[ 9.261392] [<ffffff80086e5f28>] bus_remove_device+0xe0/0x120
[ 9.261396] [<ffffff80086e2e34>] device_del+0x114/0x210
[ 9.261399] [<ffffff80086e9e00>] platform_device_del+0x30/0xa0
[ 9.261403] [<ffffff8008810bdc>] dwc3_otg_work+0x204/0x488
[ 9.261407] [<ffffff80088133fc>] event_work+0x304/0x5b8
[ 9.261414] [<ffffff80080e31b0>] process_one_work+0x148/0x490
[ 9.261417] [<ffffff80080e3548>] worker_thread+0x50/0x4a0
[ 9.261421] [<ffffff80080e9ea0>] kthread+0xe8/0x100
[ 9.261427] [<ffffff8008083680>] ret_from_fork+0x10/0x50
The problem can occur if xhci_plat_remove() is called shortly after
xhci_plat_probe(). While xhci_free_virt_devices_depth_first been
called before the device has been setup and get real_port initialized.
The problem occurred on Hikey960 and was reproduced by Guenter Roeck
on Kevin with chromeos-4.4.
Cc: Guenter Roeck <groeck@google.com>
Signed-off-by: Fan Ning <fanning4@hisilicon.com>
Signed-off-by: Li Rui <lirui39@hisilicon.com>
Signed-off-by: yangdi <yangdi10@hisilicon.com>
Signed-off-by: Yu Chen <chenyu56@huawei.com>
---
drivers/usb/host/xhci-mem.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 2a82c927ded2..97f30eb7dac0 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -947,6 +947,12 @@ void xhci_free_virt_devices_depth_first(struct xhci_hcd *xhci, int slot_id)
if (!vdev)
return;
+ if (vdev->real_port == 0 ||
+ vdev->real_port > HCS_MAX_PORTS(xhci->hcs_params1)) {
+ xhci_dbg(xhci, "Bad vdev->real_port.\n");
+ goto out;
+ }
+
tt_list_head = &(xhci->rh_bw[vdev->real_port - 1].tts);
list_for_each_entry_safe(tt_info, next, tt_list_head, tt_list) {
/* is this a hub device that added a tt_info to the tts list */
@@ -960,6 +966,7 @@ void xhci_free_virt_devices_depth_first(struct xhci_hcd *xhci, int slot_id)
}
}
}
+out:
/* we are now at a leaf device */
xhci_free_virt_device(xhci, slot_id);
}
--
2.15.0-rc2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] usb:xhci fix panic in xhci_free_virt_devices_depth_first
2017-11-07 2:01 [PATCH v3] usb:xhci fix panic in xhci_free_virt_devices_depth_first Yu Chen
@ 2017-11-07 14:36 ` Mathias Nyman
2017-11-07 15:49 ` Guenter Roeck
1 sibling, 0 replies; 3+ messages in thread
From: Mathias Nyman @ 2017-11-07 14:36 UTC (permalink / raw)
To: Yu Chen, mathias.nyman, gregkh, linux-usb, linux-kernel
Cc: fanning4, lirui39, yangdi10, wangbinghui, groeck, john.stultz
On 07.11.2017 04:01, Yu Chen wrote:
> From: Yu Chen <chenyu56@huawei.com>
>
> Check vdev->real_port 0 to avoid panic
> [ 9.261347] [<ffffff800884a390>] xhci_free_virt_devices_depth_first+0x58/0x108
> [ 9.261352] [<ffffff800884a814>] xhci_mem_cleanup+0x1bc/0x570
> [ 9.261355] [<ffffff8008842de8>] xhci_stop+0x140/0x1c8
> [ 9.261365] [<ffffff80087ed304>] usb_remove_hcd+0xfc/0x1d0
> [ 9.261369] [<ffffff80088551c4>] xhci_plat_remove+0x6c/0xa8
> [ 9.261377] [<ffffff80086e928c>] platform_drv_remove+0x2c/0x70
> [ 9.261384] [<ffffff80086e6ea0>] __device_release_driver+0x80/0x108
> [ 9.261387] [<ffffff80086e7a1c>] device_release_driver+0x2c/0x40
> [ 9.261392] [<ffffff80086e5f28>] bus_remove_device+0xe0/0x120
> [ 9.261396] [<ffffff80086e2e34>] device_del+0x114/0x210
> [ 9.261399] [<ffffff80086e9e00>] platform_device_del+0x30/0xa0
> [ 9.261403] [<ffffff8008810bdc>] dwc3_otg_work+0x204/0x488
> [ 9.261407] [<ffffff80088133fc>] event_work+0x304/0x5b8
> [ 9.261414] [<ffffff80080e31b0>] process_one_work+0x148/0x490
> [ 9.261417] [<ffffff80080e3548>] worker_thread+0x50/0x4a0
> [ 9.261421] [<ffffff80080e9ea0>] kthread+0xe8/0x100
> [ 9.261427] [<ffffff8008083680>] ret_from_fork+0x10/0x50
>
> The problem can occur if xhci_plat_remove() is called shortly after
> xhci_plat_probe(). While xhci_free_virt_devices_depth_first been
> called before the device has been setup and get real_port initialized.
> The problem occurred on Hikey960 and was reproduced by Guenter Roeck
> on Kevin with chromeos-4.4.
>
> Cc: Guenter Roeck <groeck@google.com>
> Signed-off-by: Fan Ning <fanning4@hisilicon.com>
> Signed-off-by: Li Rui <lirui39@hisilicon.com>
> Signed-off-by: yangdi <yangdi10@hisilicon.com>
> Signed-off-by: Yu Chen <chenyu56@huawei.com>
>
Thanks, adding to queue, and adding stable 4.10+ tag as well
-Mathias
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] usb:xhci fix panic in xhci_free_virt_devices_depth_first
2017-11-07 2:01 [PATCH v3] usb:xhci fix panic in xhci_free_virt_devices_depth_first Yu Chen
2017-11-07 14:36 ` Mathias Nyman
@ 2017-11-07 15:49 ` Guenter Roeck
1 sibling, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2017-11-07 15:49 UTC (permalink / raw)
To: Yu Chen
Cc: mathias.nyman, Greg Kroah-Hartman, linux-usb, linux-kernel,
fanning4, lirui39, yangdi10, wangbinghui, John Stultz
On Mon, Nov 6, 2017 at 6:01 PM, Yu Chen <chenyu56@huawei.com> wrote:
> From: Yu Chen <chenyu56@huawei.com>
>
> Check vdev->real_port 0 to avoid panic
> [ 9.261347] [<ffffff800884a390>] xhci_free_virt_devices_depth_first+0x58/0x108
> [ 9.261352] [<ffffff800884a814>] xhci_mem_cleanup+0x1bc/0x570
> [ 9.261355] [<ffffff8008842de8>] xhci_stop+0x140/0x1c8
> [ 9.261365] [<ffffff80087ed304>] usb_remove_hcd+0xfc/0x1d0
> [ 9.261369] [<ffffff80088551c4>] xhci_plat_remove+0x6c/0xa8
> [ 9.261377] [<ffffff80086e928c>] platform_drv_remove+0x2c/0x70
> [ 9.261384] [<ffffff80086e6ea0>] __device_release_driver+0x80/0x108
> [ 9.261387] [<ffffff80086e7a1c>] device_release_driver+0x2c/0x40
> [ 9.261392] [<ffffff80086e5f28>] bus_remove_device+0xe0/0x120
> [ 9.261396] [<ffffff80086e2e34>] device_del+0x114/0x210
> [ 9.261399] [<ffffff80086e9e00>] platform_device_del+0x30/0xa0
> [ 9.261403] [<ffffff8008810bdc>] dwc3_otg_work+0x204/0x488
> [ 9.261407] [<ffffff80088133fc>] event_work+0x304/0x5b8
> [ 9.261414] [<ffffff80080e31b0>] process_one_work+0x148/0x490
> [ 9.261417] [<ffffff80080e3548>] worker_thread+0x50/0x4a0
> [ 9.261421] [<ffffff80080e9ea0>] kthread+0xe8/0x100
> [ 9.261427] [<ffffff8008083680>] ret_from_fork+0x10/0x50
>
> The problem can occur if xhci_plat_remove() is called shortly after
> xhci_plat_probe(). While xhci_free_virt_devices_depth_first been
> called before the device has been setup and get real_port initialized.
> The problem occurred on Hikey960 and was reproduced by Guenter Roeck
> on Kevin with chromeos-4.4.
>
> Cc: Guenter Roeck <groeck@google.com>
> Signed-off-by: Fan Ning <fanning4@hisilicon.com>
> Signed-off-by: Li Rui <lirui39@hisilicon.com>
> Signed-off-by: yangdi <yangdi10@hisilicon.com>
> Signed-off-by: Yu Chen <chenyu56@huawei.com>
>
Thanks a lot for tracking down and fixing the problem!
Reviewed-by: Guenter Roeck <groeck@chromium.org>
I'll also give this test time today, just to make sure that there are
no other problems lurking around.
Guenter
> ---
> drivers/usb/host/xhci-mem.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
> index 2a82c927ded2..97f30eb7dac0 100644
> --- a/drivers/usb/host/xhci-mem.c
> +++ b/drivers/usb/host/xhci-mem.c
> @@ -947,6 +947,12 @@ void xhci_free_virt_devices_depth_first(struct xhci_hcd *xhci, int slot_id)
> if (!vdev)
> return;
>
> + if (vdev->real_port == 0 ||
> + vdev->real_port > HCS_MAX_PORTS(xhci->hcs_params1)) {
> + xhci_dbg(xhci, "Bad vdev->real_port.\n");
> + goto out;
> + }
> +
> tt_list_head = &(xhci->rh_bw[vdev->real_port - 1].tts);
> list_for_each_entry_safe(tt_info, next, tt_list_head, tt_list) {
> /* is this a hub device that added a tt_info to the tts list */
> @@ -960,6 +966,7 @@ void xhci_free_virt_devices_depth_first(struct xhci_hcd *xhci, int slot_id)
> }
> }
> }
> +out:
> /* we are now at a leaf device */
> xhci_free_virt_device(xhci, slot_id);
> }
> --
> 2.15.0-rc2
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-11-07 15:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-07 2:01 [PATCH v3] usb:xhci fix panic in xhci_free_virt_devices_depth_first Yu Chen
2017-11-07 14:36 ` Mathias Nyman
2017-11-07 15:49 ` Guenter Roeck
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).