Skip to content

Commit 3558831

Browse files
ChristianKoenigAMDalexdeucher
authored andcommitted
drm/amdgpu: fix amdgpu_cs_p1_user_fence
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. Signed-off-by: Christian König <christian.koenig@amd.com> Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> Cc: stable@vger.kernel.org
1 parent 46528db commit 3558831

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ static int amdgpu_cs_p1_user_fence(struct amdgpu_cs_parser *p,
127127
{
128128
struct drm_gem_object *gobj;
129129
unsigned long size;
130-
int r;
131130

132131
gobj = drm_gem_object_lookup(p->filp, data->handle);
133132
if (gobj == NULL)
@@ -137,23 +136,14 @@ static int amdgpu_cs_p1_user_fence(struct amdgpu_cs_parser *p,
137136
drm_gem_object_put(gobj);
138137

139138
size = amdgpu_bo_size(p->uf_bo);
140-
if (size != PAGE_SIZE || (data->offset + 8) > size) {
141-
r = -EINVAL;
142-
goto error_unref;
143-
}
139+
if (size != PAGE_SIZE || data->offset > (size - 8))
140+
return -EINVAL;
144141

145-
if (amdgpu_ttm_tt_get_usermm(p->uf_bo->tbo.ttm)) {
146-
r = -EINVAL;
147-
goto error_unref;
148-
}
142+
if (amdgpu_ttm_tt_get_usermm(p->uf_bo->tbo.ttm))
143+
return -EINVAL;
149144

150145
*offset = data->offset;
151-
152146
return 0;
153-
154-
error_unref:
155-
amdgpu_bo_unref(&p->uf_bo);
156-
return r;
157147
}
158148

159149
static int amdgpu_cs_p1_bo_handles(struct amdgpu_cs_parser *p,

0 commit comments

Comments
 (0)