Skip to content

Commit 76e8fe0

Browse files
Michal Hockogregkh
Michal Hocko
authored andcommitted
mm: fix double mmap_sem unlock on MMF_UNSTABLE enforced SIGBUS
commit 5b53a6e upstream. Tetsuo Handa has noticed that MMF_UNSTABLE SIGBUS path in handle_mm_fault causes a lockdep splat Out of memory: Kill process 1056 (a.out) score 603 or sacrifice child Killed process 1056 (a.out) total-vm:4268108kB, anon-rss:2246048kB, file-rss:0kB, shmem-rss:0kB a.out (1169) used greatest stack depth: 11664 bytes left DEBUG_LOCKS_WARN_ON(depth <= 0) ------------[ cut here ]------------ WARNING: CPU: 6 PID: 1339 at kernel/locking/lockdep.c:3617 lock_release+0x172/0x1e0 CPU: 6 PID: 1339 Comm: a.out Not tainted 4.13.0-rc3-next-20170803+ #142 Hardware name: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 07/02/2015 RIP: 0010:lock_release+0x172/0x1e0 Call Trace: up_read+0x1a/0x40 __do_page_fault+0x28e/0x4c0 do_page_fault+0x30/0x80 page_fault+0x28/0x30 The reason is that the page fault path might have dropped the mmap_sem and returned with VM_FAULT_RETRY. MMF_UNSTABLE check however rewrites the error path to VM_FAULT_SIGBUS and we always expect mmap_sem taken in that path. Fix this by taking mmap_sem when VM_FAULT_RETRY is held in the MMF_UNSTABLE path. We cannot simply add VM_FAULT_SIGBUS to the existing error code because all arch specific page fault handlers and g-u-p would have to learn a new error code combination. Link: http://lkml.kernel.org/r/[email protected] Fixes: 3f70dc3 ("mm: make sure that kthreads will not refault oom reaped memory") Reported-by: Tetsuo Handa <[email protected]> Signed-off-by: Michal Hocko <[email protected]> Acked-by: David Rientjes <[email protected]> Cc: Andrea Argangeli <[email protected]> Cc: "Kirill A. Shutemov" <[email protected]> Cc: Oleg Nesterov <[email protected]> Cc: Wenwei Tao <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 889a170 commit 76e8fe0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

mm/memory.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3882,8 +3882,18 @@ int handle_mm_fault(struct vm_area_struct *vma, unsigned long address,
38823882
* further.
38833883
*/
38843884
if (unlikely((current->flags & PF_KTHREAD) && !(ret & VM_FAULT_ERROR)
3885-
&& test_bit(MMF_UNSTABLE, &vma->vm_mm->flags)))
3885+
&& test_bit(MMF_UNSTABLE, &vma->vm_mm->flags))) {
3886+
3887+
/*
3888+
* We are going to enforce SIGBUS but the PF path might have
3889+
* dropped the mmap_sem already so take it again so that
3890+
* we do not break expectations of all arch specific PF paths
3891+
* and g-u-p
3892+
*/
3893+
if (ret & VM_FAULT_RETRY)
3894+
down_read(&vma->vm_mm->mmap_sem);
38863895
ret = VM_FAULT_SIGBUS;
3896+
}
38873897

38883898
return ret;
38893899
}

0 commit comments

Comments
 (0)