stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lu Baolu <baolu.lu@linux.intel.com>
To: Mathias Nyman <mathias.nyman@linux.intel.com>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH 1/1] usb: xhci: fix possible wild pointer
Date: Mon, 5 Dec 2016 17:07:14 +0800	[thread overview]
Message-ID: <58452E42.9010504@linux.intel.com> (raw)
In-Reply-To: <58417993.4040307@linux.intel.com>

Hi,

On 12/02/2016 09:39 PM, Mathias Nyman wrote:
> On 02.12.2016 04:29, Lu Baolu wrote:
>> 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.
>>
>> Cc: <stable@vger.kernel.org> # v3.16+
>> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
>> ---
>>   drivers/usb/host/xhci-ring.c | 16 +++++++++++-----
>>   1 file changed, 11 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
>> index bdf6b13..13e05f6 100644
>> --- a/drivers/usb/host/xhci-ring.c
>> +++ b/drivers/usb/host/xhci-ring.c
>> @@ -1267,14 +1267,16 @@ 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;
>>       }
>>
>> +    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 +1424,10 @@ 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;
>> +    } else {
>> +        xhci_warn(xhci, "WARN current_cmd doesn't match command\n");
>>       }
>>
>>   event_handled:
>>
>
> Thanks,
>
> I might do some tweaking to (or remove)  the warn message when applying if
> that is ok

Sure.

>
> -Mathias
>

Best regards,
Lu Baolu

      reply	other threads:[~2016-12-05  9:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-02  2:29 [PATCH 1/1] usb: xhci: fix possible wild pointer Lu Baolu
2016-12-02  4:18 ` Baolin Wang
2016-12-02  4:40   ` Lu Baolu
2016-12-02  4:48     ` Baolin Wang
2016-12-02 13:39 ` Mathias Nyman
2016-12-05  9:07   ` Lu Baolu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=58452E42.9010504@linux.intel.com \
    --to=baolu.lu@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@linux.intel.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).