mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] media: atomisp: ssh_css: Fix a null-pointer dereference in load_video_binaries
@ 2024-01-12  8:34 Zhipeng Lu
  2024-01-12  8:49 ` Hans de Goede
  0 siblings, 1 reply; 5+ messages in thread
From: Zhipeng Lu @ 2024-01-12  8:34 UTC (permalink / raw)
  To: alexious
  Cc: Hans de Goede, Mauro Carvalho Chehab, Sakari Ailus,
	Greg Kroah-Hartman, Kate Hsuan, Andy Shevchenko, Dan Carpenter,
	Brent Pappas, linux-media, linux-staging, linux-kernel

The allocation failure of mycs->yuv_scaler_binary in load_video_binaries
is followed with a dereference of mycs->yuv_scaler_binary after the
following call chain:

sh_css_pipe_load_binaries
  |-> load_video_binaries (mycs->yuv_scaler_binary == NULL)
  |
  |-> sh_css_pipe_unload_binaries
        |-> unload_video_binaries

In unload_video_binaries, it calls to ia_css_binary_unload with argument
&pipe->pipe_settings.video.yuv_scaler_binary[i], which refers to the
same memory slot as mycs->yuv_scaler_binary. Thus, a null-pointer
dereference is triggered.

Fixes: ad85094b293e ("Revert "media: staging: atomisp: Remove driver"")
Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
---
 drivers/staging/media/atomisp/pci/sh_css.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/media/atomisp/pci/sh_css.c b/drivers/staging/media/atomisp/pci/sh_css.c
index f35c90809414..eb43f4e99d02 100644
--- a/drivers/staging/media/atomisp/pci/sh_css.c
+++ b/drivers/staging/media/atomisp/pci/sh_css.c
@@ -4936,9 +4936,10 @@ unload_video_binaries(struct ia_css_pipe *pipe)
 	ia_css_binary_unload(&pipe->pipe_settings.video.video_binary);
 	ia_css_binary_unload(&pipe->pipe_settings.video.vf_pp_binary);
 
-	for (i = 0; i < pipe->pipe_settings.video.num_yuv_scaler; i++)
-		ia_css_binary_unload(&pipe->pipe_settings.video.yuv_scaler_binary[i]);
-
+	if (pipe->pipe_settings.video.yuv_scaler_binary)
+		for (i = 0; i < pipe->pipe_settings.video.num_yuv_scaler; i++)
+			ia_css_binary_unload(&pipe->pipe_settings.video.yuv_scaler_binary[i]);
+		
 	kfree(pipe->pipe_settings.video.is_output_stage);
 	pipe->pipe_settings.video.is_output_stage = NULL;
 	kfree(pipe->pipe_settings.video.yuv_scaler_binary);
-- 
2.34.1


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

* Re: [PATCH] media: atomisp: ssh_css: Fix a null-pointer dereference in load_video_binaries
  2024-01-12  8:34 [PATCH] media: atomisp: ssh_css: Fix a null-pointer dereference in load_video_binaries Zhipeng Lu
@ 2024-01-12  8:49 ` Hans de Goede
  2024-01-12 18:27   ` Andy Shevchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Hans de Goede @ 2024-01-12  8:49 UTC (permalink / raw)
  To: Zhipeng Lu
  Cc: Mauro Carvalho Chehab, Sakari Ailus, Greg Kroah-Hartman,
	Kate Hsuan, Andy Shevchenko, Dan Carpenter, Brent Pappas,
	linux-media, linux-staging, linux-kernel

Hi Zhipeng Lu,

On 1/12/24 09:34, Zhipeng Lu wrote:
> The allocation failure of mycs->yuv_scaler_binary in load_video_binaries
> is followed with a dereference of mycs->yuv_scaler_binary after the
> following call chain:
> 
> sh_css_pipe_load_binaries
>   |-> load_video_binaries (mycs->yuv_scaler_binary == NULL)
>   |
>   |-> sh_css_pipe_unload_binaries
>         |-> unload_video_binaries
> 
> In unload_video_binaries, it calls to ia_css_binary_unload with argument
> &pipe->pipe_settings.video.yuv_scaler_binary[i], which refers to the
> same memory slot as mycs->yuv_scaler_binary. Thus, a null-pointer
> dereference is triggered.
> 
> Fixes: ad85094b293e ("Revert "media: staging: atomisp: Remove driver"")
> Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>

Thank you for your patch. I believe it would be better to fix this
like this:

diff --git a/drivers/staging/media/atomisp/pci/sh_css.c b/drivers/staging/media/atomisp/pci/sh_css.c
index 1d1fbda75da1..d566c5417448 100644
--- a/drivers/staging/media/atomisp/pci/sh_css.c
+++ b/drivers/staging/media/atomisp/pci/sh_css.c
@@ -4690,6 +4690,7 @@ static int load_video_binaries(struct ia_css_pipe *pipe)
 						  sizeof(struct ia_css_binary),
 						  GFP_KERNEL);
 		if (!mycs->yuv_scaler_binary) {
+			mycs->num_yuv_scaler = 0;
 			err = -ENOMEM;
 			return err;
 		}

Can you please submit a new version using this approach ?

Regards,

Hans



> ---
>  drivers/staging/media/atomisp/pci/sh_css.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/staging/media/atomisp/pci/sh_css.c b/drivers/staging/media/atomisp/pci/sh_css.c
> index f35c90809414..eb43f4e99d02 100644
> --- a/drivers/staging/media/atomisp/pci/sh_css.c
> +++ b/drivers/staging/media/atomisp/pci/sh_css.c
> @@ -4936,9 +4936,10 @@ unload_video_binaries(struct ia_css_pipe *pipe)
>  	ia_css_binary_unload(&pipe->pipe_settings.video.video_binary);
>  	ia_css_binary_unload(&pipe->pipe_settings.video.vf_pp_binary);
>  
> -	for (i = 0; i < pipe->pipe_settings.video.num_yuv_scaler; i++)
> -		ia_css_binary_unload(&pipe->pipe_settings.video.yuv_scaler_binary[i]);
> -
> +	if (pipe->pipe_settings.video.yuv_scaler_binary)
> +		for (i = 0; i < pipe->pipe_settings.video.num_yuv_scaler; i++)
> +			ia_css_binary_unload(&pipe->pipe_settings.video.yuv_scaler_binary[i]);
> +		
>  	kfree(pipe->pipe_settings.video.is_output_stage);
>  	pipe->pipe_settings.video.is_output_stage = NULL;
>  	kfree(pipe->pipe_settings.video.yuv_scaler_binary);


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

* Re: [PATCH] media: atomisp: ssh_css: Fix a null-pointer dereference in load_video_binaries
  2024-01-12  8:49 ` Hans de Goede
@ 2024-01-12 18:27   ` Andy Shevchenko
       [not found]     ` <17d22c9e.4900.18d162090d8.Coremail.alexious@zju.edu.cn>
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2024-01-12 18:27 UTC (permalink / raw)
  To: Hans de Goede
  Cc: Zhipeng Lu, Mauro Carvalho Chehab, Sakari Ailus,
	Greg Kroah-Hartman, Kate Hsuan, Dan Carpenter, Brent Pappas,
	linux-media, linux-staging, linux-kernel

On Fri, Jan 12, 2024 at 10:49 AM Hans de Goede <hdegoede@redhat.com> wrote:
> On 1/12/24 09:34, Zhipeng Lu wrote:


> > Fixes: ad85094b293e ("Revert "media: staging: atomisp: Remove driver"")

> Can you please submit a new version using this approach ?

Besides that, are you sure the Fixes refers to the correct commit?

-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH] media: atomisp: ssh_css: Fix a null-pointer dereference in load_video_binaries
       [not found]     ` <17d22c9e.4900.18d162090d8.Coremail.alexious@zju.edu.cn>
@ 2024-01-17 20:50       ` Andy Shevchenko
  2024-01-18 15:10         ` alexious
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2024-01-17 20:50 UTC (permalink / raw)
  To: alexious
  Cc: Hans de Goede, Mauro Carvalho Chehab, Sakari Ailus,
	Greg Kroah-Hartman, Kate Hsuan, Dan Carpenter, Brent Pappas,
	linux-media, linux-staging, linux-kernel

On Wed, Jan 17, 2024 at 8:34 AM <alexious@zju.edu.cn> wrote:
> > On Fri, Jan 12, 2024 at 10:49 AM Hans de Goede <hdegoede@redhat.com> wrote:
> > > On 1/12/24 09:34, Zhipeng Lu wrote:

> > > > Fixes: ad85094b293e ("Revert "media: staging: atomisp: Remove driver"")
> > Besides that, are you sure the Fixes refers to the correct commit?
>
> Well, I think I referred to the correct commit, which introduce the whole module and leave this bug.
>
> If I did miss something please let me know.

Yes, the driver was before that commit in the kernel. Was it without
the bug? No, because you are referring to a clear revert. So, find the
real commit that had brought that into the kernel.

-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH] media: atomisp: ssh_css: Fix a null-pointer dereference in load_video_binaries
  2024-01-17 20:50       ` Andy Shevchenko
@ 2024-01-18 15:10         ` alexious
  0 siblings, 0 replies; 5+ messages in thread
From: alexious @ 2024-01-18 15:10 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Hans de Goede, Mauro Carvalho Chehab, Sakari Ailus,
	Greg Kroah-Hartman, Kate Hsuan, Dan Carpenter, Brent Pappas,
	linux-media, linux-staging, linux-kernel

> On Wed, Jan 17, 2024 at 8:34 AM <alexious@zju.edu.cn> wrote:
> > > On Fri, Jan 12, 2024 at 10:49 AM Hans de Goede <hdegoede@redhat.com> wrote:
> > > > On 1/12/24 09:34, Zhipeng Lu wrote:
> 
> > > > > Fixes: ad85094b293e ("Revert "media: staging: atomisp: Remove driver"")
> > > Besides that, are you sure the Fixes refers to the correct commit?
> >
> > Well, I think I referred to the correct commit, which introduce the whole module and leave this bug.
> >
> > If I did miss something please let me know.
> 
> Yes, the driver was before that commit in the kernel. Was it without
> the bug? No, because you are referring to a clear revert. So, find the
> real commit that had brought that into the kernel.

You are correct, I just did some git blame on the latest version but 
forgot about the commit blamed was a revert commit.
A v2 version of this patch will be sent later to fix this issue.
Thank you for pointing out my mistake.

Regards,
Zhipeng

> 
> -- 
> With Best Regards,
> Andy Shevchenko

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

end of thread, other threads:[~2024-01-18 15:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-12  8:34 [PATCH] media: atomisp: ssh_css: Fix a null-pointer dereference in load_video_binaries Zhipeng Lu
2024-01-12  8:49 ` Hans de Goede
2024-01-12 18:27   ` Andy Shevchenko
     [not found]     ` <17d22c9e.4900.18d162090d8.Coremail.alexious@zju.edu.cn>
2024-01-17 20:50       ` Andy Shevchenko
2024-01-18 15:10         ` alexious

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®