amd-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] drm/radeon: Initialize fences array entries in radeon_sa_bo_next_hole
@ 2022-06-07 15:19 Xiaohui Zhang
  2022-06-07 18:36 ` Alex Deucher
  2022-06-08  8:35 ` Christian König
  0 siblings, 2 replies; 3+ messages in thread
From: Xiaohui Zhang @ 2022-06-07 15:19 UTC (permalink / raw)
  To: Xiaohui Zhang, Alex Deucher, christian.koenig, Xinhui.Pan,
	David Airlie, Daniel Vetter, amd-gfx, dri-devel, linux-kernel

Similar to the handling of amdgpu_sa_bo_next_hole in commit 6a15f3ff19a8
("drm/amdgpu: Initialize fences array entries in amdgpu_sa_bo_next_hole"),
we thought a patch might be needed here as well.

The entries were only initialized once in radeon_sa_bo_new. If a fence
wasn't signalled yet in the first radeon_sa_bo_next_hole call, but then
got signalled before a later radeon_sa_bo_next_hole call, it could
destroy the fence but leave its pointer in the array, resulting in
use-after-free in radeon_sa_bo_new.

Signed-off-by: Xiaohui Zhang <xiaohuizhang@ruc.edu.cn>
---
 drivers/gpu/drm/radeon/radeon_sa.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon_sa.c b/drivers/gpu/drm/radeon/radeon_sa.c
index 310c322c7112..0981948bd9ed 100644
--- a/drivers/gpu/drm/radeon/radeon_sa.c
+++ b/drivers/gpu/drm/radeon/radeon_sa.c
@@ -267,6 +267,8 @@ static bool radeon_sa_bo_next_hole(struct radeon_sa_manager *sa_manager,
 	for (i = 0; i < RADEON_NUM_RINGS; ++i) {
 		struct radeon_sa_bo *sa_bo;
 
+		fences[i] = NULL;
+
 		if (list_empty(&sa_manager->flist[i])) {
 			continue;
 		}
@@ -332,10 +334,8 @@ int radeon_sa_bo_new(struct radeon_device *rdev,
 
 	spin_lock(&sa_manager->wq.lock);
 	do {
-		for (i = 0; i < RADEON_NUM_RINGS; ++i) {
-			fences[i] = NULL;
+		for (i = 0; i < RADEON_NUM_RINGS; ++i)
 			tries[i] = 0;
-		}
 
 		do {
 			radeon_sa_bo_try_free(sa_manager);
-- 
2.17.1


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

* Re: [PATCH 1/1] drm/radeon: Initialize fences array entries in radeon_sa_bo_next_hole
  2022-06-07 15:19 [PATCH 1/1] drm/radeon: Initialize fences array entries in radeon_sa_bo_next_hole Xiaohui Zhang
@ 2022-06-07 18:36 ` Alex Deucher
  2022-06-08  8:35 ` Christian König
  1 sibling, 0 replies; 3+ messages in thread
From: Alex Deucher @ 2022-06-07 18:36 UTC (permalink / raw)
  To: Xiaohui Zhang
  Cc: David Airlie, xinhui pan, LKML, amd-gfx list,
	Maling list - DRI developers, Daniel Vetter, Alex Deucher,
	Christian Koenig

Applied.  Thanks!

Alex

On Tue, Jun 7, 2022 at 12:04 PM Xiaohui Zhang <xiaohuizhang@ruc.edu.cn> wrote:
>
> Similar to the handling of amdgpu_sa_bo_next_hole in commit 6a15f3ff19a8
> ("drm/amdgpu: Initialize fences array entries in amdgpu_sa_bo_next_hole"),
> we thought a patch might be needed here as well.
>
> The entries were only initialized once in radeon_sa_bo_new. If a fence
> wasn't signalled yet in the first radeon_sa_bo_next_hole call, but then
> got signalled before a later radeon_sa_bo_next_hole call, it could
> destroy the fence but leave its pointer in the array, resulting in
> use-after-free in radeon_sa_bo_new.
>
> Signed-off-by: Xiaohui Zhang <xiaohuizhang@ruc.edu.cn>
> ---
>  drivers/gpu/drm/radeon/radeon_sa.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_sa.c b/drivers/gpu/drm/radeon/radeon_sa.c
> index 310c322c7112..0981948bd9ed 100644
> --- a/drivers/gpu/drm/radeon/radeon_sa.c
> +++ b/drivers/gpu/drm/radeon/radeon_sa.c
> @@ -267,6 +267,8 @@ static bool radeon_sa_bo_next_hole(struct radeon_sa_manager *sa_manager,
>         for (i = 0; i < RADEON_NUM_RINGS; ++i) {
>                 struct radeon_sa_bo *sa_bo;
>
> +               fences[i] = NULL;
> +
>                 if (list_empty(&sa_manager->flist[i])) {
>                         continue;
>                 }
> @@ -332,10 +334,8 @@ int radeon_sa_bo_new(struct radeon_device *rdev,
>
>         spin_lock(&sa_manager->wq.lock);
>         do {
> -               for (i = 0; i < RADEON_NUM_RINGS; ++i) {
> -                       fences[i] = NULL;
> +               for (i = 0; i < RADEON_NUM_RINGS; ++i)
>                         tries[i] = 0;
> -               }
>
>                 do {
>                         radeon_sa_bo_try_free(sa_manager);
> --
> 2.17.1
>

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

* Re: [PATCH 1/1] drm/radeon: Initialize fences array entries in radeon_sa_bo_next_hole
  2022-06-07 15:19 [PATCH 1/1] drm/radeon: Initialize fences array entries in radeon_sa_bo_next_hole Xiaohui Zhang
  2022-06-07 18:36 ` Alex Deucher
@ 2022-06-08  8:35 ` Christian König
  1 sibling, 0 replies; 3+ messages in thread
From: Christian König @ 2022-06-08  8:35 UTC (permalink / raw)
  To: Xiaohui Zhang, Alex Deucher, Xinhui.Pan, David Airlie,
	Daniel Vetter, amd-gfx, dri-devel, linux-kernel

Am 07.06.22 um 17:19 schrieb Xiaohui Zhang:
> Similar to the handling of amdgpu_sa_bo_next_hole in commit 6a15f3ff19a8
> ("drm/amdgpu: Initialize fences array entries in amdgpu_sa_bo_next_hole"),
> we thought a patch might be needed here as well.
>
> The entries were only initialized once in radeon_sa_bo_new. If a fence
> wasn't signalled yet in the first radeon_sa_bo_next_hole call, but then
> got signalled before a later radeon_sa_bo_next_hole call, it could
> destroy the fence but leave its pointer in the array, resulting in
> use-after-free in radeon_sa_bo_new.

I would rather like to see the sub allocator moved into a common drm helper.

Regards,
Christian.

>
> Signed-off-by: Xiaohui Zhang <xiaohuizhang@ruc.edu.cn>
> ---
>   drivers/gpu/drm/radeon/radeon_sa.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_sa.c b/drivers/gpu/drm/radeon/radeon_sa.c
> index 310c322c7112..0981948bd9ed 100644
> --- a/drivers/gpu/drm/radeon/radeon_sa.c
> +++ b/drivers/gpu/drm/radeon/radeon_sa.c
> @@ -267,6 +267,8 @@ static bool radeon_sa_bo_next_hole(struct radeon_sa_manager *sa_manager,
>   	for (i = 0; i < RADEON_NUM_RINGS; ++i) {
>   		struct radeon_sa_bo *sa_bo;
>   
> +		fences[i] = NULL;
> +
>   		if (list_empty(&sa_manager->flist[i])) {
>   			continue;
>   		}
> @@ -332,10 +334,8 @@ int radeon_sa_bo_new(struct radeon_device *rdev,
>   
>   	spin_lock(&sa_manager->wq.lock);
>   	do {
> -		for (i = 0; i < RADEON_NUM_RINGS; ++i) {
> -			fences[i] = NULL;
> +		for (i = 0; i < RADEON_NUM_RINGS; ++i)
>   			tries[i] = 0;
> -		}
>   
>   		do {
>   			radeon_sa_bo_try_free(sa_manager);


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

end of thread, other threads:[~2022-06-08  8:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-07 15:19 [PATCH 1/1] drm/radeon: Initialize fences array entries in radeon_sa_bo_next_hole Xiaohui Zhang
2022-06-07 18:36 ` Alex Deucher
2022-06-08  8:35 ` 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).