All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][next] media: ispstat: don't dereference user_cfg before a null check
@ 2018-04-24 13:06 ` Colin King
  0 siblings, 0 replies; 10+ messages in thread
From: Colin King @ 2018-04-24 13:06 UTC (permalink / raw)
  To: Laurent Pinchart, Mauro Carvalho Chehab, linux-media
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The pointer user_cfg (a copy of new_conf) is dereference before
new_conf is null checked, hence we may have a null pointer dereference
on user_cfg when assigning buf_size from user_cfg->buf_size. Ensure
this does not occur by moving the assignment of buf_size after the
null check.

Detected by CoverityScan, CID#1468386 ("Dereference before null check")

Fixes: 68e342b3068c ("[media] omap3isp: Statistics")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/media/platform/omap3isp/ispstat.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/omap3isp/ispstat.c b/drivers/media/platform/omap3isp/ispstat.c
index 0b31f6c5791f..38cb1b2cc672 100644
--- a/drivers/media/platform/omap3isp/ispstat.c
+++ b/drivers/media/platform/omap3isp/ispstat.c
@@ -523,7 +523,7 @@ int omap3isp_stat_config(struct ispstat *stat, void *new_conf)
 	int ret;
 	unsigned long irqflags;
 	struct ispstat_generic_config *user_cfg = new_conf;
-	u32 buf_size = user_cfg->buf_size;
+	u32 buf_size;
 
 	if (!new_conf) {
 		dev_dbg(stat->isp->dev, "%s: configuration is NULL\n",
@@ -532,6 +532,7 @@ int omap3isp_stat_config(struct ispstat *stat, void *new_conf)
 	}
 
 	mutex_lock(&stat->ioctl_lock);
+	buf_size = user_cfg->buf_size;
 
 	dev_dbg(stat->isp->dev,
 		"%s: configuring module with buffer size=0x%08lx\n",
-- 
2.17.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH][next] media: ispstat: don't dereference user_cfg before a null check
@ 2018-04-24 13:06 ` Colin King
  0 siblings, 0 replies; 10+ messages in thread
From: Colin King @ 2018-04-24 13:06 UTC (permalink / raw)
  To: Laurent Pinchart, Mauro Carvalho Chehab, linux-media
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The pointer user_cfg (a copy of new_conf) is dereference before
new_conf is null checked, hence we may have a null pointer dereference
on user_cfg when assigning buf_size from user_cfg->buf_size. Ensure
this does not occur by moving the assignment of buf_size after the
null check.

Detected by CoverityScan, CID#1468386 ("Dereference before null check")

Fixes: 68e342b3068c ("[media] omap3isp: Statistics")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/media/platform/omap3isp/ispstat.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/omap3isp/ispstat.c b/drivers/media/platform/omap3isp/ispstat.c
index 0b31f6c5791f..38cb1b2cc672 100644
--- a/drivers/media/platform/omap3isp/ispstat.c
+++ b/drivers/media/platform/omap3isp/ispstat.c
@@ -523,7 +523,7 @@ int omap3isp_stat_config(struct ispstat *stat, void *new_conf)
 	int ret;
 	unsigned long irqflags;
 	struct ispstat_generic_config *user_cfg = new_conf;
-	u32 buf_size = user_cfg->buf_size;
+	u32 buf_size;
 
 	if (!new_conf) {
 		dev_dbg(stat->isp->dev, "%s: configuration is NULL\n",
@@ -532,6 +532,7 @@ int omap3isp_stat_config(struct ispstat *stat, void *new_conf)
 	}
 
 	mutex_lock(&stat->ioctl_lock);
+	buf_size = user_cfg->buf_size;
 
 	dev_dbg(stat->isp->dev,
 		"%s: configuring module with buffer size=0x%08lx\n",
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH][next] media: ispstat: don't dereference user_cfg before a null check
  2018-04-24 13:06 ` Colin King
@ 2018-04-26  8:37   ` Sakari Ailus
  -1 siblings, 0 replies; 10+ messages in thread
From: Sakari Ailus @ 2018-04-26  8:37 UTC (permalink / raw)
  To: Colin King
  Cc: Laurent Pinchart, Mauro Carvalho Chehab, linux-media,
	kernel-janitors, linux-kernel

On Tue, Apr 24, 2018 at 02:06:18PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The pointer user_cfg (a copy of new_conf) is dereference before
> new_conf is null checked, hence we may have a null pointer dereference
> on user_cfg when assigning buf_size from user_cfg->buf_size. Ensure
> this does not occur by moving the assignment of buf_size after the
> null check.
> 
> Detected by CoverityScan, CID#1468386 ("Dereference before null check")
> 
> Fixes: 68e342b3068c ("[media] omap3isp: Statistics")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Thanks for the patch.

Gustavo sent effectively the same patch a moment earlier, and that patch
got applied instead.

-- 
Sakari Ailus
e-mail: sakari.ailus@iki.fi

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH][next] media: ispstat: don't dereference user_cfg before a null check
@ 2018-04-26  8:37   ` Sakari Ailus
  0 siblings, 0 replies; 10+ messages in thread
From: Sakari Ailus @ 2018-04-26  8:37 UTC (permalink / raw)
  To: Colin King
  Cc: Laurent Pinchart, Mauro Carvalho Chehab, linux-media,
	kernel-janitors, linux-kernel

On Tue, Apr 24, 2018 at 02:06:18PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The pointer user_cfg (a copy of new_conf) is dereference before
> new_conf is null checked, hence we may have a null pointer dereference
> on user_cfg when assigning buf_size from user_cfg->buf_size. Ensure
> this does not occur by moving the assignment of buf_size after the
> null check.
> 
> Detected by CoverityScan, CID#1468386 ("Dereference before null check")
> 
> Fixes: 68e342b3068c ("[media] omap3isp: Statistics")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Thanks for the patch.

Gustavo sent effectively the same patch a moment earlier, and that patch
got applied instead.

-- 
Sakari Ailus
e-mail: sakari.ailus@iki.fi

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH][next] media: ispstat: don't dereference user_cfg before a null check
  2018-04-26  8:37   ` Sakari Ailus
@ 2018-04-26 10:03     ` Laurent Pinchart
  -1 siblings, 0 replies; 10+ messages in thread
From: Laurent Pinchart @ 2018-04-26 10:03 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: Colin King, Mauro Carvalho Chehab, linux-media, kernel-janitors,
	linux-kernel

Hi Sakari,

On Thursday, 26 April 2018 11:37:31 EEST Sakari Ailus wrote:
> On Tue, Apr 24, 2018 at 02:06:18PM +0100, Colin King wrote:
> > From: Colin Ian King <colin.king@canonical.com>
> > 
> > The pointer user_cfg (a copy of new_conf) is dereference before
> > new_conf is null checked, hence we may have a null pointer dereference
> > on user_cfg when assigning buf_size from user_cfg->buf_size. Ensure
> > this does not occur by moving the assignment of buf_size after the
> > null check.
> > 
> > Detected by CoverityScan, CID#1468386 ("Dereference before null check")
> > 
> > Fixes: 68e342b3068c ("[media] omap3isp: Statistics")
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> 
> Thanks for the patch.
> 
> Gustavo sent effectively the same patch a moment earlier, and that patch
> got applied instead.

Isn't there a guarantee that new_buf won't be NULL ? The new_buf pointer comes 
from the parg variable in video_usercopy(), which should always point to a 
valid buffer given that the ioctl number specifies a non-zero size.

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH][next] media: ispstat: don't dereference user_cfg before a null check
@ 2018-04-26 10:03     ` Laurent Pinchart
  0 siblings, 0 replies; 10+ messages in thread
From: Laurent Pinchart @ 2018-04-26 10:03 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: Colin King, Mauro Carvalho Chehab, linux-media, kernel-janitors,
	linux-kernel

Hi Sakari,

On Thursday, 26 April 2018 11:37:31 EEST Sakari Ailus wrote:
> On Tue, Apr 24, 2018 at 02:06:18PM +0100, Colin King wrote:
> > From: Colin Ian King <colin.king@canonical.com>
> > 
> > The pointer user_cfg (a copy of new_conf) is dereference before
> > new_conf is null checked, hence we may have a null pointer dereference
> > on user_cfg when assigning buf_size from user_cfg->buf_size. Ensure
> > this does not occur by moving the assignment of buf_size after the
> > null check.
> > 
> > Detected by CoverityScan, CID#1468386 ("Dereference before null check")
> > 
> > Fixes: 68e342b3068c ("[media] omap3isp: Statistics")
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> 
> Thanks for the patch.
> 
> Gustavo sent effectively the same patch a moment earlier, and that patch
> got applied instead.

Isn't there a guarantee that new_buf won't be NULL ? The new_buf pointer comes 
from the parg variable in video_usercopy(), which should always point to a 
valid buffer given that the ioctl number specifies a non-zero size.

-- 
Regards,

Laurent Pinchart




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH][next] media: ispstat: don't dereference user_cfg before a null check
  2018-04-26 10:03     ` Laurent Pinchart
@ 2018-04-30 15:15       ` Sakari Ailus
  -1 siblings, 0 replies; 10+ messages in thread
From: Sakari Ailus @ 2018-04-30 15:15 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Colin King, Mauro Carvalho Chehab, linux-media, kernel-janitors,
	linux-kernel

On Thu, Apr 26, 2018 at 01:03:15PM +0300, Laurent Pinchart wrote:
> Hi Sakari,
> 
> On Thursday, 26 April 2018 11:37:31 EEST Sakari Ailus wrote:
> > On Tue, Apr 24, 2018 at 02:06:18PM +0100, Colin King wrote:
> > > From: Colin Ian King <colin.king@canonical.com>
> > > 
> > > The pointer user_cfg (a copy of new_conf) is dereference before
> > > new_conf is null checked, hence we may have a null pointer dereference
> > > on user_cfg when assigning buf_size from user_cfg->buf_size. Ensure
> > > this does not occur by moving the assignment of buf_size after the
> > > null check.
> > > 
> > > Detected by CoverityScan, CID#1468386 ("Dereference before null check")
> > > 
> > > Fixes: 68e342b3068c ("[media] omap3isp: Statistics")
> > > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > 
> > Thanks for the patch.
> > 
> > Gustavo sent effectively the same patch a moment earlier, and that patch
> > got applied instead.
> 
> Isn't there a guarantee that new_buf won't be NULL ? The new_buf pointer comes 
> from the parg variable in video_usercopy(), which should always point to a 
> valid buffer given that the ioctl number specifies a non-zero size.

Fair question. After looking at the code, I agree with you; there should be
no reason to perform the check in the first place. It may have been that
the function has been used differently in the past but the check should be
rather removed now.

I'll drop the patch.

-- 
Sakari Ailus
e-mail: sakari.ailus@iki.fi

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH][next] media: ispstat: don't dereference user_cfg before a null check
@ 2018-04-30 15:15       ` Sakari Ailus
  0 siblings, 0 replies; 10+ messages in thread
From: Sakari Ailus @ 2018-04-30 15:15 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Colin King, Mauro Carvalho Chehab, linux-media, kernel-janitors,
	linux-kernel

On Thu, Apr 26, 2018 at 01:03:15PM +0300, Laurent Pinchart wrote:
> Hi Sakari,
> 
> On Thursday, 26 April 2018 11:37:31 EEST Sakari Ailus wrote:
> > On Tue, Apr 24, 2018 at 02:06:18PM +0100, Colin King wrote:
> > > From: Colin Ian King <colin.king@canonical.com>
> > > 
> > > The pointer user_cfg (a copy of new_conf) is dereference before
> > > new_conf is null checked, hence we may have a null pointer dereference
> > > on user_cfg when assigning buf_size from user_cfg->buf_size. Ensure
> > > this does not occur by moving the assignment of buf_size after the
> > > null check.
> > > 
> > > Detected by CoverityScan, CID#1468386 ("Dereference before null check")
> > > 
> > > Fixes: 68e342b3068c ("[media] omap3isp: Statistics")
> > > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > 
> > Thanks for the patch.
> > 
> > Gustavo sent effectively the same patch a moment earlier, and that patch
> > got applied instead.
> 
> Isn't there a guarantee that new_buf won't be NULL ? The new_buf pointer comes 
> from the parg variable in video_usercopy(), which should always point to a 
> valid buffer given that the ioctl number specifies a non-zero size.

Fair question. After looking at the code, I agree with you; there should be
no reason to perform the check in the first place. It may have been that
the function has been used differently in the past but the check should be
rather removed now.

I'll drop the patch.

-- 
Sakari Ailus
e-mail: sakari.ailus@iki.fi

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH][next] media: ispstat: don't dereference user_cfg before a null check
  2018-04-30 15:15       ` Sakari Ailus
@ 2018-04-30 15:26         ` Gustavo A. R. Silva
  -1 siblings, 0 replies; 10+ messages in thread
From: Gustavo A. R. Silva @ 2018-04-30 15:26 UTC (permalink / raw)
  To: Sakari Ailus, Laurent Pinchart
  Cc: Colin King, Mauro Carvalho Chehab, linux-media, kernel-janitors,
	linux-kernel

Hi Sakari,

On 04/30/2018 10:15 AM, Sakari Ailus wrote:
>> Isn't there a guarantee that new_buf won't be NULL ? The new_buf pointer comes
>> from the parg variable in video_usercopy(), which should always point to a
>> valid buffer given that the ioctl number specifies a non-zero size.
> 
> Fair question. After looking at the code, I agree with you; there should be
> no reason to perform the check in the first place. It may have been that
> the function has been used differently in the past but the check should be
> rather removed now.
> 
> I'll drop the patch.
> 

Please, if the check isn't needed anymore, make sure it is removed.

This helps to reduce the number of false positives reported by static 
analyzers.

Thanks
--
Gustavo

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH][next] media: ispstat: don't dereference user_cfg before a null check
@ 2018-04-30 15:26         ` Gustavo A. R. Silva
  0 siblings, 0 replies; 10+ messages in thread
From: Gustavo A. R. Silva @ 2018-04-30 15:26 UTC (permalink / raw)
  To: Sakari Ailus, Laurent Pinchart
  Cc: Colin King, Mauro Carvalho Chehab, linux-media, kernel-janitors,
	linux-kernel

Hi Sakari,

On 04/30/2018 10:15 AM, Sakari Ailus wrote:
>> Isn't there a guarantee that new_buf won't be NULL ? The new_buf pointer comes
>> from the parg variable in video_usercopy(), which should always point to a
>> valid buffer given that the ioctl number specifies a non-zero size.
> 
> Fair question. After looking at the code, I agree with you; there should be
> no reason to perform the check in the first place. It may have been that
> the function has been used differently in the past but the check should be
> rather removed now.
> 
> I'll drop the patch.
> 

Please, if the check isn't needed anymore, make sure it is removed.

This helps to reduce the number of false positives reported by static 
analyzers.

Thanks
--
Gustavo

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-04-30 15:26 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-24 13:06 [PATCH][next] media: ispstat: don't dereference user_cfg before a null check Colin King
2018-04-24 13:06 ` Colin King
2018-04-26  8:37 ` Sakari Ailus
2018-04-26  8:37   ` Sakari Ailus
2018-04-26 10:03   ` Laurent Pinchart
2018-04-26 10:03     ` Laurent Pinchart
2018-04-30 15:15     ` Sakari Ailus
2018-04-30 15:15       ` Sakari Ailus
2018-04-30 15:26       ` Gustavo A. R. Silva
2018-04-30 15:26         ` Gustavo A. R. Silva

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.