Skip to content

Commit f6f91b0

Browse files
author
Russell King
committed
ARM: allow kuser helpers to be removed from the vector page
Provide a kernel configuration option to allow the kernel user helpers to be removed from the vector page, thereby preventing their use with ROP (return orientated programming) attacks. This option is only visible for CPU architectures which natively support all the operations which kernel user helpers would normally provide, and must be enabled with caution. Cc: <stable@vger.kernel.org> Acked-by: Nicolas Pitre <nico@linaro.org> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent e39e3f3 commit f6f91b0

3 files changed

Lines changed: 51 additions & 9 deletions

File tree

‎arch/arm/kernel/entry-armv.S‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ ENDPROC(__switch_to)
753753
.endr
754754
.endm
755755

756+
#ifdef CONFIG_KUSER_HELPERS
756757
.align 5
757758
.globl __kuser_helper_start
758759
__kuser_helper_start:
@@ -939,6 +940,8 @@ __kuser_helper_version: @ 0xffff0ffc
939940
.globl __kuser_helper_end
940941
__kuser_helper_end:
941942

943+
#endif
944+
942945
THUMB( .thumb )
943946

944947
/*

‎arch/arm/kernel/traps.c‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -800,24 +800,33 @@ void __init trap_init(void)
800800
return;
801801
}
802802

803-
static void __init kuser_get_tls_init(unsigned long vectors)
803+
#ifdef CONFIG_KUSER_HELPERS
804+
static void __init kuser_init(void *vectors)
804805
{
806+
extern char __kuser_helper_start[], __kuser_helper_end[];
807+
int kuser_sz = __kuser_helper_end - __kuser_helper_start;
808+
809+
memcpy(vectors + 0x1000 - kuser_sz, __kuser_helper_start, kuser_sz);
810+
805811
/*
806812
* vectors + 0xfe0 = __kuser_get_tls
807813
* vectors + 0xfe8 = hardware TLS instruction at 0xffff0fe8
808814
*/
809815
if (tls_emu || has_tls_reg)
810-
memcpy((void *)vectors + 0xfe0, (void *)vectors + 0xfe8, 4);
816+
memcpy(vectors + 0xfe0, vectors + 0xfe8, 4);
817+
}
818+
#else
819+
static void __init kuser_init(void *vectors)
820+
{
811821
}
822+
#endif
812823

813824
void __init early_trap_init(void *vectors_base)
814825
{
815826
#ifndef CONFIG_CPU_V7M
816827
unsigned long vectors = (unsigned long)vectors_base;
817828
extern char __stubs_start[], __stubs_end[];
818829
extern char __vectors_start[], __vectors_end[];
819-
extern char __kuser_helper_start[], __kuser_helper_end[];
820-
int kuser_sz = __kuser_helper_end - __kuser_helper_start;
821830
unsigned i;
822831

823832
vectors_page = vectors_base;
@@ -838,12 +847,8 @@ void __init early_trap_init(void *vectors_base)
838847
*/
839848
memcpy((void *)vectors, __vectors_start, __vectors_end - __vectors_start);
840849
memcpy((void *)vectors + 0x1000, __stubs_start, __stubs_end - __stubs_start);
841-
memcpy((void *)vectors + 0x1000 - kuser_sz, __kuser_helper_start, kuser_sz);
842850

843-
/*
844-
* Do processor specific fixups for the kuser helpers
845-
*/
846-
kuser_get_tls_init(vectors);
851+
kuser_init(vectors_base);
847852

848853
/*
849854
* Copy signal return handlers into the vector page, and

‎arch/arm/mm/Kconfig‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,24 +421,28 @@ config CPU_32v3
421421
select CPU_USE_DOMAINS if MMU
422422
select NEEDS_SYSCALL_FOR_CMPXCHG if SMP
423423
select TLS_REG_EMUL if SMP || !MMU
424+
select NEED_KUSER_HELPERS
424425

425426
config CPU_32v4
426427
bool
427428
select CPU_USE_DOMAINS if MMU
428429
select NEEDS_SYSCALL_FOR_CMPXCHG if SMP
429430
select TLS_REG_EMUL if SMP || !MMU
431+
select NEED_KUSER_HELPERS
430432

431433
config CPU_32v4T
432434
bool
433435
select CPU_USE_DOMAINS if MMU
434436
select NEEDS_SYSCALL_FOR_CMPXCHG if SMP
435437
select TLS_REG_EMUL if SMP || !MMU
438+
select NEED_KUSER_HELPERS
436439

437440
config CPU_32v5
438441
bool
439442
select CPU_USE_DOMAINS if MMU
440443
select NEEDS_SYSCALL_FOR_CMPXCHG if SMP
441444
select TLS_REG_EMUL if SMP || !MMU
445+
select NEED_KUSER_HELPERS
442446

443447
config CPU_32v6
444448
bool
@@ -776,18 +780,48 @@ config CPU_BPREDICT_DISABLE
776780

777781
config TLS_REG_EMUL
778782
bool
783+
select NEED_KUSER_HELPERS
779784
help
780785
An SMP system using a pre-ARMv6 processor (there are apparently
781786
a few prototypes like that in existence) and therefore access to
782787
that required register must be emulated.
783788

784789
config NEEDS_SYSCALL_FOR_CMPXCHG
785790
bool
791+
select NEED_KUSER_HELPERS
786792
help
787793
SMP on a pre-ARMv6 processor? Well OK then.
788794
Forget about fast user space cmpxchg support.
789795
It is just not possible.
790796

797+
config NEED_KUSER_HELPERS
798+
bool
799+
800+
config KUSER_HELPERS
801+
bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
802+
default y
803+
help
804+
Warning: disabling this option may break user programs.
805+
806+
Provide kuser helpers in the vector page. The kernel provides
807+
helper code to userspace in read only form at a fixed location
808+
in the high vector page to allow userspace to be independent of
809+
the CPU type fitted to the system. This permits binaries to be
810+
run on ARMv4 through to ARMv7 without modification.
811+
812+
However, the fixed address nature of these helpers can be used
813+
by ROP (return orientated programming) authors when creating
814+
exploits.
815+
816+
If all of the binaries and libraries which run on your platform
817+
are built specifically for your platform, and make no use of
818+
these helpers, then you can turn this option off. However,
819+
when such an binary or library is run, it will receive a SIGILL
820+
signal, which will terminate the program.
821+
822+
Say N here only if you are absolutely certain that you do not
823+
need these helpers; otherwise, the safe option is to say Y.
824+
791825
config DMA_CACHE_RWFO
792826
bool "Enable read/write for ownership DMA cache maintenance"
793827
depends on CPU_V6K && SMP

0 commit comments

Comments
 (0)