* [PATCH] gpu: drm: drm_mm: Fix a sleep-in-atomic-context bug in show_leaks()
@ 2018-09-01 12:20 Jia-Ju Bai
2018-09-01 12:32 ` Chris Wilson
0 siblings, 1 reply; 4+ messages in thread
From: Jia-Ju Bai @ 2018-09-01 12:20 UTC (permalink / raw)
To: gustavo, maarten.lankhorst, seanpaul, airlied
Cc: dri-devel, linux-kernel, Jia-Ju Bai
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_leaks
drivers/gpu/drm/drm_mm.c, 913:
show_leaks in drm_mm_takedown
drivers/gpu/drm/drm_vma_manager.c, 107:
drm_mm_takedown in drm_vma_offset_manager_destroy
drivers/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_leaks
drivers/gpu/drm/drm_mm.c, 913:
show_leaks in drm_mm_takedown
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c, 71:
drm_mm_takedown in amdgpu_vram_mgr_fini
drivers/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_leaks
drivers/gpu/drm/drm_mm.c, 913:
show_leaks in drm_mm_takedown
drivers/gpu/drm/ttm/ttm_bo_manager.c, 128:
drm_mm_takedown in ttm_bo_man_takedown
drivers/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.
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
drivers/gpu/drm/drm_mm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c
index 3166026a1874..2486121a78d4 100644
--- a/drivers/gpu/drm/drm_mm.c
+++ b/drivers/gpu/drm/drm_mm.c
@@ -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;
--
2.17.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] gpu: drm: drm_mm: Fix a sleep-in-atomic-context bug in show_leaks()
2018-09-01 12:20 [PATCH] gpu: drm: drm_mm: Fix a sleep-in-atomic-context bug in show_leaks() Jia-Ju Bai
@ 2018-09-01 12:32 ` Chris Wilson
2018-09-03 7:52 ` Daniel Vetter
0 siblings, 1 reply; 4+ messages in thread
From: Chris Wilson @ 2018-09-01 12:32 UTC (permalink / raw)
To: Jia-Ju Bai, airlied, gustavo, maarten.lankhorst, seanpaul
Cc: dri-devel, linux-kernel, Jia-Ju Bai
Quoting Jia-Ju Bai (2018-09-01 13:20:41)
> 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_leaks
> drivers/gpu/drm/drm_mm.c, 913:
> show_leaks in drm_mm_takedown
> drivers/gpu/drm/drm_vma_manager.c, 107:
> drm_mm_takedown in drm_vma_offset_manager_destroy
> drivers/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_leaks
> drivers/gpu/drm/drm_mm.c, 913:
> show_leaks in drm_mm_takedown
> drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c, 71:
> drm_mm_takedown in amdgpu_vram_mgr_fini
> drivers/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_leaks
> drivers/gpu/drm/drm_mm.c, 913:
> show_leaks in drm_mm_takedown
> drivers/gpu/drm/ttm/ttm_bo_manager.c, 128:
> drm_mm_takedown in ttm_bo_man_takedown
> drivers/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.
The bug are above, since those spinlocks do not protect the data and
imply use-after-free.
-Chris
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] gpu: drm: drm_mm: Fix a sleep-in-atomic-context bug in show_leaks()
2018-09-01 12:32 ` Chris Wilson
@ 2018-09-03 7:52 ` Daniel Vetter
2018-09-03 12:05 ` Christian König
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Vetter @ 2018-09-03 7:52 UTC (permalink / raw)
To: Chris Wilson
Cc: Jia-Ju Bai, airlied, gustavo, maarten.lankhorst, seanpaul,
linux-kernel, dri-devel, Alex Deucher, amd-gfx, David Zhou,
Christian König
On Sat, Sep 01, 2018 at 01:32:54PM +0100, Chris Wilson wrote:
> Quoting Jia-Ju Bai (2018-09-01 13:20:41)
> > 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_leaks
> > drivers/gpu/drm/drm_mm.c, 913:
> > show_leaks in drm_mm_takedown
> > drivers/gpu/drm/drm_vma_manager.c, 107:
> > drm_mm_takedown in drm_vma_offset_manager_destroy
> > drivers/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_leaks
> > drivers/gpu/drm/drm_mm.c, 913:
> > show_leaks in drm_mm_takedown
> > drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c, 71:
> > drm_mm_takedown in amdgpu_vram_mgr_fini
> > drivers/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_leaks
> > drivers/gpu/drm/drm_mm.c, 913:
> > show_leaks in drm_mm_takedown
> > drivers/gpu/drm/ttm/ttm_bo_manager.c, 128:
> > drm_mm_takedown in ttm_bo_man_takedown
> > drivers/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.
>
> 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
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] gpu: drm: drm_mm: Fix a sleep-in-atomic-context bug in show_leaks()
2018-09-03 7:52 ` Daniel Vetter
@ 2018-09-03 12:05 ` Christian König
0 siblings, 0 replies; 4+ messages in thread
From: Christian König @ 2018-09-03 12:05 UTC (permalink / raw)
To: Chris Wilson, Jia-Ju Bai, airlied, gustavo, maarten.lankhorst,
seanpaul, linux-kernel, dri-devel, Alex Deucher, amd-gfx,
David Zhou, Christian König
Am 03.09.2018 um 09:52 schrieb Daniel Vetter:
> On Sat, Sep 01, 2018 at 01:32:54PM +0100, Chris Wilson wrote:
>> Quoting Jia-Ju Bai (2018-09-01 13:20:41)
>>> 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_leaks
>>> drivers/gpu/drm/drm_mm.c, 913:
>>> show_leaks in drm_mm_takedown
>>> drivers/gpu/drm/drm_vma_manager.c, 107:
>>> drm_mm_takedown in drm_vma_offset_manager_destroy
>>> drivers/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_leaks
>>> drivers/gpu/drm/drm_mm.c, 913:
>>> show_leaks in drm_mm_takedown
>>> drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c, 71:
>>> drm_mm_takedown in amdgpu_vram_mgr_fini
>>> drivers/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_leaks
>>> drivers/gpu/drm/drm_mm.c, 913:
>>> show_leaks in drm_mm_takedown
>>> drivers/gpu/drm/ttm/ttm_bo_manager.c, 128:
>>> drm_mm_takedown in ttm_bo_man_takedown
>>> drivers/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.
>> 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.
> -Daniel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-09-03 12:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-01 12:20 [PATCH] gpu: drm: drm_mm: Fix a sleep-in-atomic-context bug in show_leaks() Jia-Ju Bai
2018-09-01 12:32 ` Chris Wilson
2018-09-03 7:52 ` Daniel Vetter
2018-09-03 12:05 ` Christian König
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).