Skip to content

Commit 6ee3cf6

Browse files
ardbiesheuvelctmarinas
authored andcommitted
arm64: lds: move special code sections out of kernel exec segment
There are a few code sections that are emitted into the kernel's executable .text segment simply because they contain code, but are actually never executed via this mapping, so they can happily live in a region that gets mapped without executable permissions, reducing the risk of being gadgetized. Note that the kexec and hibernate region contents are always copied into a fresh page, and so there is no need to align them as long as the overall size of each is below 4 KiB. Signed-off-by: Ard Biesheuvel <[email protected]> Acked-by: Mark Rutland <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent bc5dfb4 commit 6ee3cf6

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

arch/arm64/kernel/vmlinux.lds.S

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ jiffies = jiffies_64;
9393

9494
#ifdef CONFIG_HIBERNATION
9595
#define HIBERNATE_TEXT \
96-
. = ALIGN(SZ_4K); \
9796
__hibernate_exit_text_start = .; \
9897
*(.hibernate_exit.text) \
9998
__hibernate_exit_text_end = .;
@@ -103,7 +102,6 @@ jiffies = jiffies_64;
103102

104103
#ifdef CONFIG_KEXEC_CORE
105104
#define KEXEC_TEXT \
106-
. = ALIGN(SZ_4K); \
107105
__relocate_new_kernel_start = .; \
108106
*(.kexec_relocate.text) \
109107
__relocate_new_kernel_end = .;
@@ -170,9 +168,6 @@ SECTIONS
170168
KPROBES_TEXT
171169
HYPERVISOR_TEXT
172170
IDMAP_TEXT
173-
HIBERNATE_TEXT
174-
KEXEC_TEXT
175-
TRAMP_TEXT
176171
*(.gnu.warning)
177172
. = ALIGN(16);
178173
*(.got) /* Global offset table */
@@ -194,6 +189,14 @@ SECTIONS
194189

195190
HYPERVISOR_DATA_SECTIONS
196191

192+
/* code sections that are never executed via the kernel mapping */
193+
.rodata.text : {
194+
TRAMP_TEXT
195+
HIBERNATE_TEXT
196+
KEXEC_TEXT
197+
. = ALIGN(PAGE_SIZE);
198+
}
199+
197200
idmap_pg_dir = .;
198201
. += IDMAP_DIR_SIZE;
199202
idmap_pg_end = .;
@@ -337,8 +340,8 @@ ASSERT(__hyp_idmap_text_end - __hyp_idmap_text_start <= PAGE_SIZE,
337340
ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
338341
"ID map text too big or misaligned")
339342
#ifdef CONFIG_HIBERNATION
340-
ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
341-
<= SZ_4K, "Hibernate exit text too big or misaligned")
343+
ASSERT(__hibernate_exit_text_end - __hibernate_exit_text_start <= SZ_4K,
344+
"Hibernate exit text is bigger than 4 KiB")
342345
#endif
343346
#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
344347
ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) <= 3*PAGE_SIZE,
@@ -362,7 +365,7 @@ ASSERT(swapper_pg_dir - tramp_pg_dir == TRAMP_SWAPPER_OFFSET,
362365

363366
#ifdef CONFIG_KEXEC_CORE
364367
/* kexec relocation code should fit into one KEXEC_CONTROL_PAGE_SIZE */
365-
ASSERT(__relocate_new_kernel_end - (__relocate_new_kernel_start & ~(SZ_4K - 1))
366-
<= SZ_4K, "kexec relocation code is too big or misaligned")
368+
ASSERT(__relocate_new_kernel_end - __relocate_new_kernel_start <= SZ_4K,
369+
"kexec relocation code is bigger than 4 KiB")
367370
ASSERT(KEXEC_CONTROL_PAGE_SIZE >= SZ_4K, "KEXEC_CONTROL_PAGE_SIZE is broken")
368371
#endif

0 commit comments

Comments
 (0)