From: Venu Byravarasu <vbyravarasu@nvidia.com>
To: "gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>
Cc: Alan Stern <stern@rowland.harvard.edu>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v1] usb: host: Fix possible kernel crash
Date: Wed, 11 Jul 2012 12:35:48 +0530 [thread overview]
Message-ID: <4FFD25CC.3050401@nvidia.com> (raw)
In-Reply-To: <20120710144554.GC15912@kroah.com>
On Tuesday 10 July 2012 08:15 PM, gregkh@linuxfoundation.org wrote:
> On Tue, Jul 10, 2012 at 09:56:39AM +0530, Venu Byravarasu wrote:
>> Thanks Alan for your comments.
>>
>> On Monday 09 July 2012 08:04 PM, Alan Stern wrote:
>>> On Mon, 9 Jul 2012, Venu Byravarasu wrote:
>>>
>>>> In functions itd_complete & sitd_complete, a pointer
>>>> by name stream may get dereferenced after freeing it, when
>>>> iso_stream_put is called with stream->refcount = 2.
>>> I don't understand the problem. Did you actually see this happen or is
>>> it only theoretical?
>> Yes it is a theoretical problem, as complained by Coverity.
>>
>>> /* for each uframe with a packet */
>>> for (uframe = 0; uframe < 8; uframe++) {
>>> @@ -1783,7 +1784,8 @@ itd_complete (
>>> dev->devpath, stream->bEndpointAddress & 0x0f,
>>> (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out");
>>> }
>>> - iso_stream_put (ehci, stream);
>>> + stream_ref_count = stream->refcount;
>>> + iso_stream_put(ehci, stream);
>>> This iso_stream_put removes the reference held by the URB. Before it
>>> is called, stream->refcount must be >= 3:
>>>
>>> refcount is set to 1 when the stream is created;
>>>
>>> each active URB holds a reference;
>>>
>>> each itd holds a reference.
>>>
>>> So after the call, the refcount value must be >= 2 and the stream could
>>> not have been deallocated.
>>>
>>>> done:
>>>> itd->urb = NULL;
>>>> @@ -1797,7 +1799,7 @@ done:
>>>> * Move it to a safe place until a new frame starts.
>>>> */
>>>> list_move(&itd->itd_list, &ehci->cached_itd_list);
>>>> - if (stream->refcount == 2) {
>>>> + if (stream_ref_count == 3) {
>>> Therefore this seems unnecessary.
>> As per the logic you explained above, this change is not needed.
>> However coverity was complaining as below:
>>
>> /kernel/drivers/usb/host/ehci-sched.c 1777 USE_AFTER_FREE
>> Dereferencing freed pointer "stream"
>>
>> Hence to pacify coverity, this change is done.
> Why are you trying to "pacify" coverity, when the tool is wrong in this
> case? Go poke the owners of that tool to get it to stop emitting this
> false warning. Don't paper over it in the kernel. Especially for a
> tool that none of us can run on our own.
>
> greg k-h
Thanks Greg for your comments.
In fact coverity team also mentioned this as one of the false positives.
Also as Alan mentioned that he'll be taking care of it in a different
way, will stop working on this patch.
Thanks,
Venu
next prev parent reply other threads:[~2012-07-11 7:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-09 10:46 [PATCH v1] usb: host: Fix possible kernel crash Venu Byravarasu
2012-07-09 14:34 ` Alan Stern
2012-07-10 4:26 ` Venu Byravarasu
2012-07-10 14:45 ` gregkh
2012-07-10 16:35 ` Scan Subscription
2012-07-11 7:03 ` Venu Byravarasu
2012-07-11 7:05 ` Venu Byravarasu [this message]
2012-07-10 15:09 ` Alan Stern
2012-07-11 7:04 ` Venu Byravarasu
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=4FFD25CC.3050401@nvidia.com \
--to=vbyravarasu@nvidia.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=stern@rowland.harvard.edu \
/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).