From: Peter Xu <pet...@redhat.com> Only declare _UFFDIO_WRITEPROTECT if the user specified UFFDIO_REGISTER_MODE_WP and if all the checks passed. Then when the user registers regions with shmem/hugetlbfs we won't expose the new ioctl to them. Even with complete anonymous memory range, we'll only expose the new WP ioctl bit if the register mode has MODE_WP.
Signed-off-by: Peter Xu <pet...@redhat.com> Signed-off-by: Andrew Morton <a...@linux-foundation.org> Reviewed-by: Mike Rapoport <r...@linux.vnet.ibm.com> Cc: Andrea Arcangeli <aarca...@redhat.com> Cc: Bobby Powers <bobbypow...@gmail.com> Cc: Brian Geffon <bgef...@google.com> Cc: David Hildenbrand <da...@redhat.com> Cc: Denis Plotnikov <dplotni...@virtuozzo.com> Cc: "Dr . David Alan Gilbert" <dgilb...@redhat.com> Cc: Hugh Dickins <hu...@google.com> Cc: Jerome Glisse <jgli...@redhat.com> Cc: Johannes Weiner <han...@cmpxchg.org> Cc: "Kirill A . Shutemov" <kir...@shutemov.name> Cc: Martin Cracauer <craca...@cons.org> Cc: Marty McFadden <mcfadd...@llnl.gov> Cc: Maya Gokhale <gokha...@llnl.gov> Cc: Mel Gorman <mgor...@suse.de> Cc: Mike Kravetz <mike.krav...@oracle.com> Cc: Pavel Emelyanov <xe...@openvz.org> Cc: Rik van Riel <r...@redhat.com> Cc: Shaohua Li <s...@fb.com> Link: http://lkml.kernel.org/r/20200220163112.11409-18-pet...@redhat.com Signed-off-by: Linus Torvalds <torva...@linux-foundation.org> https://jira.sw.ru/browse/PSBM-102938 (cherry picked from commit 14819305e09fe4fda546f0dfa12134c8e5366616) Signed-off-by: Andrey Ryabinin <aryabi...@virtuozzo.com> --- fs/userfaultfd.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 8d8dadc9a8b1..8427143fd546 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1486,14 +1486,24 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx, up_write(&mm->mmap_sem); mmput(mm); if (!ret) { + __u64 ioctls_out; + + ioctls_out = basic_ioctls ? UFFD_API_RANGE_IOCTLS_BASIC : + UFFD_API_RANGE_IOCTLS; + + /* + * Declare the WP ioctl only if the WP mode is + * specified and all checks passed with the range + */ + if (!(uffdio_register.mode & UFFDIO_REGISTER_MODE_WP)) + ioctls_out &= ~((__u64)1 << _UFFDIO_WRITEPROTECT); + /* * Now that we scanned all vmas we can already tell * userland which ioctls methods are guaranteed to * succeed on this range. */ - if (put_user(basic_ioctls ? UFFD_API_RANGE_IOCTLS_BASIC : - UFFD_API_RANGE_IOCTLS, - &user_uffdio_register->ioctls)) + if (put_user(ioctls_out, &user_uffdio_register->ioctls)) ret = -EFAULT; } out: -- 2.25.3 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel