Commit 35477ad4 authored by Lu Baolu's avatar Lu Baolu Committed by Ben Hutchings

usb: xhci: fix possible wild pointer

commit 2b985467 upstream.

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.
Signed-off-by: default avatarLu Baolu <baolu.lu@linux.intel.com>
Signed-off-by: default avatarMathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
[bwh: Backported to 3.16: adjust context]
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent 8d0258ac
...@@ -1292,13 +1292,16 @@ void xhci_handle_command_timeout(unsigned long data) ...@@ -1292,13 +1292,16 @@ void xhci_handle_command_timeout(unsigned long data)
struct xhci_command *cur_cmd = NULL; struct xhci_command *cur_cmd = NULL;
xhci = (struct xhci_hcd *) data; xhci = (struct xhci_hcd *) data;
/* mark this command to be cancelled */
spin_lock_irqsave(&xhci->lock, flags); spin_lock_irqsave(&xhci->lock, flags);
if (xhci->current_cmd) {
cur_cmd = xhci->current_cmd; if (!xhci->current_cmd) {
cur_cmd->status = COMP_CMD_ABORT; spin_unlock_irqrestore(&xhci->lock, flags);
return;
} }
/* mark this command to be cancelled */
cur_cmd = xhci->current_cmd;
cur_cmd->status = COMP_CMD_ABORT;
/* Make sure command ring is running before aborting it */ /* Make sure command ring is running before aborting it */
hw_ring_state = xhci_read_64(xhci, &xhci->op_regs->cmd_ring); hw_ring_state = xhci_read_64(xhci, &xhci->op_regs->cmd_ring);
...@@ -1440,6 +1443,8 @@ static void handle_cmd_completion(struct xhci_hcd *xhci, ...@@ -1440,6 +1443,8 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
xhci->current_cmd = list_entry(cmd->cmd_list.next, xhci->current_cmd = list_entry(cmd->cmd_list.next,
struct xhci_command, cmd_list); struct xhci_command, cmd_list);
mod_timer(&xhci->cmd_timer, jiffies + XHCI_CMD_DEFAULT_TIMEOUT); mod_timer(&xhci->cmd_timer, jiffies + XHCI_CMD_DEFAULT_TIMEOUT);
} else if (xhci->current_cmd == cmd) {
xhci->current_cmd = NULL;
} }
event_handled: event_handled:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment