From: Lokesh Gidra <lokeshgidra@google.com>
To: Kees Cook <keescook@chromium.org>,
Jonathan Corbet <corbet@lwn.net>, Peter Xu <peterx@redhat.com>,
Andrea Arcangeli <aarcange@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
Stephen Smalley <stephen.smalley.work@gmail.com>,
Eric Biggers <ebiggers@kernel.com>,
Lokesh Gidra <lokeshgidra@google.com>,
Daniel Colascione <dancol@dancol.org>,
"Joel Fernandes (Google)" <joel@joelfernandes.org>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-doc@vger.kernel.org, kaleshsingh@google.com,
calin@google.com, surenb@google.com, nnk@google.com,
jeffv@google.com, kernel-team@android.com,
Mike Rapoport <rppt@linux.vnet.ibm.com>, Shaohua Li <shli@fb.com>,
Jerome Glisse <jglisse@redhat.com>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
Johannes Weiner <hannes@cmpxchg.org>,
Mel Gorman <mgorman@techsingularity.net>,
Nitin Gupta <nigupta@nvidia.com>,
Vlastimil Babka <vbabka@suse.cz>,
Iurii Zaikin <yzaikin@google.com>,
Luis Chamberlain <mcgrof@kernel.org>,
Daniel Colascione <dancol@google.com>
Subject: [PATCH v2 2/2] Add user-mode only option to unprivileged_userfaultfd sysctl knob
Date: Fri, 21 Aug 2020 18:40:18 -0700 [thread overview]
Message-ID: <20200822014018.913868-3-lokeshgidra@google.com> (raw)
In-Reply-To: <20200822014018.913868-1-lokeshgidra@google.com>
A third option is added to 'unprivileged_userfaultfd' sysctl knob.
When the knob is set to 2, it allows unprivileged users to call
userfaultfd, like when it is set to 1, but with the restriction that
page faults from only user-mode can be handled. In this mode,
an unprivileged user (without SYS_CAP_PTRACE capability) must pass
UFFD_USER_MODE_ONLY to userfaultd or the API will fail with EPERM.
This facility allows administrators to reduce the likelihood that
an attacker with access to userfaultfd can delay faulting kernel
code to widen timing windows for other exploits.
Signed-off-by: Daniel Colascione <dancol@google.com>
Signed-off-by: Lokesh Gidra <lokeshgidra@google.com>
---
Documentation/admin-guide/sysctl/vm.rst | 10 +++++++---
fs/userfaultfd.c | 10 ++++++++--
kernel/sysctl.c | 2 +-
3 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/Documentation/admin-guide/sysctl/vm.rst b/Documentation/admin-guide/sysctl/vm.rst
index 4b9d2e8e9142..23d6feb79f5c 100644
--- a/Documentation/admin-guide/sysctl/vm.rst
+++ b/Documentation/admin-guide/sysctl/vm.rst
@@ -872,9 +872,13 @@ unprivileged_userfaultfd
========================
This flag controls whether unprivileged users can use the userfaultfd
-system calls. Set this to 1 to allow unprivileged users to use the
-userfaultfd system calls, or set this to 0 to restrict userfaultfd to only
-privileged users (with SYS_CAP_PTRACE capability).
+system calls. Set this to 0 to restrict userfaultfd to only privileged
+users (with SYS_CAP_PTRACE capability), set this to 1 to allow unprivileged
+users to use the userfaultfd system calls, or set this to 2 to restrict
+unprivileged users to handle page faults in user mode only. In the last case,
+users without SYS_CAP_PTRACE must pass UFFD_USER_MODE_ONLY in order for
+userfaultfd to succeed. Prohibiting use of userfaultfd for handling faults
+from kernel mode may make certain vulnerabilities more difficult to exploit.
The default value is 1.
diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
index 3e4ae6145112..2fcdeb28c960 100644
--- a/fs/userfaultfd.c
+++ b/fs/userfaultfd.c
@@ -1973,8 +1973,14 @@ SYSCALL_DEFINE1(userfaultfd, int, flags)
struct userfaultfd_ctx *ctx;
int fd;
- if (!sysctl_unprivileged_userfaultfd && !capable(CAP_SYS_PTRACE))
- return -EPERM;
+ switch (sysctl_unprivileged_userfaultfd) {
+ case 2:
+ if (flags & UFFD_USER_MODE_ONLY)
+ break;
+ case 0:
+ if (!capable(CAP_SYS_PTRACE))
+ return -EPERM;
+ }
BUG_ON(!current->mm);
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 287862f91717..7e94215dfff5 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -3119,7 +3119,7 @@ static struct ctl_table vm_table[] = {
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
.extra1 = SYSCTL_ZERO,
- .extra2 = SYSCTL_ONE,
+ .extra2 = &two,
},
#endif
{ }
--
2.28.0.297.g1956fa8f8d-goog
prev parent reply other threads:[~2020-08-22 1:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-22 1:40 [PATCH v2 0/2] Control over userfaultfd kernel-fault handling Lokesh Gidra
2020-08-22 1:40 ` [PATCH v2 1/2] Add UFFD_USER_MODE_ONLY Lokesh Gidra
2020-08-24 12:32 ` Sebastian Andrzej Siewior
2020-08-26 0:24 ` Lokesh Gidra
2020-08-22 1:40 ` Lokesh Gidra [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200822014018.913868-3-lokeshgidra@google.com \
--to=lokeshgidra@google.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=bigeasy@linutronix.de \
--cc=calin@google.com \
--cc=corbet@lwn.net \
--cc=dancol@dancol.org \
--cc=dancol@google.com \
--cc=ebiggers@kernel.com \
--cc=hannes@cmpxchg.org \
--cc=jeffv@google.com \
--cc=jglisse@redhat.com \
--cc=joel@joelfernandes.org \
--cc=kaleshsingh@google.com \
--cc=keescook@chromium.org \
--cc=kernel-team@android.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=mchehab+huawei@kernel.org \
--cc=mgorman@techsingularity.net \
--cc=nigupta@nvidia.com \
--cc=nnk@google.com \
--cc=peterx@redhat.com \
--cc=rppt@linux.vnet.ibm.com \
--cc=shli@fb.com \
--cc=stephen.smalley.work@gmail.com \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
--cc=viro@zeniv.linux.org.uk \
--cc=yzaikin@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®