From: Florian Mickler <florian@mickler.org>
To: Dan Carpenter <error27@gmail.com>
Cc: Florian Mickler <florian@mickler.org>,
linux-kernel@vger.kernel.org, Tino Keitel <tino.keitel@tikei.de>,
mchehab@infradead.org
Subject: Re: USB related "unable to handle kernel paging request" in 3.0.0-rc7
Date: Tue, 2 Aug 2011 12:40:28 +0200 [thread overview]
Message-ID: <20110802124028.3b8dcd5a@schatten.dmk.lab> (raw)
In-Reply-To: <20110802115145.25b6a445@schatten.dmk.lab>
On Tue, 2 Aug 2011 11:51:45 +0200
Florian Mickler <florian@mickler.org> wrote:
> On Tue, 2 Aug 2011 11:54:47 +0300
> Dan Carpenter <error27@gmail.com> wrote:
>
> > Looking at this, I noticed a memory corruption bug introduce in:
> > ab22cbda6651d "[media] vp7045: get rid of on-stack dma buffers"
> >
> > vp7045_properties.size_of_priv is sizeof(u8 *) so in vp7045_usb_probe()
> > the d->priv buffer gets allocated twice. Once in:
> > dvb_usb_device_init()
> > -> dvb_usb_init()
> >
> > And once explicitly to a larger buffer later on in the function with
> > a kmalloc().
> >
> > So the two places that use the buffer will probably race and cause
> > memory corruption.
Btw, what two places use the buffer? I only see vp7045_usb_op. Did you
mean s/use/free/ or did I overlook it?
Patch below.
> >
> > regards,
> > dan carpenter
>
> Damn. That (u8*)sized priv buffer should only hold a pointer to the
> transfer buffer allocated in the prope routine. But I botched that.
> I will send a fixup in a minute.
>
> Regards,
> Flo
This should fix it.
[git am -c ]
--------->8-------->8---------->8------------>8---------------------------
commit 2c505d4867be9f3605c20ed505ec62d2096a05b1
Author: Florian Mickler <florian@mickler.org>
Date: Tue Aug 2 12:18:55 2011 +0200
[media] vp7045: fix double free and mem leak
The vp7045 priv data should be a pointer to a buffer.
Make it so.
This was introduced in commit ab22cbda6651db25 ([media] vp7045: get rid of on-stack
dma buffers).
CC: stable@kernel.org
Reported-by: Dan Carpenter <error27@gmail.com>
Signed-off-by: Florian Mickler <florian@mickler.org>
diff --git a/drivers/media/dvb/dvb-usb/vp7045.c b/drivers/media/dvb/dvb-usb/vp7045.c
index 3db89e3..8dd348b 100644
--- a/drivers/media/dvb/dvb-usb/vp7045.c
+++ b/drivers/media/dvb/dvb-usb/vp7045.c
@@ -28,7 +28,8 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
int vp7045_usb_op(struct dvb_usb_device *d, u8 cmd, u8 *out, int outlen, u8 *in, int inlen, int msec)
{
int ret = 0;
- u8 *buf = d->priv;
+ u8 **bufp = d->priv;
+ u8 *buf = *bufp
buf[0] = cmd;
@@ -224,14 +225,16 @@ static struct dvb_usb_device_properties vp7045_properties;
static int vp7045_usb_probe(struct usb_interface *intf,
const struct usb_device_id *id)
{
+ u8 **bufp;
struct dvb_usb_device *d;
int ret = dvb_usb_device_init(intf, &vp7045_properties,
THIS_MODULE, &d, adapter_nr);
if (ret)
return ret;
- d->priv = kmalloc(20, GFP_KERNEL);
- if (!d->priv) {
+ bufp = d->priv;
+ *bufp = kmalloc(20, GFP_KERNEL);
+ if (!*bufp) {
dvb_usb_device_exit(intf);
return -ENOMEM;
}
@@ -241,8 +244,10 @@ static int vp7045_usb_probe(struct usb_interface *intf,
static void vp7045_usb_disconnect(struct usb_interface *intf)
{
+ u8 **bufp;
struct dvb_usb_device *d = usb_get_intfdata(intf);
- kfree(d->priv);
+ bufp = d->priv;
+ kfree(*bufp);
dvb_usb_device_exit(intf);
}
next prev parent reply other threads:[~2011-08-02 10:40 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-22 19:27 USB related "unable to handle kernel paging request" in 3.0.0-rc7 Tino Keitel
2011-07-25 19:47 ` Maciej Rutecki
2011-08-02 8:54 ` Dan Carpenter
2011-08-02 9:51 ` Florian Mickler
2011-08-02 10:40 ` Florian Mickler [this message]
2011-08-02 11:10 ` Florian Mickler
2011-08-02 11:51 ` Florian Mickler
2011-08-02 11:56 ` Dan Carpenter
2011-08-02 11:35 ` Dan Carpenter
2011-08-02 11:40 ` Dan Carpenter
2011-08-02 12:02 ` Florian Mickler
2011-08-02 12:29 ` [PATCH] [media] vp7045: fix buffer setup Florian Mickler
2011-08-03 19:02 ` Tino Keitel
2011-08-09 20:08 ` Tino Keitel
2011-08-10 9:46 ` Florian Mickler
2011-08-10 10:05 ` Florian Mickler
2011-08-19 16:35 ` Florian Mickler
2011-08-24 16:26 ` Tino Keitel
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=20110802124028.3b8dcd5a@schatten.dmk.lab \
--to=florian@mickler.org \
--cc=error27@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mchehab@infradead.org \
--cc=tino.keitel@tikei.de \
/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