* [PATCH] drivers/media/video: avoid NULL dereference
@ 2010-03-21 21:31 Julia Lawall
2010-03-23 3:14 ` Andrew Morton
0 siblings, 1 reply; 4+ messages in thread
From: Julia Lawall @ 2010-03-21 21:31 UTC (permalink / raw)
To: Mark McClelland, Mauro Carvalho Chehab, linux-usb, linux-media,
linux-kernel, kernel-janitors
From: Julia Lawall <julia@diku.dk>
If ov is NULL, it will not be possible to take the lock in the first place,
so move the test up earlier.
The semantic match that finds the problem is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@r exists@
expression E, E1;
identifier f;
statement S1,S3;
iterator iter;
@@
if ((E == NULL && ...) || ...)
{
... when != false ((E == NULL && ...) || ...)
when != true ((E != NULL && ...) || ...)
when != iter(E,...) S1
when != E = E1
(
sizeof(E->f)
|
* E->f
)
... when any
return ...;
}
else S3
// </smpl>
Signed-off-by: Julia Lawall <julia@diku.dk>
---
drivers/media/video/ov511.c | 8 +++-----
1 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/media/video/ov511.c b/drivers/media/video/ov511.c
index e0bce8d..2357218 100644
--- a/drivers/media/video/ov511.c
+++ b/drivers/media/video/ov511.c
@@ -5913,14 +5913,12 @@ ov51x_disconnect(struct usb_interface *intf)
PDEBUG(3, "");
+ if (!ov)
+ return;
+
mutex_lock(&ov->lock);
usb_set_intfdata (intf, NULL);
- if (!ov) {
- mutex_unlock(&ov->lock);
- return;
- }
-
/* Free device number */
ov511_devused &= ~(1 << ov->nr);
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] drivers/media/video: avoid NULL dereference
2010-03-21 21:31 [PATCH] drivers/media/video: avoid NULL dereference Julia Lawall
@ 2010-03-23 3:14 ` Andrew Morton
2010-03-23 6:22 ` Julia Lawall
2010-03-23 6:24 ` Julia Lawall
0 siblings, 2 replies; 4+ messages in thread
From: Andrew Morton @ 2010-03-23 3:14 UTC (permalink / raw)
To: Julia Lawall
Cc: Mark McClelland, Mauro Carvalho Chehab, linux-usb, linux-media,
linux-kernel, kernel-janitors
On Sun, 21 Mar 2010 22:31:06 +0100 (CET) Julia Lawall <julia@diku.dk> wrote:
> From: Julia Lawall <julia@diku.dk>
>
> If ov is NULL, it will not be possible to take the lock in the first place,
> so move the test up earlier.
>
> ...
>
> --- a/drivers/media/video/ov511.c
> +++ b/drivers/media/video/ov511.c
> @@ -5913,14 +5913,12 @@ ov51x_disconnect(struct usb_interface *intf)
>
> PDEBUG(3, "");
>
> + if (!ov)
> + return;
> +
> mutex_lock(&ov->lock);
> usb_set_intfdata (intf, NULL);
>
> - if (!ov) {
> - mutex_unlock(&ov->lock);
> - return;
> - }
> -
> /* Free device number */
> ov511_devused &= ~(1 << ov->nr);
I think we can pretty safely assume that we never get here with ov==NULL.
Oh well, I'll leave the test there for others to ponder.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] drivers/media/video: avoid NULL dereference
2010-03-23 3:14 ` Andrew Morton
@ 2010-03-23 6:22 ` Julia Lawall
2010-03-23 6:24 ` Julia Lawall
1 sibling, 0 replies; 4+ messages in thread
From: Julia Lawall @ 2010-03-23 6:22 UTC (permalink / raw)
To: Andrew Morton
Cc: Mark McClelland, Mauro Carvalho Chehab, linux-usb, linux-media,
linux-kernel, kernel-janitors
From: Julia Lawall <julia@diku.dk>
It seems impossible for ov to be NULL at this point.
The semantic match that finds the problem is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@r exists@
expression E, E1;
identifier f;
statement S1,S3;
iterator iter;
@@
if ((E == NULL && ...) || ...)
{
... when != false ((E == NULL && ...) || ...)
when != true ((E != NULL && ...) || ...)
when != iter(E,...) S1
when != E = E1
(
sizeof(E->f)
|
* E->f
)
... when any
return ...;
}
else S3
// </smpl>
Signed-off-by: Julia Lawall <julia@diku.dk>
---
drivers/media/video/ov511.c | 5 -----
1 files changed, 0 insertions(+), 5 deletions(-)
diff --git a/drivers/media/video/ov511.c b/drivers/media/video/ov511.c
index e0bce8d..dd1b1ac 100644
--- a/drivers/media/video/ov511.c
+++ b/drivers/media/video/ov511.c
@@ -5916,11 +5916,6 @@ ov51x_disconnect(struct usb_interface *intf)
mutex_lock(&ov->lock);
usb_set_intfdata (intf, NULL);
- if (!ov) {
- mutex_unlock(&ov->lock);
- return;
- }
-
/* Free device number */
ov511_devused &= ~(1 << ov->nr);
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] drivers/media/video: avoid NULL dereference
2010-03-23 3:14 ` Andrew Morton
2010-03-23 6:22 ` Julia Lawall
@ 2010-03-23 6:24 ` Julia Lawall
1 sibling, 0 replies; 4+ messages in thread
From: Julia Lawall @ 2010-03-23 6:24 UTC (permalink / raw)
To: Andrew Morton
Cc: Mark McClelland, Mauro Carvalho Chehab, linux-usb, linux-media,
linux-kernel, kernel-janitors
> I think we can pretty safely assume that we never get here with ov==NULL.
>
> Oh well, I'll leave the test there for others to ponder.
OK. I didn't read far enough in this email and sent another patch, in
case it's useful.
julia
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-03-23 6:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-21 21:31 [PATCH] drivers/media/video: avoid NULL dereference Julia Lawall
2010-03-23 3:14 ` Andrew Morton
2010-03-23 6:22 ` Julia Lawall
2010-03-23 6:24 ` Julia Lawall
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).