patch "usb: xhci: fix possible wild pointer" added to usb-linus
Subsystems (3)
This is a note to let you know that I've just added the patch titled
usb: xhci: fix possible wild pointer
to my usb git tree which can be found at
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git
in the usb-linus branch.
The patch will show up in the next release of the linux-next tree (usually sometime within the next 24 hours during the week.)
The patch will hopefully also be merged in Linus's tree for the next -rc kernel release.
If you have any questions about this process, please let me know.
Quoted 1 line
From
2b985467371a58ae44d76c7ba12b0951fee6ed98Mon Sep 17 00:00:00 2001
From: Lu Baolu <[email protected]>
Date: Tue, 3 Jan 2017 18:28:46 +0200
Subject: usb: xhci: fix possible wild pointer
handle_cmd_completion() frees a command structure which might be still referenced by xhci->current_cmd.
This might cause problem when xhci->current_cmd is accessed after that.
A real-life case could be like this. The host takes a very long time to respond to a command, and the command timer is fired at the same time when the command completion event arrives. The command completion handler frees xhci->current_cmd before the timer function can grab xhci->lock. Afterward, timer function grabs the lock and go ahead with checking and setting members of xhci->current_cmd.
--- drivers/usb/host/xhci-ring.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
drivers/usb/host/xhci-ring.c +11 -5
@@ -1267,14 +1267,18 @@ void xhci_handle_command_timeout(unsigned long data)bool second_timeout = false; xhci = (struct xhci_hcd *) data; -/* mark this command to be cancelled */ spin_lock_irqsave (&xhci->lock, flags); -if (xhci->current_cmd) { -if (xhci->current_cmd->status ==COMP_CMD_ABORT ) - second_timeout = true; - xhci->current_cmd->status =COMP_CMD_ABORT ; + +if (!xhci->current_cmd) { +spin_unlock_irqrestore (&xhci->lock, flags); +return ; } +/* mark this command to be cancelled */ +if (xhci->current_cmd->status ==COMP_CMD_ABORT ) + second_timeout = true; + xhci->current_cmd->status =COMP_CMD_ABORT ; +/* Make sure command ring is running before aborting it */ hw_ring_state =xhci_read_64 (xhci, &xhci->op_regs->cmd_ring); if ((xhci->cmd_ring_state & CMD_RING_STATE_RUNNING) &&
@@ -1422,6 +1426,8 @@ static void handle_cmd_completion(struct xhci_hcd *xhci, xhci->current_cmd =list_entry (cmd->cmd_list.next, struct xhci_command, cmd_list);mod_timer (&xhci->cmd_timer, jiffies +XHCI_CMD_DEFAULT_TIMEOUT ); + }else if (xhci->current_cmd == cmd) { + xhci->current_cmd =NULL ; } event_handled:
Signature · 1 line
2.11.0