From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751989AbdI2JNN (ORCPT ); Fri, 29 Sep 2017 05:13:13 -0400 Received: from regular1.263xmail.com ([211.150.99.141]:44788 "EHLO regular1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751490AbdI2JNL (ORCPT ); Fri, 29 Sep 2017 05:13:11 -0400 X-263anti-spam: KSV:0; X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-KSVirus-check: 0 X-ABS-CHECKED: 4 X-RL-SENDER: jeffy.chen@rock-chips.com X-FST-TO: linux-kernel@vger.kernel.org X-SENDER-IP: 103.29.142.67 X-LOGIN-NAME: jeffy.chen@rock-chips.com X-UNIQUE-TAG: <193376f548ace5bb51841cc9d20834d6> X-ATTACHMENT-NUM: 0 X-DNS-TYPE: 0 From: Jeffy Chen To: linux-kernel@vger.kernel.org Cc: Jeffy Chen , Greg Kroah-Hartman , linux-usb@vger.kernel.org, Mathias Nyman Subject: [PATCH] xhci: Cancel cmd_timer before cleanup the command queue in xhci_hc_died() Date: Fri, 29 Sep 2017 17:12:47 +0800 Message-Id: <20170929091247.28604-1-jeffy.chen@rock-chips.com> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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