From 5fe446d24aff4b9742cc2358014eb92eaa34ac38 Mon Sep 17 00:00:00 2001 From: Peter Xu Date: Mon, 6 Apr 2020 20:06:29 -0700 Subject: [PATCH] BACKPORT: userfaultfd: wp: declare _UFFDIO_WRITEPROTECT conditionally 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 Signed-off-by: Andrew Morton Reviewed-by: Mike Rapoport Cc: Andrea Arcangeli Cc: Bobby Powers Cc: Brian Geffon Cc: David Hildenbrand Cc: Denis Plotnikov Cc: "Dr . David Alan Gilbert" Cc: Hugh Dickins Cc: Jerome Glisse Cc: Johannes Weiner Cc: "Kirill A . Shutemov" Cc: Martin Cracauer Cc: Marty McFadden Cc: Maya Gokhale Cc: Mel Gorman Cc: Mike Kravetz Cc: Pavel Emelyanov Cc: Rik van Riel Cc: Shaohua Li Link: http://lkml.kernel.org/r/20200220163112.11409-18-peterx@redhat.com Signed-off-by: Linus Torvalds (cherry picked from commit 14819305e09fe4fda546f0dfa12134c8e5366616) [ Kalesh Singh - resolve conflicts in fs/userfaultfd.c ] Signed-off-by: Kalesh Singh Reported-by: kernel test robot [1] [1] https://lore.kernel.org/r/202201170247.Cir3moOM-lkp@intel.com/ Bug: 160737021 Bug: 169683130 Change-Id: I4f205e642f5f0e5824a43303aab30626cce3ddcb --- fs/userfaultfd.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 1d0c0397907e..4a6719214dc4 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1530,9 +1530,7 @@ out_unlock: * 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: