* re: media: dvb-usb-v2/gl861: ensure USB message buffers DMA'able
@ 2018-07-02 12:58 Colin Ian King
2018-07-03 12:07 ` Akihiro TSUKADA
0 siblings, 1 reply; 4+ messages in thread
From: Colin Ian King @ 2018-07-02 12:58 UTC (permalink / raw)
To: Akihiro Tsukada, Mauro Carvalho Chehab, linux-media, Antti Palosaari
Cc: linux-kernel
Hi,
While running static analysis on linux-next with CoverityScan an issue
was detected with recent commit:
commit 86f65c218123c4e36fd855fbbc38147ffaf29974
Author: Akihiro Tsukada <tskd08@gmail.com>
Date: Sun Apr 8 13:21:38 2018 -0400
media: dvb-usb-v2/gl861: ensure USB message buffers DMA'able
The report is as follows:
46 }
assign_zero: Assigning: buf = NULL.
47 buf = NULL;
Condition rlen > 0, taking false branch.
48 if (rlen > 0) {
49 buf = kmalloc(rlen, GFP_KERNEL);
50 if (!buf)
51 return -ENOMEM;
52 }
53 usleep_range(1000, 2000); /* avoid I2C errors */
54
CID 1470241 (#1 of 1): Explicit null dereferenced (FORWARD_NULL).
var_deref_model: Passing null pointer buf to usb_control_msg, which
dereferences it.
55 ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0),
req, type,
56 value, index, buf, rlen, 2000);
The assignment of buf = NULL means a null buffer is passed down the usb
control message stack until it eventually gets dereferenced. This only
occurs when rlen <= 0. I was unsure how to fix this for the case when
rlen <= 0, so I am flagging this up as an issue that needs fixing.
Regards,
Colin
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: media: dvb-usb-v2/gl861: ensure USB message buffers DMA'able
2018-07-02 12:58 media: dvb-usb-v2/gl861: ensure USB message buffers DMA'able Colin Ian King
@ 2018-07-03 12:07 ` Akihiro TSUKADA
2018-07-25 13:57 ` Mauro Carvalho Chehab
0 siblings, 1 reply; 4+ messages in thread
From: Akihiro TSUKADA @ 2018-07-03 12:07 UTC (permalink / raw)
To: Colin Ian King, Mauro Carvalho Chehab, linux-media, Antti Palosaari
Cc: linux-kernel
Hi,
thanks for the report.
> 47 buf = NULL;
>
> Condition rlen > 0, taking false branch.
>
> 48 if (rlen > 0) {
> 49 buf = kmalloc(rlen, GFP_KERNEL);
> 50 if (!buf)
> 51 return -ENOMEM;
> 52 }
>
> 53 usleep_range(1000, 2000); /* avoid I2C errors */
> 54
> CID 1470241 (#1 of 1): Explicit null dereferenced (FORWARD_NULL).
> var_deref_model: Passing null pointer buf to usb_control_msg, which
> dereferences it.
>
> 55 ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0),
> req, type,
> 56 value, index, buf, rlen, 2000);
>
>
> The assignment of buf = NULL means a null buffer is passed down the usb
> control message stack until it eventually gets dereferenced. This only
> occurs when rlen <= 0. I was unsure how to fix this for the case when
> rlen <= 0, so I am flagging this up as an issue that needs fixing.
>
Since rlen is an u16, null pointer is passed only when rlen == 0,
so I think it is not a problem,
but I am OK to add a guard in order to make scan result clean.
regards,
Akihiro
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: media: dvb-usb-v2/gl861: ensure USB message buffers DMA'able
2018-07-03 12:07 ` Akihiro TSUKADA
@ 2018-07-25 13:57 ` Mauro Carvalho Chehab
2018-07-27 2:00 ` Akihiro TSUKADA
0 siblings, 1 reply; 4+ messages in thread
From: Mauro Carvalho Chehab @ 2018-07-25 13:57 UTC (permalink / raw)
To: Akihiro TSUKADA
Cc: Colin Ian King, linux-media, Antti Palosaari, linux-kernel, mika.batsman
Em Tue, 3 Jul 2018 21:07:07 +0900
Akihiro TSUKADA <tskd08@gmail.com> escreveu:
> Hi,
> thanks for the report.
>
> > 47 buf = NULL;
> >
> > Condition rlen > 0, taking false branch.
> >
> > 48 if (rlen > 0) {
> > 49 buf = kmalloc(rlen, GFP_KERNEL);
> > 50 if (!buf)
> > 51 return -ENOMEM;
> > 52 }
> >
> > 53 usleep_range(1000, 2000); /* avoid I2C errors */
> > 54
> > CID 1470241 (#1 of 1): Explicit null dereferenced (FORWARD_NULL).
> > var_deref_model: Passing null pointer buf to usb_control_msg, which
> > dereferences it.
> >
> > 55 ret = usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0),
> > req, type,
> > 56 value, index, buf, rlen, 2000);
> >
> >
> > The assignment of buf = NULL means a null buffer is passed down the usb
> > control message stack until it eventually gets dereferenced. This only
> > occurs when rlen <= 0. I was unsure how to fix this for the case when
> > rlen <= 0, so I am flagging this up as an issue that needs fixing.
> >
>
> Since rlen is an u16, null pointer is passed only when rlen == 0,
> so I think it is not a problem,
> but I am OK to add a guard in order to make scan result clean.
There was another patch proposed to fix this issue with does the
right thing when rlen == 0. I rebased it on the top of the current
tree:
https://git.linuxtv.org/media_tree.git/commit/?id=0b666e1c8120c0b17a8a68aaed58e22011f06ab3
That should cover both cases.
Thanks,
Mauro
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: media: dvb-usb-v2/gl861: ensure USB message buffers DMA'able
2018-07-25 13:57 ` Mauro Carvalho Chehab
@ 2018-07-27 2:00 ` Akihiro TSUKADA
0 siblings, 0 replies; 4+ messages in thread
From: Akihiro TSUKADA @ 2018-07-27 2:00 UTC (permalink / raw)
To: Mauro Carvalho Chehab
Cc: Colin Ian King, linux-media, Antti Palosaari, linux-kernel, mika.batsman
Hi,
On 2018年07月25日 22:57, Mauro Carvalho Chehab wrote:
...
> There was another patch proposed to fix this issue with does the
> right thing when rlen == 0. I rebased it on the top of the current
> tree:
> https://git.linuxtv.org/media_tree.git/commit/?id=0b666e1c8120c0b17a8a68aaed58e22011f06ab3
>
> That should cover both cases.
When wlen is checked to be <= 2 and
wbuf[0],wbuf[1] are already used in 'index','value',
why this patch copys wbuf and passes it again in usb_control_msg when wo==1 ?
(just to silence static analiyzers?)
Furthermore,
I am afraid that a static analyzer might warn on a possible
buffer overrun in usb_control_msg in the case of rbuf == NULL && rlen > 2,
since buf's length is passed as rlen but is actually wlen.
regards,
Akihiro
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-07-27 2:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-02 12:58 media: dvb-usb-v2/gl861: ensure USB message buffers DMA'able Colin Ian King
2018-07-03 12:07 ` Akihiro TSUKADA
2018-07-25 13:57 ` Mauro Carvalho Chehab
2018-07-27 2:00 ` Akihiro TSUKADA
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).