Patch "mm: fix double mmap_sem unlock on MMF_UNSTABLE enforced SIGBUS" has been added to the 4.9-stable tree
Subsystems (3)
This is a note to let you know that I've just added the patch titled
mm: fix double mmap_sem unlock on MMF_UNSTABLE enforced SIGBUS
to the 4.9-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
mm-fix-double-mmap_sem-unlock-on-mmf_unstable-enforced-sigbus.patch
and it can be found in the queue-4.9 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From
5b53a6ea886700a128b697a6fe8375340dea2c30Mon Sep 17 00:00:00 2001
From: Michal Hocko <[email protected]>
Date: Fri, 18 Aug 2017 15:16:12 -0700
Subject: mm: fix double mmap_sem unlock on MMF_UNSTABLE enforced SIGBUS
From: Michal Hocko <[email protected]>
commit 5b53a6ea886700a128b697a6fe8375340dea2c30 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/0x30The 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.
--- mm/memory.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
mm/memory.c +11 -1
@@ -3635,8 +3635,18 @@ int handle_mm_fault(struct vm_area_struc* further. */ if (unlikely ((current->flags &PF_KTHREAD ) && !(ret &VM_FAULT_ERROR ) - &&test_bit (MMF_UNSTABLE , &vma->vm_mm->flags))) + &&test_bit (MMF_UNSTABLE , &vma->vm_mm->flags))) { + +/* +* We are going to enforce SIGBUS but the PF path might have +* dropped the mmap_sem already so take it again so that +* we do not break expectations of all arch specific PF paths +* and g-u-p +*/ +if (ret &VM_FAULT_RETRY ) +down_read (&vma->vm_mm->mmap_sem); ret =VM_FAULT_SIGBUS ; + }return ret; }
Patches currently in stable-queue which might be from [email protected] are
queue-4.9/mm-discard-memblock-data-later.patch queue-4.9/mm-fix-double-mmap_sem-unlock-on-mmf_unstable-enforced-sigbus.patch queue-4.9/mm-mempolicy-fix-use-after-free-when-calling-get_mempolicy.patch