userfaultfd: shmem: __do_fault requires VM_FAULT_NOPAGE
authorAndrea Arcangeli <[email protected]>
Fri, 10 Mar 2017 00:16:28 +0000 (16:16 -0800)
committerLinus Torvalds <[email protected]>
Fri, 10 Mar 2017 01:01:09 +0000 (17:01 -0800)
__do_fault assumes vmf->page has been initialized and is valid if
VM_FAULT_NOPAGE is not returned by vma->vm_ops->fault(vma, vmf).

handle_userfault() in turn should return VM_FAULT_NOPAGE if it doesn't
return VM_FAULT_SIGBUS or VM_FAULT_RETRY (the other two possibilities).

This VM_FAULT_NOPAGE case is only invoked when signal are pending and it
didn't matter for anonymous memory before.  It only started to matter
since shmem was introduced.  hugetlbfs also takes a different path and
doesn't exercise __do_fault.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Andrea Arcangeli <[email protected]>
Reported-by: Dmitry Vyukov <[email protected]>
Cc: "Kirill A. Shutemov" <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
fs/userfaultfd.c

index 973607df579db324e64da1c3c26999d60853fa80..f62199b90fd01cd78797b06cb8fd4320033e8792 100644 (file)
@@ -490,7 +490,7 @@ int handle_userfault(struct vm_fault *vmf, unsigned long reason)
                         * in such case.
                         */
                        down_read(&mm->mmap_sem);
-                       ret = 0;
+                       ret = VM_FAULT_NOPAGE;
                }
        }