Skip to content

Commit ced5c30

Browse files
avasummeralexdeucher
authored andcommitted
drm/amdgpu/userq: fix memory leak in MQD creation error paths
In mes_userq_mqd_create(), the memdup_user() allocations for IP-specific MQD structs are not freed when subsequent VA validation fails. The goto free_mqd label only cleans up the MQD BO object and userq_props. Fix by adding kfree() before each goto free_mqd on VA validation failure in the COMPUTE, GFX, and SDMA branches. Fixes: 9e46b8b ("drm/amdgpu: validate userq buffer virtual address and size") Reported-by: Yuhao Jiang <danisjiang@gmail.com> Signed-off-by: Junrui Luo <moonafterrain@outlook.com> Reviewed-by: Prike Liang <Prike.Liang@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit 27f5ff9) Cc: stable@vger.kernel.org
1 parent 6caeace commit ced5c30

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,10 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
324324

325325
r = amdgpu_userq_input_va_validate(adev, queue, compute_mqd->eop_va,
326326
2048);
327-
if (r)
327+
if (r) {
328+
kfree(compute_mqd);
328329
goto free_mqd;
330+
}
329331

330332
userq_props->eop_gpu_addr = compute_mqd->eop_va;
331333
userq_props->hqd_pipe_priority = AMDGPU_GFX_PIPE_PRIO_NORMAL;
@@ -365,12 +367,16 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
365367

366368
r = amdgpu_userq_input_va_validate(adev, queue, mqd_gfx_v11->shadow_va,
367369
shadow_info.shadow_size);
368-
if (r)
370+
if (r) {
371+
kfree(mqd_gfx_v11);
369372
goto free_mqd;
373+
}
370374
r = amdgpu_userq_input_va_validate(adev, queue, mqd_gfx_v11->csa_va,
371375
shadow_info.csa_size);
372-
if (r)
376+
if (r) {
377+
kfree(mqd_gfx_v11);
373378
goto free_mqd;
379+
}
374380

375381
kfree(mqd_gfx_v11);
376382
} else if (queue->queue_type == AMDGPU_HW_IP_DMA) {
@@ -390,8 +396,10 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
390396
}
391397
r = amdgpu_userq_input_va_validate(adev, queue, mqd_sdma_v11->csa_va,
392398
32);
393-
if (r)
399+
if (r) {
400+
kfree(mqd_sdma_v11);
394401
goto free_mqd;
402+
}
395403

396404
userq_props->csa_addr = mqd_sdma_v11->csa_va;
397405
kfree(mqd_sdma_v11);

0 commit comments

Comments
 (0)