The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] drm/ttm: fix null-ptr-deref in radeon_ttm_tt_populate()
@ 2023-04-17 14:34 Nikita Zhandarovich
  2023-04-17 14:42 ` Christian König
  0 siblings, 1 reply; 3+ messages in thread
From: Nikita Zhandarovich @ 2023-04-17 14:34 UTC (permalink / raw)
  To: Alex Deucher
  Cc: Nikita Zhandarovich, Christian König, Pan, Xinhui,
	David Airlie, Daniel Vetter, Jerome Glisse, amd-gfx, dri-devel,
	linux-kernel, lvc-project

Currently, drm_prime_sg_to_page_addr_arrays() dereferences 'gtt->ttm'
without ensuring that 'gtt' (and therefore 'gtt->tmm') is not NULL.

Fix this by testing 'gtt' for NULL value before dereferencing.

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

Fixes: 40f5cf996991 ("drm/radeon: add PRIME support (v2)")
Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
---
 drivers/gpu/drm/radeon/radeon_ttm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index 1e8e287e113c..33d01c3bdee4 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -553,7 +553,7 @@ static int radeon_ttm_tt_populate(struct ttm_device *bdev,
 		return 0;
 	}
 
-	if (slave && ttm->sg) {
+	if (gtt && slave && ttm->sg) {
 		drm_prime_sg_to_dma_addr_array(ttm->sg, gtt->ttm.dma_address,
 					       ttm->num_pages);
 		return 0;
-- 
2.25.1


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

* Re: [PATCH] drm/ttm: fix null-ptr-deref in radeon_ttm_tt_populate()
  2023-04-17 14:34 [PATCH] drm/ttm: fix null-ptr-deref in radeon_ttm_tt_populate() Nikita Zhandarovich
@ 2023-04-17 14:42 ` Christian König
  2023-04-17 14:58   ` Nikita Zhandarovich
  0 siblings, 1 reply; 3+ messages in thread
From: Christian König @ 2023-04-17 14:42 UTC (permalink / raw)
  To: Nikita Zhandarovich, Alex Deucher
  Cc: Pan, Xinhui, David Airlie, Daniel Vetter, Jerome Glisse, amd-gfx,
	dri-devel, linux-kernel, lvc-project



Am 17.04.23 um 16:34 schrieb Nikita Zhandarovich:
> Currently, drm_prime_sg_to_page_addr_arrays() dereferences 'gtt->ttm'
> without ensuring that 'gtt' (and therefore 'gtt->tmm') is not NULL.
>
> Fix this by testing 'gtt' for NULL value before dereferencing.
>
> Found by Linux Verification Center (linuxtesting.org) with static
> analysis tool SVACE.
>
> Fixes: 40f5cf996991 ("drm/radeon: add PRIME support (v2)")
> Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
> ---
>   drivers/gpu/drm/radeon/radeon_ttm.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
> index 1e8e287e113c..33d01c3bdee4 100644
> --- a/drivers/gpu/drm/radeon/radeon_ttm.c
> +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
> @@ -553,7 +553,7 @@ static int radeon_ttm_tt_populate(struct ttm_device *bdev,
>   		return 0;
>   	}
>   
> -	if (slave && ttm->sg) {
> +	if (gtt && slave && ttm->sg) {

The gtt variable is derived from the ttm variable and so never NULL 
here. The only case when this can be NULL is for AGP and IIRC we don't 
support DMA-buf in this case.

>   		drm_prime_sg_to_dma_addr_array(ttm->sg, gtt->ttm.dma_address,

Just use ttm->dma_addresses instead of gtt->ttm.dma_address here to make 
your automated checker happy.

Regards,
Christian.

>   					       ttm->num_pages);
>   		return 0;


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

* Re: [PATCH] drm/ttm: fix null-ptr-deref in radeon_ttm_tt_populate()
  2023-04-17 14:42 ` Christian König
@ 2023-04-17 14:58   ` Nikita Zhandarovich
  0 siblings, 0 replies; 3+ messages in thread
From: Nikita Zhandarovich @ 2023-04-17 14:58 UTC (permalink / raw)
  To: Christian König, Alex Deucher
  Cc: Pan, Xinhui, David Airlie, Daniel Vetter, Jerome Glisse, amd-gfx,
	dri-devel, linux-kernel, lvc-project



On 4/17/23 07:42, Christian König wrote:
> 
> 
> Am 17.04.23 um 16:34 schrieb Nikita Zhandarovich:
>> Currently, drm_prime_sg_to_page_addr_arrays() dereferences 'gtt->ttm'
>> without ensuring that 'gtt' (and therefore 'gtt->tmm') is not NULL.
>>
>> Fix this by testing 'gtt' for NULL value before dereferencing.
>>
>> Found by Linux Verification Center (linuxtesting.org) with static
>> analysis tool SVACE.
>>
>> Fixes: 40f5cf996991 ("drm/radeon: add PRIME support (v2)")
>> Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
>> ---
>>   drivers/gpu/drm/radeon/radeon_ttm.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c
>> b/drivers/gpu/drm/radeon/radeon_ttm.c
>> index 1e8e287e113c..33d01c3bdee4 100644
>> --- a/drivers/gpu/drm/radeon/radeon_ttm.c
>> +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
>> @@ -553,7 +553,7 @@ static int radeon_ttm_tt_populate(struct
>> ttm_device *bdev,
>>           return 0;
>>       }
>>   -    if (slave && ttm->sg) {
>> +    if (gtt && slave && ttm->sg) {
> 
> The gtt variable is derived from the ttm variable and so never NULL
> here. The only case when this can be NULL is for AGP and IIRC we don't
> support DMA-buf in this case.
> 
>>           drm_prime_sg_to_dma_addr_array(ttm->sg, gtt->ttm.dma_address,
> 
> Just use ttm->dma_addresses instead of gtt->ttm.dma_address here to make
> your automated checker happy.
> 
> Regards,
> Christian.
> 
>>                              ttm->num_pages);
>>           return 0;
> 

Thank you for your reply, you are absolutely right.
Apologies for wasting your time.

Nikita

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

end of thread, other threads:[~2023-04-17 14:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-17 14:34 [PATCH] drm/ttm: fix null-ptr-deref in radeon_ttm_tt_populate() Nikita Zhandarovich
2023-04-17 14:42 ` Christian König
2023-04-17 14:58   ` Nikita Zhandarovich

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