[RHEL8,COMMIT] fs/userfaultfd.c: wp: clear VM_UFFD_MISSING or VM_UFFD_WP during userfaultfd_register()

Submitted by Konstantin Khorenko on April 20, 2020, 7:34 a.m.


Message ID 202004200734.03K7Y4Lg015414@finist_co8.work.ct
State New
Series "Series without cover letter"
Headers show

Commit Message

Konstantin Khorenko April 20, 2020, 7:34 a.m.
The commit is pushed to "branch-rh8-4.18.0-80.1.2.vz8.3.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-80.1.2.vz8.3.6
commit f60fc47edac34f669bd9d1c8bbddfd552524becc
Author: Andrea Arcangeli <aarcange@redhat.com>
Date:   Mon Apr 20 10:34:04 2020 +0300

    fs/userfaultfd.c: wp: clear VM_UFFD_MISSING or VM_UFFD_WP during userfaultfd_register()
    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.
    Link: http://lkml.kernel.org/r/20191004232834.GP13922@redhat.com
    Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>
    Reported-by: Wei Yang <richardw.yang@linux.intel.com>
    Reviewed-by: Wei Yang <richardw.yang@linux.intel.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    (cherry picked from commit 9d4678eb170c4c632174d1fec8ecee31c2f314f9)
    Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
 fs/userfaultfd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
index d126b4ae57ee..2dcade9daa73 100644
--- a/fs/userfaultfd.c
+++ b/fs/userfaultfd.c
@@ -1451,7 +1451,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,