Skip to contentSkip to conversation

drm/amdgpu: fix amdgpu_cs_p1_user_fence

PATCH In review Alex Deucher 2 participants 2 messages Sep 18, 2023 – Sep 20, 2023

Subsystems (3)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/1 drm/amdgpu: fix amdgpu_cs_p1_user_fence

From: Christian König <[email protected]>

The offset is just 32bits here so this can potentially overflow if somebody specifies a large value. Instead reduce the size to calculate the last possible offset.

The error handling path incorrectly drops the reference to the user fence BO resulting in potential reference count underflow.

(cherry picked from commit 35588314e963938dfdcdb792c9170108399377d6)

---

This is a backport of 35588314e963 ("drm/amdgpu: fix amdgpu_cs_p1_user_fence") to 6.5 and older stable kernels because the original patch does not apply cleanly as is.

 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +4 -14
index fb78a8f47587..946d031d2520 100644
@@ -127,7 +127,6 @@ static int amdgpu_cs_p1_user_fence(struct amdgpu_cs_parser *p,
 	struct drm_gem_object *gobj;
 	struct amdgpu_bo *bo;
 	unsigned long size;
-	int r;
 
 	gobj = drm_gem_object_lookup(p->filp, data->handle);
 	if (gobj == NULL)
@@ -139,23 +138,14 @@ static int amdgpu_cs_p1_user_fence(struct amdgpu_cs_parser *p,
 	drm_gem_object_put(gobj);
 
 	size = amdgpu_bo_size(bo);
-	if (size != PAGE_SIZE || (data->offset + 8) > size) {
-		r = -EINVAL;
-		goto error_unref;
-	}
+	if (size != PAGE_SIZE || data->offset > (size - 8))
+		return -EINVAL;
 
-	if (amdgpu_ttm_tt_get_usermm(bo->tbo.ttm)) {
-		r = -EINVAL;
-		goto error_unref;
-	}
+	if (amdgpu_ttm_tt_get_usermm(bo->tbo.ttm))
+		return -EINVAL;
 
 	*offset = data->offset;
-
 	return 0;
-
-error_unref:
-	amdgpu_bo_unref(&bo);
-	return r;
 }
 
 static int amdgpu_cs_p1_bo_handles(struct amdgpu_cs_parser *p,
Signature · 1 line
2.41.0
maintainer
#1 lore raw
Quoted 14 lines · Alex Deucher

From: Christian König <[email protected]>

The offset is just 32bits here so this can potentially overflow if somebody specifies a large value. Instead reduce the size to calculate the last possible offset.

The error handling path incorrectly drops the reference to the user fence BO resulting in potential reference count underflow.

(cherry picked from commit 35588314e963938dfdcdb792c9170108399377d6)
Quoted 8 lines

---

This is a backport of 35588314e963 ("drm/amdgpu: fix amdgpu_cs_p1_user_fence") to 6.5 and older stable kernels because the original patch does not apply cleanly as is.

 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)

Now queued up, thanks.

greg k-h