From: Sean Young <sean@mess.org>
To: nil Yi <teroincn@gmail.com>
Cc: crope@iki.fi, linux-media@vger.kernel.org
Subject: Re: [BUG]: drivers: media: dvb-frontends: rtl2832_sdr.c: a dangling pointer may cause double free
Date: Sun, 1 Aug 2021 15:41:50 +0100 [thread overview]
Message-ID: <20210801144150.GA17214@gofer.mess.org> (raw)
In-Reply-To: <CANTwqXCapbBTXEx1ow9QBw_h0mqCq_myRvmTN=2KpsEEBBJFKg@mail.gmail.com>
Hi,
On Sun, Aug 01, 2021 at 03:08:16PM +0800, nil Yi wrote:
> Hi,
> I found there is a dangling pointer in rtl2832_sdr_alloc_urbs which
> may cause double free in v5.14-rc3
>
> in rtl2832_sdr_alloc_urbs:
>
> 379: for (j = 0; j < i; j++)
> 380: usb_free_urb(dev->urb_list[j]);
> it frees all the urbs but forgets to set the dev->urbs_initialized to
> zero, which will be used in function rtl2832_sdr_free_urbs:
>
> 357: for (i = dev->urbs_initialized - 1; i >= 0; i--) {
> 358: if (dev->urb_list[i]) {
> 359: dev_dbg(&pdev->dev, "free urb=%d\n", i);
> 360: /* free the URBs */
> 361: usb_free_urb(dev->urb_list[i]);
> 362: }
> 363: }
> 364: dev->urbs_initialized = 0;
>
>
> I'm not sure whether this double free would be triggered or not,
> similar issue happened in commit b7f870510384 <media: tm6000: double
> free if usb disconnect while streaming>
>
> Any feedback would be appreciated, thanks :)
I am not quite sure how this bug could be triggered, since this would involve
rtl2832_sdr_start_streaming() being called and then failing, and then
rtl2832_sdr_stop_streaming() being called even though start failed (I don't
think that happens).
Note that the code around this is pretty ugly; it might be nicer to remove
urbs_initialized and simply rely on the fact the the urb_list[i] entry
is non-null if it needs to be freed. That would be a great patch. :-)
For discussion it is best if you post a patch and then we can discuss the
patch itself rather than "is there a possible way this could go wrong".
Sean
prev parent reply other threads:[~2021-08-01 14:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-01 7:08 [BUG]: drivers: media: dvb-frontends: rtl2832_sdr.c: a dangling pointer may cause double free nil Yi
2021-08-01 14:41 ` Sean Young [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=20210801144150.GA17214@gofer.mess.org \
--to=sean@mess.org \
--cc=crope@iki.fi \
--cc=linux-media@vger.kernel.org \
--cc=teroincn@gmail.com \
/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