mm, oom: fix concurrent munlock and oom reaper unmap, v3
[email protected]
maintainerPATCH 10/13 mm, oom: fix concurrent munlock and oom reaper unmap, v3
From: David Rientjes <[email protected]>
Subject: mm, oom: fix concurrent munlock and oom reaper unmap, v3
Since exit_mmap() is done without the protection of mm->mmap_sem, it is possible for the oom reaper to concurrently operate on an mm until MMF_OOM_SKIP is set.
This allows munlock_vma_pages_all() to concurrently run while the oom reaper is operating on a vma. Since munlock_vma_pages_range() depends on clearing VM_LOCKED from vm_flags before actually doing the munlock to determine if any other vmas are locking the same memory, the check for VM_LOCKED in the oom reaper is racy.
This is especially noticeable on architectures such as powerpc where clearing a huge pmd requires serialize_against_pte_lookup(). If the pmd is zapped by the oom reaper during follow_page_mask() after the check for pmd_none() is bypassed, this ends up deferencing a NULL ptl or a kernel oops.
Fix this by manually freeing all possible memory from the mm before doing the munlock and then setting MMF_OOM_SKIP. The oom reaper can not run on the mm anymore so the munlock is safe to do in exit_mmap(). It also matches the logic that the oom reaper currently uses for determining when to set MMF_OOM_SKIP itself, so there's no new risk of excessive oom killing.
This issue fixes CVE-2018-1000200.
---
include/linux/oom.h | 2 + mm/mmap.c | 44 +++++++++++++--------- mm/oom_kill.c | 81 ++++++++++++++++++++++-------------------- 3 files changed, 71 insertions(+), 56 deletions(-)
include/linux/oom.h renamed from include/linux/oom.h~mm-oom-fix-concurrent-munlock-and-oom-reaper-unmap +2 -0
@@ -95,6 +95,8 @@ static inline int check_stable_address_sreturn 0 ; } +void __oom_reap_task_mm (struct mm_struct *mm); +extern unsigned long oom_badness (struct task_struct *p,struct mem_cgroup *memcg,const nodemask_t *nodemask,unsigned long totalpages);
mm/mmap.c renamed from mm/mmap.c~mm-oom-fix-concurrent-munlock-and-oom-reaper-unmap +26 -18
56 lines not on this page · raw message
mm/oom_kill.c renamed from mm/oom_kill.c~mm-oom-fix-concurrent-munlock-and-oom-reaper-unmap +43 -38
119 lines not on this page · raw message
_