* [PATCH] drm/amdgpu: unmap GART dma pages before free
@ 2026-09-22 15:38 Michail Tatas
2026-09-22 15:46 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Michail Tatas @ 2026-09-22 15:38 UTC (permalink / raw)
To: alexander.deucher, christian.koenig, airlied, simona
Cc: amd-gfx, dri-devel, linux-kernel
amdgpu_gart_table_ram_alloc() maps the GART dma pages
and neither the error path nor amdgpu_gart_table_ram_free()
unmaps those pages before freeing them, which could leave
the device writing to freed memory.
Fix by unmapping the GART dma pages before freeing them.
Signed-off-by: Michail Tatas <michail.tatas@gmail.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
index c4c21dbbbdbf..780fb01530e6 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
@@ -209,6 +209,8 @@ int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev)
error_resv:
amdgpu_bo_unreserve(bo);
error:
+ dma_unmap_page(&adev->pdev->dev, sg_dma_address(sg->sgl), adev->gart.table_size,
+ DMA_BIDIRECTIONAL);
amdgpu_bo_unref(&bo);
if (sg) {
sg_free_table(sg);
@@ -240,6 +242,8 @@ void amdgpu_gart_table_ram_free(struct amdgpu_device *adev)
amdgpu_bo_unreserve(adev->gart.bo);
}
amdgpu_bo_unref(&adev->gart.bo);
+ dma_unmap_page(&adev->pdev->dev, sg_dma_address(sg->sgl), adev->gart.table_size,
+ DMA_BIDIRECTIONAL);
sg_free_table(sg);
kfree(sg);
p = virt_to_page(adev->gart.ptr);
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] drm/amdgpu: unmap GART dma pages before free
2026-09-22 15:38 [PATCH] drm/amdgpu: unmap GART dma pages before free Michail Tatas
@ 2026-09-22 15:46 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-09-22 15:46 UTC (permalink / raw)
To: Michail Tatas; +Cc: dri-devel
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] drm/amdgpu: NULL pointer dereference in amdgpu_gart_table_ram_alloc error path
--
commit cffcb1919743d55f9dc644f758abf99d4187be7c
Author: Michail Tatas <michail.tatas@gmail.com>
drm/amdgpu: unmap GART dma pages before free
This commit unmaps the GART dma pages before freeing them to avoid leaving
the device writing to freed memory.
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
> index c4c21dbbbdbf8..780fb01530e69 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
[ ... ]
> @@ -209,6 +209,8 @@ int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev)
> error_resv:
> amdgpu_bo_unreserve(bo);
> error:
> + dma_unmap_page(&adev->pdev->dev, sg_dma_address(sg->sgl), adev->gart.table_size,
> + DMA_BIDIRECTIONAL);
[Severity: High]
Can this cause a NULL pointer dereference during memory pressure?
If memory allocation fails earlier in amdgpu_gart_table_ram_alloc(),
sg is set to NULL and execution jumps to the error label:
sg = kmalloc_obj(*sg);
if (!sg) {
ret = -ENOMEM;
goto error;
}
The new dma_unmap_page() call unconditionally accesses sg->sgl at the error
label. If the execution arrived here due to the allocation failure above,
dereferencing sg->sgl will crash.
Additionally, if sg_alloc_table() fails, sg is allocated but sg->sgl may be
uninitialized when accessed here.
> amdgpu_bo_unref(&bo);
> if (sg) {
> sg_free_table(sg);
--
Sashiko AI review · https://sashiko.dev/#/patchset/arKhDFCSoPDNYaxX@michalis-linux?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-22 15:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-22 15:38 [PATCH] drm/amdgpu: unmap GART dma pages before free Michail Tatas
2026-09-22 15:46 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox