[PATCH 1/1] uffd: wp: clear VM_UFFD_MISSING or VM_UFFD_WP during userfaultfd_register()
From: Andrea Arcangeli
Date: Fri Oct 04 2019 - 19:09:59 EST
If the registration is repeated without VM_UFFD_MISSING or VM_UFFD_WP
they need to be cleared. Currently setting UFFDIO_REGISTER_MODE_WP
returns -EINVAL, so this patch is a noop until the
UFFDIO_REGISTER_MODE_WP support is applied.
Reported-by: Wei Yang <richardw.yang@xxxxxxxxxxxxxxx>
Signed-off-by: Andrea Arcangeli <aarcange@xxxxxxxxxx>
---
fs/userfaultfd.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
index fe6d804a38dc..97596bb65dd5 100644
--- a/fs/userfaultfd.c
+++ b/fs/userfaultfd.c
@@ -1458,7 +1458,8 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx,
start = vma->vm_start;
vma_end = min(end, vma->vm_end);
- new_flags = (vma->vm_flags & ~vm_flags) | vm_flags;
+ new_flags = (vma->vm_flags &
+ ~(VM_UFFD_MISSING|VM_UFFD_WP)) | vm_flags;
prev = vma_merge(mm, prev, start, vma_end, new_flags,
vma->anon_vma, vma->vm_file, vma->vm_pgoff,
vma_policy(vma),