linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: davinci_vpfe: fix a NULL pointer dereference bug
@ 2018-10-04 16:00 Wenwen Wang
  2018-10-29 20:35 ` Wenwen Wang
  0 siblings, 1 reply; 2+ messages in thread
From: Wenwen Wang @ 2018-10-04 16:00 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: Kangjie Lu, Mauro Carvalho Chehab, Greg Kroah-Hartman,
	open list:MEDIA INPUT INFRASTRUCTURE (V4L/DVB),
	open list:STAGING SUBSYSTEM, open list

In vpfe_isif_init(), there is a while loop to get the ISIF base address and
linearization table0 and table1 address. In the loop body, the function
platform_get_resource() is called to get the resource. If
platform_get_resource() returns NULL, the loop is terminated and the
execution goes to 'fail_nobase_res'. Suppose the loop is terminated at the
first iteration because platform_get_resource() returns NULL and the
execution goes to 'fail_nobase_res'. Given that there is another while loop
at 'fail_nobase_res' and i equals to 0, one iteration of the second while
loop will be executed. However, the second while loop does not check the
return value of platform_get_resource(). This can cause a NULL pointer
dereference bug if the return value is a NULL pointer.

This patch avoids the above issue by adding a check in the second while
loop after the call to platform_get_resource().

Signed-off-by: Wenwen Wang <wang6495@umn.edu>
---
 drivers/staging/media/davinci_vpfe/dm365_isif.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/media/davinci_vpfe/dm365_isif.c b/drivers/staging/media/davinci_vpfe/dm365_isif.c
index 745e33f..b0425a6 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_isif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_isif.c
@@ -2080,7 +2080,8 @@ int vpfe_isif_init(struct vpfe_isif_device *isif, struct platform_device *pdev)
 
 	while (i >= 0) {
 		res = platform_get_resource(pdev, IORESOURCE_MEM, i);
-		release_mem_region(res->start, res_len);
+		if (res)
+			release_mem_region(res->start, res_len);
 		i--;
 	}
 	return status;
-- 
2.7.4


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

* Re: [PATCH] media: davinci_vpfe: fix a NULL pointer dereference bug
  2018-10-04 16:00 [PATCH] media: davinci_vpfe: fix a NULL pointer dereference bug Wenwen Wang
@ 2018-10-29 20:35 ` Wenwen Wang
  0 siblings, 0 replies; 2+ messages in thread
From: Wenwen Wang @ 2018-10-29 20:35 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: Kangjie Lu, Mauro Carvalho Chehab, Greg Kroah-Hartman,
	open list:STAGING - ATOMISP DRIVER, open list:STAGING SUBSYSTEM,
	open list

Hello,

Can anyone please confirm this bug and apply the patch? Thanks!

Wenwen

On Thu, Oct 4, 2018 at 11:00 AM Wenwen Wang <wang6495@umn.edu> wrote:
>
> In vpfe_isif_init(), there is a while loop to get the ISIF base address and
> linearization table0 and table1 address. In the loop body, the function
> platform_get_resource() is called to get the resource. If
> platform_get_resource() returns NULL, the loop is terminated and the
> execution goes to 'fail_nobase_res'. Suppose the loop is terminated at the
> first iteration because platform_get_resource() returns NULL and the
> execution goes to 'fail_nobase_res'. Given that there is another while loop
> at 'fail_nobase_res' and i equals to 0, one iteration of the second while
> loop will be executed. However, the second while loop does not check the
> return value of platform_get_resource(). This can cause a NULL pointer
> dereference bug if the return value is a NULL pointer.
>
> This patch avoids the above issue by adding a check in the second while
> loop after the call to platform_get_resource().
>
> Signed-off-by: Wenwen Wang <wang6495@umn.edu>
> ---
>  drivers/staging/media/davinci_vpfe/dm365_isif.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/staging/media/davinci_vpfe/dm365_isif.c b/drivers/staging/media/davinci_vpfe/dm365_isif.c
> index 745e33f..b0425a6 100644
> --- a/drivers/staging/media/davinci_vpfe/dm365_isif.c
> +++ b/drivers/staging/media/davinci_vpfe/dm365_isif.c
> @@ -2080,7 +2080,8 @@ int vpfe_isif_init(struct vpfe_isif_device *isif, struct platform_device *pdev)
>
>         while (i >= 0) {
>                 res = platform_get_resource(pdev, IORESOURCE_MEM, i);
> -               release_mem_region(res->start, res_len);
> +               if (res)
> +                       release_mem_region(res->start, res_len);
>                 i--;
>         }
>         return status;
> --
> 2.7.4
>

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

end of thread, other threads:[~2018-10-29 20:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-04 16:00 [PATCH] media: davinci_vpfe: fix a NULL pointer dereference bug Wenwen Wang
2018-10-29 20:35 ` Wenwen Wang

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).