[PATCH 1/1] userfaultfd: shmem: __do_fault requires VM_FAULT_NOPAGE

From: Andrea Arcangeli
Date: Tue Feb 28 2017 - 10:36:59 EST


__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.

Signed-off-by: Andrea Arcangeli <aarcange@xxxxxxxxxx>
---
fs/userfaultfd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
index fb6d02b..de28f43 100644
--- a/fs/userfaultfd.c
+++ b/fs/userfaultfd.c
@@ -500,7 +500,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;
}
}