diff mbox series

[4/4] vmlinux.lds.h: Have ORC lookup cover entire _etext - _stext

Message ID 20211013175742.1197608-5-keescook@chromium.org (mailing list archive)
State Mainlined
Commit ca136cac37eb51649d52d5bc4271c55e30ed354c
Headers show
Series x86: Various clean-ups in support of FGKASLR | expand

Commit Message

Kees Cook Oct. 13, 2021, 5:57 p.m. UTC
From: Kristen Carlson Accardi <kristen@linux.intel.com>

When using -ffunction-sections to place each function in its own text
section (so it can be randomized at load time in the future FGKASLR
series), the linker will place most of the functions into separate .text.*
sections. SIZEOF(.text) won't work here for calculating the ORC lookup
table size, so the total text size must be calculated to include .text
AND all .text.* sections.

Signed-off-by: Kristen Carlson Accardi <kristen@linux.intel.com>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Tested-by: Tony Luck <tony.luck@intel.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
[ alobakin: move it to vmlinux.lds.h and make arch-indep ]
Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 include/asm-generic/vmlinux.lds.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Josh Poimboeuf Oct. 14, 2021, 12:29 a.m. UTC | #1
On Wed, Oct 13, 2021 at 10:57:42AM -0700, Kees Cook wrote:
> From: Kristen Carlson Accardi <kristen@linux.intel.com>
> 
> When using -ffunction-sections to place each function in its own text
> section (so it can be randomized at load time in the future FGKASLR
> series), the linker will place most of the functions into separate .text.*
> sections. SIZEOF(.text) won't work here for calculating the ORC lookup
> table size, so the total text size must be calculated to include .text
> AND all .text.* sections.
> 
> Signed-off-by: Kristen Carlson Accardi <kristen@linux.intel.com>
> Reviewed-by: Tony Luck <tony.luck@intel.com>
> Tested-by: Tony Luck <tony.luck@intel.com>
> Reviewed-by: Kees Cook <keescook@chromium.org>
> [ alobakin: move it to vmlinux.lds.h and make arch-indep ]
> Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com>
> Signed-off-by: Kees Cook <keescook@chromium.org>

Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
diff mbox series

Patch

diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index f2984af2b85b..e8234911dc18 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -869,10 +869,11 @@ 
 		KEEP(*(.orc_unwind))					\
 		__stop_orc_unwind = .;					\
 	}								\
+	text_size = _etext - _stext;					\
 	. = ALIGN(4);							\
 	.orc_lookup : AT(ADDR(.orc_lookup) - LOAD_OFFSET) {		\
 		orc_lookup = .;						\
-		. += (((SIZEOF(.text) + LOOKUP_BLOCK_SIZE - 1) /	\
+		. += (((text_size + LOOKUP_BLOCK_SIZE - 1) /		\
 			LOOKUP_BLOCK_SIZE) + 1) * 4;			\
 		orc_lookup_end = .;					\
 	}