dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dma-buf: Fix NULL pointer dereference in sanitycheck()
@ 2024-03-19 23:15 Pavel Sakharov
  2024-03-20  8:37 ` [Linaro-mm-sig] " Christian König
  0 siblings, 1 reply; 2+ messages in thread
From: Pavel Sakharov @ 2024-03-19 23:15 UTC (permalink / raw)
  To: Christian König
  Cc: Pavel Sakharov, Sumit Semwal, Arvind Yadav, linux-media,
	dri-devel, linaro-mm-sig, linux-kernel, Fedor Pchelkin,
	lvc-project

If due to a memory allocation failure mock_chain() returns NULL, it is
passed to dma_fence_enable_sw_signaling() resulting in NULL pointer
dereference there.

Call dma_fence_enable_sw_signaling() only if mock_chain() succeeds.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: d62c43a953ce ("dma-buf: Enable signaling on fence for selftests")
Signed-off-by: Pavel Sakharov <p.sakharov@ispras.ru>

---
 drivers/dma-buf/st-dma-fence-chain.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/dma-buf/st-dma-fence-chain.c b/drivers/dma-buf/st-dma-fence-chain.c
index 9c2a0c082a76..ed4b323886e4 100644
--- a/drivers/dma-buf/st-dma-fence-chain.c
+++ b/drivers/dma-buf/st-dma-fence-chain.c
@@ -84,11 +84,11 @@ static int sanitycheck(void *arg)
 		return -ENOMEM;

 	chain = mock_chain(NULL, f, 1);
-	if (!chain)
+	if (chain)
+		dma_fence_enable_sw_signaling(chain);
+	else
 		err = -ENOMEM;

-	dma_fence_enable_sw_signaling(chain);
-
 	dma_fence_signal(f);
 	dma_fence_put(f);

--
2.44.0


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

* Re: [Linaro-mm-sig] [PATCH] dma-buf: Fix NULL pointer dereference in sanitycheck()
  2024-03-19 23:15 [PATCH] dma-buf: Fix NULL pointer dereference in sanitycheck() Pavel Sakharov
@ 2024-03-20  8:37 ` Christian König
  0 siblings, 0 replies; 2+ messages in thread
From: Christian König @ 2024-03-20  8:37 UTC (permalink / raw)
  To: Pavel Sakharov, Christian König
  Cc: Sumit Semwal, Arvind Yadav, linux-media, dri-devel,
	linaro-mm-sig, linux-kernel, Fedor Pchelkin, lvc-project

Am 20.03.24 um 00:15 schrieb Pavel Sakharov:
> If due to a memory allocation failure mock_chain() returns NULL, it is
> passed to dma_fence_enable_sw_signaling() resulting in NULL pointer
> dereference there.
>
> Call dma_fence_enable_sw_signaling() only if mock_chain() succeeds.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: d62c43a953ce ("dma-buf: Enable signaling on fence for selftests")
> Signed-off-by: Pavel Sakharov <p.sakharov@ispras.ru>

Reviewed-by: Christian König <christian.koenig@amd.com>

Going to push it to drm-misc-fixes in a minute.

Thanks,
Christian.

>
> ---
>   drivers/dma-buf/st-dma-fence-chain.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/dma-buf/st-dma-fence-chain.c b/drivers/dma-buf/st-dma-fence-chain.c
> index 9c2a0c082a76..ed4b323886e4 100644
> --- a/drivers/dma-buf/st-dma-fence-chain.c
> +++ b/drivers/dma-buf/st-dma-fence-chain.c
> @@ -84,11 +84,11 @@ static int sanitycheck(void *arg)
>   		return -ENOMEM;
>
>   	chain = mock_chain(NULL, f, 1);
> -	if (!chain)
> +	if (chain)
> +		dma_fence_enable_sw_signaling(chain);
> +	else
>   		err = -ENOMEM;
>
> -	dma_fence_enable_sw_signaling(chain);
> -
>   	dma_fence_signal(f);
>   	dma_fence_put(f);
>
> --
> 2.44.0
>
> _______________________________________________
> Linaro-mm-sig mailing list -- linaro-mm-sig@lists.linaro.org
> To unsubscribe send an email to linaro-mm-sig-leave@lists.linaro.org


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

end of thread, other threads:[~2024-03-20  8:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-19 23:15 [PATCH] dma-buf: Fix NULL pointer dereference in sanitycheck() Pavel Sakharov
2024-03-20  8:37 ` [Linaro-mm-sig] " Christian König

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