gpu: drm: drm_mm: Fix a sleep-in-atomic-context bug in show_leaks()
Subsystems (2)
PATCH 1/1 gpu: drm: drm_mm: Fix a sleep-in-atomic-context bug in show_leaks()
The driver may sleep with holding a spinlock.
The function call paths (from bottom to top) in Linux-4.16 are:
[FUNC] kmalloc(GFP_KERNEL) drivers/gpu/drm/drm_mm.c, 130:
kmalloc in show_leaksdrivers/gpu/drm/drm_mm.c, 913:
show_leaks in drm_mm_takedowndrivers/gpu/drm/drm_vma_manager.c, 107:
drm_mm_takedown in drm_vma_offset_manager_destroydrivers/gpu/drm/drm_vma_manager.c, 106:
_raw_write_lock in drm_vma_offset_manager_destroy
[FUNC] kmalloc(GFP_KERNEL)drivers/gpu/drm/drm_mm.c, 130:
kmalloc in show_leaksdrivers/gpu/drm/drm_mm.c, 913:
show_leaks in drm_mm_takedowndrivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c, 71:
drm_mm_takedown in amdgpu_vram_mgr_finidrivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c, 70:
spin_lock in amdgpu_vram_mgr_fini
[FUNC] kmalloc(GFP_KERNEL)drivers/gpu/drm/drm_mm.c, 130:
kmalloc in show_leaksdrivers/gpu/drm/drm_mm.c, 913:
show_leaks in drm_mm_takedowndrivers/gpu/drm/ttm/ttm_bo_manager.c, 128:
drm_mm_takedown in ttm_bo_man_takedowndrivers/gpu/drm/ttm/ttm_bo_manager.c, 126:
spin_lock in ttm_bo_man_takedown
To fix this bug, GFP_KERNEL is replaced with GFP_ATOMIC.
This bug is found by my static analysis tool DSAC.
--- drivers/gpu/drm/drm_mm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_mm.c +1 -1
@@ -127,7 +127,7 @@ static void show_leaks(struct drm_mm *mm)unsigned long entries[STACKDEPTH ];char *buf; - buf =kmalloc (BUFSZ ,GFP_KERNEL ); + buf =kmalloc (BUFSZ ,GFP_ATOMIC );if (!buf)return ;
Signature · 1 line
2.17.0
Quoting Jia-Ju Bai (2018-09-01 13:20:41)
Quoted 34 lines
The driver may sleep with holding a spinlock.
The function call paths (from bottom to top) in Linux-4.16 are:
[FUNC]
kmalloc(GFP_KERNEL)drivers/gpu/drm/drm_mm.c, 130:
kmalloc inshow_leaksdrivers/gpu/drm/drm_mm.c, 913:
show_leaksindrm_mm_takedowndrivers/gpu/drm/drm_vma_manager.c, 107:
drm_mm_takedownindrm_vma_offset_manager_destroydrivers/gpu/drm/drm_vma_manager.c, 106:
_raw_write_lockindrm_vma_offset_manager_destroy[FUNC]
kmalloc(GFP_KERNEL)drivers/gpu/drm/drm_mm.c, 130:
kmalloc inshow_leaksdrivers/gpu/drm/drm_mm.c, 913:
show_leaksindrm_mm_takedowndrivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c, 71:
drm_mm_takedowninamdgpu_vram_mgr_finidrivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c, 70:
spin_lockinamdgpu_vram_mgr_fini[FUNC]
kmalloc(GFP_KERNEL)drivers/gpu/drm/drm_mm.c, 130:
kmalloc inshow_leaksdrivers/gpu/drm/drm_mm.c, 913:
show_leaksindrm_mm_takedowndrivers/gpu/drm/ttm/ttm_bo_manager.c, 128:
drm_mm_takedowninttm_bo_man_takedowndrivers/gpu/drm/ttm/ttm_bo_manager.c, 126:
spin_lockinttm_bo_man_takedown
Quoted 1 line
To fix this bug,
GFP_KERNELis replaced withGFP_ATOMIC.
The bug are above, since those spinlocks do not protect the data and imply use-after-free.
-Chris
Quoted 35 lines · Chris Wilson
Quoting Jia-Ju Bai (2018-09-01 13:20:41)
Quoted 34 lines
The driver may sleep with holding a spinlock.
The function call paths (from bottom to top) in Linux-4.16 are:
[FUNC]
kmalloc(GFP_KERNEL)drivers/gpu/drm/drm_mm.c, 130:
kmalloc inshow_leaksdrivers/gpu/drm/drm_mm.c, 913:
show_leaksindrm_mm_takedowndrivers/gpu/drm/drm_vma_manager.c, 107:
drm_mm_takedownindrm_vma_offset_manager_destroydrivers/gpu/drm/drm_vma_manager.c, 106:
_raw_write_lockindrm_vma_offset_manager_destroy[FUNC]
kmalloc(GFP_KERNEL)drivers/gpu/drm/drm_mm.c, 130:
kmalloc inshow_leaksdrivers/gpu/drm/drm_mm.c, 913:
show_leaksindrm_mm_takedowndrivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c, 71:
drm_mm_takedowninamdgpu_vram_mgr_finidrivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c, 70:
spin_lockinamdgpu_vram_mgr_fini[FUNC]
kmalloc(GFP_KERNEL)drivers/gpu/drm/drm_mm.c, 130:
kmalloc inshow_leaksdrivers/gpu/drm/drm_mm.c, 913:
show_leaksindrm_mm_takedowndrivers/gpu/drm/ttm/ttm_bo_manager.c, 128:
drm_mm_takedowninttm_bo_man_takedowndrivers/gpu/drm/ttm/ttm_bo_manager.c, 126:
spin_lockinttm_bo_man_takedown
Quoted 4 lines
Quoted 1 line
To fix this bug,
GFP_KERNELis replaced withGFP_ATOMIC.The bug are above, since those spinlocks do not protect the data and imply use-after-free.
Adding amdgpu, since that's where the bug seems to be. -Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Am 03.09.2018 um 09:52 schrieb Daniel Vetter:
Quoted 36 lines · Chris Wilson
Quoted 35 lines
Quoting Jia-Ju Bai (2018-09-01 13:20:41)
Quoted 34 lines
The driver may sleep with holding a spinlock.
The function call paths (from bottom to top) in Linux-4.16 are:
[FUNC]
kmalloc(GFP_KERNEL)drivers/gpu/drm/drm_mm.c, 130:
kmalloc inshow_leaksdrivers/gpu/drm/drm_mm.c, 913:
show_leaksindrm_mm_takedowndrivers/gpu/drm/drm_vma_manager.c, 107:
drm_mm_takedownindrm_vma_offset_manager_destroydrivers/gpu/drm/drm_vma_manager.c, 106:
_raw_write_lockindrm_vma_offset_manager_destroy[FUNC]
kmalloc(GFP_KERNEL)drivers/gpu/drm/drm_mm.c, 130:
kmalloc inshow_leaksdrivers/gpu/drm/drm_mm.c, 913:
show_leaksindrm_mm_takedowndrivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c, 71:
drm_mm_takedowninamdgpu_vram_mgr_finidrivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c, 70:
spin_lockinamdgpu_vram_mgr_fini[FUNC]
kmalloc(GFP_KERNEL)drivers/gpu/drm/drm_mm.c, 130:
kmalloc inshow_leaksdrivers/gpu/drm/drm_mm.c, 913:
show_leaksindrm_mm_takedowndrivers/gpu/drm/ttm/ttm_bo_manager.c, 128:
drm_mm_takedowninttm_bo_man_takedowndrivers/gpu/drm/ttm/ttm_bo_manager.c, 126:
spin_lockinttm_bo_man_takedown
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
To fix this bug,
GFP_KERNELis replaced withGFP_ATOMIC.The bug are above, since those spinlocks do not protect the data and imply use-after-free.
Adding amdgpu, since that's where the bug seems to be.
When we have use after free we might have concurrent uses as well.
I think taking the lock here is probably a good idea if you don't want to accidentally access freed memory in show_leaks.
So Chris change sounds valid to me.
Christian.
Quoted 1 line
-Daniel
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx