Skip to content

Commit af1b3cf

Browse files
thule-vincenzowildea01
authored andcommitted
arm64: compat: Add KUSER_HELPERS config option
When kuser helpers are enabled the kernel maps the relative code at a fixed address (0xffff0000). Making configurable the option to disable them means that the kernel can remove this mapping and any access to this memory area results in a sigfault. Add a KUSER_HELPERS config option that can be used to disable the mapping when it is turned off. This option can be turned off if and only if the applications are designed specifically for the platform and they do not make use of the kuser helpers code. Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Will Deacon <will.deacon@arm.com> Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> [will: Use IS_ENABLED() instead of #ifdef] Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent 1255a73 commit af1b3cf

4 files changed

Lines changed: 39 additions & 5 deletions

File tree

‎arch/arm64/Kconfig‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,34 @@ config COMPAT
14981498

14991499
If you want to execute 32-bit userspace applications, say Y.
15001500

1501+
config KUSER_HELPERS
1502+
bool "Enable kuser helpers page for 32 bit applications."
1503+
depends on COMPAT
1504+
default y
1505+
help
1506+
Warning: disabling this option may break 32-bit user programs.
1507+
1508+
Provide kuser helpers to compat tasks. The kernel provides
1509+
helper code to userspace in read only form at a fixed location
1510+
to allow userspace to be independent of the CPU type fitted to
1511+
the system. This permits binaries to be run on ARMv4 through
1512+
to ARMv8 without modification.
1513+
1514+
See Documentation/arm/kernel_user_helpers.txt for details.
1515+
1516+
However, the fixed address nature of these helpers can be used
1517+
by ROP (return orientated programming) authors when creating
1518+
exploits.
1519+
1520+
If all of the binaries and libraries which run on your platform
1521+
are built specifically for your platform, and make no use of
1522+
these helpers, then you can turn this option off to hinder
1523+
such exploits. However, in that case, if a binary or library
1524+
relying on those helpers is run, it will not function correctly.
1525+
1526+
Say N here only if you are absolutely certain that you do not
1527+
need these helpers; otherwise, the safe option is to say Y.
1528+
15011529
config SYSVIPC_COMPAT
15021530
def_bool y
15031531
depends on COMPAT && SYSVIPC

‎arch/arm64/kernel/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ OBJCOPYFLAGS := --prefix-symbols=__efistub_
2727
$(obj)/%.stub.o: $(obj)/%.o FORCE
2828
$(call if_changed,objcopy)
2929

30-
obj-$(CONFIG_COMPAT) += sys32.o kuser32.o signal32.o \
30+
obj-$(CONFIG_COMPAT) += sys32.o signal32.o \
3131
sigreturn32.o sys_compat.o
32+
obj-$(CONFIG_KUSER_HELPERS) += kuser32.o
3233
obj-$(CONFIG_FUNCTION_TRACER) += ftrace.o entry-ftrace.o
3334
obj-$(CONFIG_MODULES) += module.o
3435
obj-$(CONFIG_ARM64_MODULE_PLTS) += module-plts.o

‎arch/arm64/kernel/kuser32.S‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
* Copyright (C) 2005-2011 Nicolas Pitre <nico@fluxnic.net>
77
* Copyright (C) 2012-2018 ARM Ltd.
88
*
9-
* Each segment is 32-byte aligned and will be moved to the top of the high
10-
* vector page. New segments (if ever needed) must be added in front of
11-
* existing ones. This mechanism should be used only for things that are
12-
* really small and justified, and not be abused freely.
9+
* The kuser helpers below are mapped at a fixed address by
10+
* aarch32_setup_additional_pages() and are provided for compatibility
11+
* reasons with 32 bit (aarch32) applications that need them.
1312
*
1413
* See Documentation/arm/kernel_user_helpers.txt for formal definitions.
1514
*/

‎arch/arm64/kernel/vdso.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ static int aarch32_alloc_kuser_vdso_page(void)
7474
int kuser_sz = __kuser_helper_end - __kuser_helper_start;
7575
unsigned long vdso_page;
7676

77+
if (!IS_ENABLED(CONFIG_KUSER_HELPERS))
78+
return 0;
79+
7780
vdso_page = get_zeroed_page(GFP_ATOMIC);
7881
if (!vdso_page)
7982
return -ENOMEM;
@@ -112,6 +115,9 @@ static int aarch32_kuser_helpers_setup(struct mm_struct *mm)
112115
{
113116
void *ret;
114117

118+
if (!IS_ENABLED(CONFIG_KUSER_HELPERS))
119+
return 0;
120+
115121
/*
116122
* Avoid VM_MAYWRITE for compatibility with arch/arm/, where it's
117123
* not safe to CoW the page containing the CPU exception vectors.

0 commit comments

Comments
 (0)