media: ispstat: don't dereference user_cfg before a null check
Subsystems (2)
PATCH 1/1 media: ispstat: don't dereference user_cfg before a null check
From: Colin Ian King <[email protected]>
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")
--- drivers/media/platform/omap3isp/ispstat.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/platform/omap3isp/ispstat.c +2 -1
@@ -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",
Signature · 1 line
2.17.0
Quoted 8 lines · Colin King
From: Colin Ian King <[email protected]>
The pointer
user_cfg(a copy ofnew_conf) is dereference beforenew_confis null checked, hence we may have a null pointer dereference onuser_cfgwhen assigningbuf_sizefromuser_cfg->buf_size. Ensure this does not occur by moving the assignment ofbuf_sizeafter the null check.
Quoted 4 lines
Detected by CoverityScan, CID#1468386 ("Dereference before null check")
Fixes 68e342b3068c ("[media] omap3isp: Statistics")Signed-off-by Colin Ian King <[email protected]>
Thanks for the patch.
Gustavo sent effectively the same patch a moment earlier, and that patch got applied instead.
Signature · 2 lines
Sakari Ailus e-mail: [email protected]
Hi Sakari,
Quoted 11 lines · On Thursday, 26 April 2018 11:37:31 EEST Sakari Ailus wrote:
Quoted 10 lines · Colin King
From: Colin Ian King <[email protected]>
The pointer
user_cfg(a copy ofnew_conf) is dereference beforenew_confis null checked, hence we may have a null pointer dereference onuser_cfgwhen assigningbuf_sizefromuser_cfg->buf_size. Ensure this does not occur by moving the assignment ofbuf_sizeafter the null check.Detected by CoverityScan, CID#1468386 ("Dereference before null check")
Quoted 7 lines
Quoted 2 lines
Fixes 68e342b3068c ("[media] omap3isp: Statistics")Signed-off-by Colin Ian King <[email protected]>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.
Signature · 3 lines
Regards, Laurent Pinchart
Quoted 17 lines · Laurent Pinchart
Hi Sakari,
Quoted 14 lines · On Thursday, 26 April 2018 11:37:31 EEST Sakari Ailus wrote:
Quoted 12 lines · Colin King
From: Colin Ian King <[email protected]>
The pointer
user_cfg(a copy ofnew_conf) is dereference beforenew_confis null checked, hence we may have a null pointer dereference onuser_cfgwhen assigningbuf_sizefromuser_cfg->buf_size. Ensure this does not occur by moving the assignment ofbuf_sizeafter the null check.Detected by CoverityScan, CID#1468386 ("Dereference before null check")
Fixes 68e342b3068c ("[media] omap3isp: Statistics")Signed-off-by Colin Ian King <[email protected]>
Quoted 8 lines
Quoted 4 lines
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_bufwon't be NULL ? Thenew_bufpointer comes from the parg variable invideo_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.
Signature · 2 lines
Sakari Ailus e-mail: [email protected]
Hi Sakari,
Quoted 11 lines · Sakari Ailus
Quoted 3 lines
Isn't there a guarantee that
new_bufwon't be NULL ? Thenew_bufpointer comes from the parg variable invideo_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