Commit 30080059 authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Zheng Zengkai
Browse files

ARM: kernel: switch to relative exception tables

maillist inclusion
commit ccb456783dd71f474e5783a81d7f18c2cd4dda81
category: feature
feature: ARM kaslr support
bugzilla: 47952
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/ardb/linux.git/commit/?h=arm-kaslr-latest&id=ccb456783dd71f474e5783a81d7f18c2cd4dda81



-------------------------------------------------

To avoid having to relocate the contents of extable entries at
runtime when running with KASLR enabled, wire up the existing
support for emitting them as relative references. This ensures
these quantities are invariant under runtime relocation.

Cc: Russell King <linux@armlinux.org.uk>
Signed-off-by: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: default avatarCui GaoSheng <cuigaosheng1@huawei.com>
Reviewed-by: default avatarXiu Jianfeng <xiujianfeng@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parent bb266760
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
# SPDX-License-Identifier: GPL-2.0
generic-y += early_ioremap.h
generic-y += extable.h
generic-y += flat.h
generic-y += parport.h
generic-y += seccomp.h
+4 −12
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#endif

#include <asm/ptrace.h>
#include <asm/extable.h>
#include <asm/opcodes-virt.h>
#include <asm/asm-offsets.h>
#include <asm/page.h>
@@ -242,10 +243,7 @@

#define USERL(l, x...)				\
9999:	x;					\
	.pushsection __ex_table,"a";		\
	.align	3;				\
	.long	9999b,l;			\
	.popsection
	ex_entry	9999b,l;

#define USER(x...)	USERL(9001f, x)

@@ -379,10 +377,7 @@ THUMB( orr \reg , \reg , #PSR_T_BIT )
	.error	"Unsupported inc macro argument"
	.endif

	.pushsection __ex_table,"a"
	.align	3
	.long	9999b, \abort
	.popsection
	ex_entry	9999b, \abort
	.endm

	.macro	usracc, instr, reg, ptr, inc, cond, rept, abort
@@ -420,10 +415,7 @@ THUMB( orr \reg , \reg , #PSR_T_BIT )
	.error	"Unsupported inc macro argument"
	.endif

	.pushsection __ex_table,"a"
	.align	3
	.long	9999b, \abort
	.popsection
	ex_entry	9999b, \abort
	.endr
	.endm

+47 −0
Original line number Diff line number Diff line
#ifndef __ASM_EXTABLE_H
#define __ASM_EXTABLE_H

#ifndef __ASSEMBLY__

/*
 * The exception table consists of pairs of relative offsets: the first
 * is the relative offset to an instruction that is allowed to fault,
 * and the second is the relative offset at which the program should
 * continue. No registers are modified, so it is entirely up to the
 * continuation code to figure out what to do.
 */

struct exception_table_entry {
	int insn, fixup;
};

#define ARCH_HAS_RELATIVE_EXTABLE

extern int fixup_exception(struct pt_regs *regs);

	/*
	 * ex_entry - place-relative extable entry
	 */
asm(	".macro		ex_entry, insn, fixup		\n"
	".pushsection	__ex_table, \"a\", %progbits	\n"
	".align		3				\n"
	".long		\\insn - .			\n"
	".long		\\fixup - .			\n"
	".popsection					\n"
	".endm						\n");

#else

	/*
	 * ex_entry - place-relative extable entry
	 */
	.macro		ex_entry, insn, fixup
	.pushsection	__ex_table, "a", %progbits
	.align		3
	.long		\insn - .
	.long		\fixup - .
	.popsection
	.endm

#endif
#endif
+2 −4
Original line number Diff line number Diff line
@@ -10,10 +10,8 @@

#define __futex_atomic_ex_table(err_reg)			\
	"3:\n"							\
	"	.pushsection __ex_table,\"a\"\n"		\
	"	.align	3\n"					\
	"	.long	1b, 4f, 2b, 4f\n"			\
	"	.popsection\n"					\
	"	ex_entry	1b, 4f\n"			\
	"	ex_entry	2b, 4f\n"			\
	"	.pushsection .text.fixup,\"ax\"\n"		\
	"	.align	2\n"					\
	"4:	mov	%0, " err_reg "\n"			\
+4 −13
Original line number Diff line number Diff line
@@ -340,10 +340,7 @@ do { \
	"	mov	%1, #0\n"				\
	"	b	2b\n"					\
	"	.popsection\n"					\
	"	.pushsection __ex_table,\"a\"\n"		\
	"	.align	3\n"					\
	"	.long	1b, 3b\n"				\
	"	.popsection"					\
	"	ex_entry	1b, 3b\n"			\
	: "+r" (err), "=&r" (x)					\
	: "r" (addr), "i" (-EFAULT)				\
	: "cc")
@@ -442,10 +439,7 @@ do { \
	"3:	mov	%0, %3\n"				\
	"	b	2b\n"					\
	"	.popsection\n"					\
	"	.pushsection __ex_table,\"a\"\n"		\
	"	.align	3\n"					\
	"	.long	1b, 3b\n"				\
	"	.popsection"					\
	"	ex_entry	1b, 3b\n"			\
	: "+r" (err)						\
	: "r" (x), "r" (__pu_addr), "i" (-EFAULT)		\
	: "cc")
@@ -501,11 +495,8 @@ do { \
	"4:	mov	%0, %3\n"				\
	"	b	3b\n"					\
	"	.popsection\n"					\
	"	.pushsection __ex_table,\"a\"\n"		\
	"	.align	3\n"					\
	"	.long	1b, 4b\n"				\
	"	.long	2b, 4b\n"				\
	"	.popsection"					\
	"	ex_entry	1b, 4b\n"			\
	"	ex_entry	2b, 4b\n"			\
	: "+r" (err), "+r" (__pu_addr)				\
	: "r" (x), "i" (-EFAULT)				\
	: "cc")
Loading