fix unmap_vmas() with NULL vma
Subsystems (3)
PATCH 1/1 fix unmap_vmas() with NULL vma
unmap_vmas() with NULL vma causes kernel NULL pointer dereference by vma->mm.
It is happend the following scenario:
1. dup_mm() duplicates mm_struct and ->mmap is NULL
2. dup_mm() calls dup_mmap() to duplicate vmas
3. If dup_mmap() cannot duplicate any vmas due to no enough memory, it returns error and ->mmap is still NULL
4. dup_mm() calls mmput() with the incompletely duplicated mm_struct to deallocate it
5. mmput calls exit_mmap with the mm_struct
6. exit_mmap calls unmap_vmas with NULL vma
--- mm/memory.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
mm/memory.c +5 -1
@@ -899,8 +899,12 @@ unsigned long unmap_vmas(struct mmu_gathunsigned long start = start_addr;spinlock_t *i_mmap_lock = details? details->i_mmap_lock:NULL ;int fullmm = (*tlbp)->fullmm; -struct mm_struct *mm = vma->vm_mm; +struct mm_struct *mm; + +if (!vma) +return start; + mm = vma->vm_mm;mmu_notifier_invalidate_range_start (mm, start_addr, end_addr);for ( ; vma && vma->vm_start < end_addr; vma = vma->vm_next) {unsigned long end;
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 31 lines · Akinobu Mita
unmap_vmas()with NULL vma causes kernel NULL pointer dereference byvma->mm.It is happend the following scenario:
1.
dup_mm()duplicatesmm_structand ->mmap is NULL
2.dup_mm()callsdup_mmap()to duplicate vmas3. If
dup_mmap()cannot duplicate any vmas due to no enough memory, it returns error and ->mmap is still NULL4.
dup_mm()callsmmput()with the incompletely duplicatedmm_structto deallocate it5. mmput calls
exit_mmapwith themm_struct
6.exit_mmapcallsunmap_vmaswith NULL vmaSigned-off-by Akinobu Mita <[email protected]>--- mm/memory.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)Index:
2.6-rc/mm/memory.c
===================================================================mm/memory.c +0
-0@@ -899,8 +899,12 @@ unsigned long unmap_vmas(struct mmu_gathunsigned long start = start_addr;spinlock_t *i_mmap_lock = details? details->i_mmap_lock:NULL ;int fullmm = (*tlbp)->fullmm;
mm/memory.c unsigned long unmap_vmas(struct mmu_gath · line 910
Quoted 10 lines
mm/memory.c +5
-1-struct mm_struct *mm = vma->vm_mm; +struct mm_struct *mm; + +if (!vma) +return start; + mm = vma->vm_mm;mmu_notifier_invalidate_range_start (mm, start_addr, end_addr);for ( ; vma && vma->vm_start < end_addr; vma = vma->vm_next) {unsigned long end;
Why bail out this late? We can save the other stuff in exit_mmap() as well if we have no mmaps.
Granted, the path is dead cold so the extra call overhead doesn't matter but I think the check is logically better placed in exit_mmap().
Hannes
---
Subject: mm: check for no mmaps in exit_mmap()
When dup_mmap() ooms we can end up with mm->mmap == NULL. The error path does mmput() and unmap_vmas() gets a NULL vma which it dereferences.
In exit_mmap() there is nothing to do at all for this case, we can cancel the callpath right there.
---
mm/mmap.c +3 -0
@@ -2091,6 +2091,9 @@ void exit_mmap(struct mm_struct *mm)arch_exit_mmap (mm);mmu_notifier_release (mm); +if (!mm->mmap) +return ; +if (mm->locked_vm) { vma = mm->mmap;while (vma) {
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 6 lines
Why bail out this late? We can save the other stuff in
exit_mmap()as well if we have no mmaps.Granted, the path is dead cold so the extra call overhead doesn't matter but I think the check is logically better placed in
exit_mmap().
Looks good, this patch should go in.
Quoted 21 lines
Hannes
---
Subject: mm: check for no mmaps inexit_mmap()When
dup_mmap()ooms we can end up withmm->mmap== NULL. The error path doesmmput()andunmap_vmas()gets a NULL vma which it dereferences.In
exit_mmap()there is nothing to do at all for this case, we can cancel the callpath right there.Signed-off-by Johannes Weiner <[email protected]>---
mm/mmap.c +0
-0
mm/mmap.c void exit_mmap(struct mm_struct *mm) · line 2099
Quoted 9 lines
mm/mmap.c +3
-0@@ -2091,6 +2091,9 @@ void exit_mmap(struct mm_struct *mm)arch_exit_mmap (mm);mmu_notifier_release (mm); +if (!mm->mmap) +return ; +if (mm->locked_vm) { vma = mm->mmap;while (vma) {
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>