]> git.baikalelectronics.ru Git - kernel.git/commit
mm/uffd: fix vma check on userfault for wp
authorPeter Xu <peterx@redhat.com>
Mon, 24 Oct 2022 19:33:35 +0000 (15:33 -0400)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 28 Oct 2022 20:37:22 +0000 (13:37 -0700)
commitbb7a1c99348a6cc1e5f0b89bf877d11e81c77f74
treeafc0e6c728b45b4cfea986fdd916d935cbc438dd
parent96f3cb0271bac0bcdc0c6eca3b9b759d38defb5e
mm/uffd: fix vma check on userfault for wp

We used to have a report that pte-marker code can be reached even when
uffd-wp is not compiled in for file memories, here:

https://lore.kernel.org/all/YzeR+R6b4bwBlBHh@x1n/T/#u

I just got time to revisit this and found that the root cause is we simply
messed up with the vma check, so that for !PTE_MARKER_UFFD_WP system, we
will allow UFFDIO_REGISTER of MINOR & WP upon shmem as the check was
wrong:

    if (vm_flags & VM_UFFD_MINOR)
        return is_vm_hugetlb_page(vma) || vma_is_shmem(vma);

Where we'll allow anything to pass on shmem as long as minor mode is
requested.

Axel did it right when introducing minor mode but I messed it up in
7fda9ca216bd when moving code around.  Fix it.

Link: https://lkml.kernel.org/r/20221024193336.1233616-1-peterx@redhat.com
Link: https://lkml.kernel.org/r/20221024193336.1233616-2-peterx@redhat.com
Fixes: 7fda9ca216bd ("mm/uffd: enable write protection for shmem & hugetlbfs")
Signed-off-by: Peter Xu <peterx@redhat.com>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Nadav Amit <nadav.amit@gmail.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/userfaultfd_k.h