* [PATCH 4/14] drivers/media/v4l2-core/videobuf2-core.c: fix error return code
@ 2012-09-06 15:23 Peter Senna Tschudin
2012-10-06 11:17 ` Mauro Carvalho Chehab
0 siblings, 1 reply; 7+ messages in thread
From: Peter Senna Tschudin @ 2012-09-06 15:23 UTC (permalink / raw)
To: Mauro Carvalho Chehab
Cc: kernel-janitors, Julia.Lawall, linux-media, linux-kernel
From: Peter Senna Tschudin <peter.senna@gmail.com>
Convert a nonnegative error return code to a negative one, as returned
elsewhere in the function.
A simplified version of the semantic match that finds this problem is as
follows: (http://coccinelle.lip6.fr/)
// <smpl>
(
if@p1 (\(ret < 0\|ret != 0\))
{ ... return ret; }
|
ret@p1 = 0
)
... when != ret = e1
when != &ret
*if(...)
{
... when != ret = e2
when forall
return ret;
}
// </smpl>
Signed-off-by: Peter Senna Tschudin <peter.senna@gmail.com>
---
drivers/media/v4l2-core/videobuf2-core.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
index 4da3df6..f6bc240 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1876,8 +1876,10 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
*/
for (i = 0; i < q->num_buffers; i++) {
fileio->bufs[i].vaddr = vb2_plane_vaddr(q->bufs[i], 0);
- if (fileio->bufs[i].vaddr = NULL)
+ if (fileio->bufs[i].vaddr = NULL) {
+ ret = -EFAULT;
goto err_reqbufs;
+ }
fileio->bufs[i].size = vb2_plane_size(q->bufs[i], 0);
}
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 4/14] drivers/media/v4l2-core/videobuf2-core.c: fix error return code
2012-09-06 15:23 [PATCH 4/14] drivers/media/v4l2-core/videobuf2-core.c: fix error return code Peter Senna Tschudin
@ 2012-10-06 11:17 ` Mauro Carvalho Chehab
2012-10-10 16:47 ` Peter Senna Tschudin
0 siblings, 1 reply; 7+ messages in thread
From: Mauro Carvalho Chehab @ 2012-10-06 11:17 UTC (permalink / raw)
To: Peter Senna Tschudin
Cc: kernel-janitors, Julia.Lawall, linux-media, linux-kernel
Em Thu, 6 Sep 2012 17:23:57 +0200
Peter Senna Tschudin <peter.senna@gmail.com> escreveu:
> From: Peter Senna Tschudin <peter.senna@gmail.com>
>
> Convert a nonnegative error return code to a negative one, as returned
> elsewhere in the function.
>
> A simplified version of the semantic match that finds this problem is as
> follows: (http://coccinelle.lip6.fr/)
>
> // <smpl>
> (
> if@p1 (\(ret < 0\|ret != 0\))
> { ... return ret; }
> |
> ret@p1 = 0
> )
> ... when != ret = e1
> when != &ret
> *if(...)
> {
> ... when != ret = e2
> when forall
> return ret;
> }
>
> // </smpl>
>
> Signed-off-by: Peter Senna Tschudin <peter.senna@gmail.com>
>
> ---
> drivers/media/v4l2-core/videobuf2-core.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
> index 4da3df6..f6bc240 100644
> --- a/drivers/media/v4l2-core/videobuf2-core.c
> +++ b/drivers/media/v4l2-core/videobuf2-core.c
> @@ -1876,8 +1876,10 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
> */
> for (i = 0; i < q->num_buffers; i++) {
> fileio->bufs[i].vaddr = vb2_plane_vaddr(q->bufs[i], 0);
> - if (fileio->bufs[i].vaddr = NULL)
> + if (fileio->bufs[i].vaddr = NULL) {
> + ret = -EFAULT;
> goto err_reqbufs;
> + }
Had you test this patch? I suspect it breaks the driver, as there are failures under
streaming handling that are acceptable, as it may indicate that userspace was not
able to handle all queued frames in time. On such cases, what the Kernel does is to
just discard the frame. Userspace is able to detect it, by looking inside the timestamp
added on each frame.
> fileio->bufs[i].size = vb2_plane_size(q->bufs[i], 0);
> }
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
Cheers,
Mauro
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 4/14] drivers/media/v4l2-core/videobuf2-core.c: fix error return code
2012-10-06 11:17 ` Mauro Carvalho Chehab
@ 2012-10-10 16:47 ` Peter Senna Tschudin
2012-10-10 17:07 ` Sylwester Nawrocki
0 siblings, 1 reply; 7+ messages in thread
From: Peter Senna Tschudin @ 2012-10-10 16:47 UTC (permalink / raw)
To: Mauro Carvalho Chehab
Cc: kernel-janitors, Julia.Lawall, linux-media, linux-kernel
On Sat, Oct 6, 2012 at 1:17 PM, Mauro Carvalho Chehab
<mchehab@infradead.org> wrote:
> Em Thu, 6 Sep 2012 17:23:57 +0200
> Peter Senna Tschudin <peter.senna@gmail.com> escreveu:
>
>> From: Peter Senna Tschudin <peter.senna@gmail.com>
>>
>> Convert a nonnegative error return code to a negative one, as returned
>> elsewhere in the function.
>>
>> A simplified version of the semantic match that finds this problem is as
>> follows: (http://coccinelle.lip6.fr/)
>>
>> // <smpl>
>> (
>> if@p1 (\(ret < 0\|ret != 0\))
>> { ... return ret; }
>> |
>> ret@p1 = 0
>> )
>> ... when != ret = e1
>> when != &ret
>> *if(...)
>> {
>> ... when != ret = e2
>> when forall
>> return ret;
>> }
>>
>> // </smpl>
>>
>> Signed-off-by: Peter Senna Tschudin <peter.senna@gmail.com>
>>
>> ---
>> drivers/media/v4l2-core/videobuf2-core.c | 4 +++-
>> 1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
>> index 4da3df6..f6bc240 100644
>> --- a/drivers/media/v4l2-core/videobuf2-core.c
>> +++ b/drivers/media/v4l2-core/videobuf2-core.c
>> @@ -1876,8 +1876,10 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
>> */
>> for (i = 0; i < q->num_buffers; i++) {
>> fileio->bufs[i].vaddr = vb2_plane_vaddr(q->bufs[i], 0);
>> - if (fileio->bufs[i].vaddr = NULL)
>> + if (fileio->bufs[i].vaddr = NULL) {
>> + ret = -EFAULT;
>> goto err_reqbufs;
>> + }
>
> Had you test this patch? I suspect it breaks the driver, as there are failures under
> streaming handling that are acceptable, as it may indicate that userspace was not
> able to handle all queued frames in time. On such cases, what the Kernel does is to
> just discard the frame. Userspace is able to detect it, by looking inside the timestamp
> added on each frame.
No, I have not tested it. This was the only place the function was
returning non negative value for error path, so looked as a bug to me.
May I add a comment about returning non-negative value is intended
there?
>
>> fileio->bufs[i].size = vb2_plane_size(q->bufs[i], 0);
>> }
>>
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-media" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
>
>
>
> Cheers,
> Mauro
--
Peter
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 4/14] drivers/media/v4l2-core/videobuf2-core.c: fix error return code
2012-10-10 16:47 ` Peter Senna Tschudin
@ 2012-10-10 17:07 ` Sylwester Nawrocki
[not found] ` <1350571624-4666-1-git-send-email-peter.senna@gmail.com>
0 siblings, 1 reply; 7+ messages in thread
From: Sylwester Nawrocki @ 2012-10-10 17:07 UTC (permalink / raw)
To: Peter Senna Tschudin
Cc: Mauro Carvalho Chehab, kernel-janitors, Julia.Lawall, linux-media,
linux-kernel
Hi Peter,
On 10/10/2012 06:47 PM, Peter Senna Tschudin wrote:
>>> diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
>>> index 4da3df6..f6bc240 100644
>>> --- a/drivers/media/v4l2-core/videobuf2-core.c
>>> +++ b/drivers/media/v4l2-core/videobuf2-core.c
>>> @@ -1876,8 +1876,10 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read)
>>> */
>>> for (i = 0; i < q->num_buffers; i++) {
>>> fileio->bufs[i].vaddr = vb2_plane_vaddr(q->bufs[i], 0);
>>> - if (fileio->bufs[i].vaddr = NULL)
>>> + if (fileio->bufs[i].vaddr = NULL) {
>>> + ret = -EFAULT;
>>> goto err_reqbufs;
>>> + }
>>
>> Had you test this patch? I suspect it breaks the driver, as there are failures under
>> streaming handling that are acceptable, as it may indicate that userspace was not
>> able to handle all queued frames in time. On such cases, what the Kernel does is to
>> just discard the frame. Userspace is able to detect it, by looking inside the timestamp
>> added on each frame.
>
> No, I have not tested it. This was the only place the function was
> returning non negative value for error path, so looked as a bug to me.
> May I add a comment about returning non-negative value is intended
> there?
There are several drivers depending on core modules like videobuf2. By making
random changes for something that _looks like_ a bug to you and not verifying
it by testing with at least one driver you are potentially causing trouble to
developers that are already busy fixing real bugs or working on new features.
I appreciate your help but I also don't want to see _any_ untested, not trivial
patches for core modules like videobuf2 being applied.
--
Thanks,
Sylwester
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V2] drivers/media/v4l2-core/videobuf2-core.c: fix error return code
[not found] ` <1350571624-4666-1-git-send-email-peter.senna@gmail.com>
@ 2012-10-18 15:28 ` Ezequiel Garcia
2012-10-18 15:39 ` Peter Senna Tschudin
2012-10-18 15:51 ` Sylwester Nawrocki
0 siblings, 2 replies; 7+ messages in thread
From: Ezequiel Garcia @ 2012-10-18 15:28 UTC (permalink / raw)
To: Peter Senna Tschudin
Cc: pawel, m.szyprowski, kyungmin.park, mchehab, linux-media,
linux-kernel, kernel-janitors
On Thu, Oct 18, 2012 at 11:47 AM, Peter Senna Tschudin
<peter.senna@gmail.com> wrote:
> This patch fixes a NULL pointer dereference bug at __vb2_init_fileio().
> The NULL pointer deference happens at videobuf2-core.c:
>
> static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_t count,
> loff_t *ppos, int nonblock, int read)
> {
> ...
> if (!q->fileio) {
> ret = __vb2_init_fileio(q, read);
> dprintk(3, "file io: vb2_init_fileio result: %d\n", ret);
> if (ret)
> return ret;
> }
> fileio = q->fileio; // NULL pointer deference here
> ...
> }
>
> It was tested with vivi driver and qv4l2 for selecting read() as capture method.
> The OOPS happened when I've artificially forced the error by commenting the line:
> if (fileio->bufs[i].vaddr = NULL)
>
... but if you manually changed the original source, how
can this be a real BUG?
Or am I missing something here ?
Ezequiel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V2] drivers/media/v4l2-core/videobuf2-core.c: fix error return code
2012-10-18 15:28 ` [PATCH V2] " Ezequiel Garcia
@ 2012-10-18 15:39 ` Peter Senna Tschudin
2012-10-18 15:51 ` Sylwester Nawrocki
1 sibling, 0 replies; 7+ messages in thread
From: Peter Senna Tschudin @ 2012-10-18 15:39 UTC (permalink / raw)
To: Ezequiel Garcia
Cc: pawel, m.szyprowski, kyungmin.park, mchehab, linux-media,
linux-kernel, kernel-janitors
On Thu, Oct 18, 2012 at 5:28 PM, Ezequiel Garcia <elezegarcia@gmail.com> wrote:
> On Thu, Oct 18, 2012 at 11:47 AM, Peter Senna Tschudin
> <peter.senna@gmail.com> wrote:
>> This patch fixes a NULL pointer dereference bug at __vb2_init_fileio().
>> The NULL pointer deference happens at videobuf2-core.c:
>>
>> static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_t count,
>> loff_t *ppos, int nonblock, int read)
>> {
>> ...
>> if (!q->fileio) {
>> ret = __vb2_init_fileio(q, read);
>> dprintk(3, "file io: vb2_init_fileio result: %d\n", ret);
>> if (ret)
>> return ret;
>> }
>> fileio = q->fileio; // NULL pointer deference here
>> ...
>> }
>>
>> It was tested with vivi driver and qv4l2 for selecting read() as capture method.
>> The OOPS happened when I've artificially forced the error by commenting the line:
>> if (fileio->bufs[i].vaddr = NULL)
>>
>
> ... but if you manually changed the original source, how
> can this be a real BUG?
It is supposed that under some circumstances, (fileio->bufs[i].vaddr
= NULL) can be true. 'While testing', my change forced the scenario
in which (fileio->bufs[i].vaddr = NULL) is true...
>
> Or am I missing something here ?
>
> Ezequiel
--
Peter
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V2] drivers/media/v4l2-core/videobuf2-core.c: fix error return code
2012-10-18 15:28 ` [PATCH V2] " Ezequiel Garcia
2012-10-18 15:39 ` Peter Senna Tschudin
@ 2012-10-18 15:51 ` Sylwester Nawrocki
1 sibling, 0 replies; 7+ messages in thread
From: Sylwester Nawrocki @ 2012-10-18 15:51 UTC (permalink / raw)
To: Ezequiel Garcia
Cc: Peter Senna Tschudin, pawel, m.szyprowski, kyungmin.park, mchehab,
linux-media, linux-kernel, kernel-janitors
On 10/18/2012 05:28 PM, Ezequiel Garcia wrote:
> On Thu, Oct 18, 2012 at 11:47 AM, Peter Senna Tschudin
> <peter.senna@gmail.com> wrote:
>> This patch fixes a NULL pointer dereference bug at __vb2_init_fileio().
>> The NULL pointer deference happens at videobuf2-core.c:
>>
>> static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_t count,
>> loff_t *ppos, int nonblock, int read)
>> {
>> ...
>> if (!q->fileio) {
>> ret = __vb2_init_fileio(q, read);
>> dprintk(3, "file io: vb2_init_fileio result: %d\n", ret);
>> if (ret)
>> return ret;
>> }
>> fileio = q->fileio; // NULL pointer deference here
>> ...
>> }
>>
>> It was tested with vivi driver and qv4l2 for selecting read() as capture method.
>> The OOPS happened when I've artificially forced the error by commenting the line:
>> if (fileio->bufs[i].vaddr = NULL)
>>
>
> ... but if you manually changed the original source, how
> can this be a real BUG?
>
> Or am I missing something here ?
He just commented out this line to trigger the bug, i.e. to simulate
a situation where fileio->bufs[i].vaddr is NULL. Which is now not
handled properly.
--
Thanks,
Sylwester
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-10-18 15:51 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-06 15:23 [PATCH 4/14] drivers/media/v4l2-core/videobuf2-core.c: fix error return code Peter Senna Tschudin
2012-10-06 11:17 ` Mauro Carvalho Chehab
2012-10-10 16:47 ` Peter Senna Tschudin
2012-10-10 17:07 ` Sylwester Nawrocki
[not found] ` <1350571624-4666-1-git-send-email-peter.senna@gmail.com>
2012-10-18 15:28 ` [PATCH V2] " Ezequiel Garcia
2012-10-18 15:39 ` Peter Senna Tschudin
2012-10-18 15:51 ` Sylwester Nawrocki
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).