Skip to content

Commit 922fadc

Browse files
committed
add CONFIG for unprivileged_userfaultfd
When disabled, unprivileged users will not be able to use the userfaultfd syscall. Userfaultfd provide attackers with a way to stall a kernel thread in the middle of memory accesses from userspace by initiating an access on an unmapped page. To avoid various heap grooming and heap spraying techniques for exploiting use-after-free flaws this should be disabled by default. This setting can be overridden at runtime via the vm.unprivileged_userfaultfd sysctl. Signed-off-by: Levente Polyak <[email protected]>
1 parent a746e05 commit 922fadc

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

fs/userfaultfd.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
2828
#include <linux/security.h>
2929
#include <linux/hugetlb.h>
3030

31+
#ifdef CONFIG_USERFAULTFD_UNPRIVILEGED
3132
int sysctl_unprivileged_userfaultfd __read_mostly = 1;
33+
#else
34+
int sysctl_unprivileged_userfaultfd __read_mostly;
35+
#endif
3236

3337
static struct kmem_cache *userfaultfd_ctx_cachep __read_mostly;
3438

init/Kconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,23 @@ config USERFAULTFD
16501650
Enable the userfaultfd() system call that allows to intercept and
16511651
handle page faults in userland.
16521652

1653+
config USERFAULTFD_UNPRIVILEGED
1654+
bool "Allow unprivileged users to use the userfaultfd syscall"
1655+
depends on USERFAULTFD
1656+
default n
1657+
help
1658+
When disabled, unprivileged users will not be able to use the userfaultfd
1659+
syscall. Userfaultfd provide attackers with a way to stall a kernel
1660+
thread in the middle of memory accesses from userspace by initiating an
1661+
access on an unmapped page. To avoid various heap grooming and heap
1662+
spraying techniques for exploiting use-after-free flaws this should be
1663+
disabled by default.
1664+
1665+
This setting can be overridden at runtime via the
1666+
vm.unprivileged_userfaultfd sysctl.
1667+
1668+
If unsure, say N.
1669+
16531670
config ARCH_HAS_MEMBARRIER_CALLBACKS
16541671
bool
16551672

0 commit comments

Comments
 (0)