Skip to content

Commit 428f889

Browse files
committed
x86, vmlinux.lds.S: Page align RO data for xo text
RO data starts right after the kernel text. If the kernel text doesn’t end exactly on a 2MB page boundary, then the last page of text will share a page with the RO data. This prevents all of the text being set as execute-only, since it would make the RO data not readable. So page align the start of the RO data when CONFIG_XO_TEXT so this does not happen. This usually results in the last page of kernel text being a 4k page instead of a 2MB one. The RO data could be 2MB aligned to avoid this, but at the cost of extra memory usage. So have it be a 4k page, as it is the compromise PTI used when setting some pages non-global. Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
1 parent 79b157b commit 428f889

File tree

Image for: File tree

2 files changed

Image for: 2 files changed
+11
-0
lines changed

2 files changed

Image for: 2 files changed
+11
-0
lines changed

‎arch/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,9 @@ config STRICT_MODULE_RWX
872872
and non-text memory will be made non-executable. This provides
873873
protection against certain security exploits (e.g. writing to text)
874874

875+
config STRICT_KERNEL_NR
876+
bool "Align kernel rodata so all kernel text can be set not readable"
877+
875878
# select if the architecture provides an asm/dma-direct.h header
876879
config ARCH_HAS_PHYS_TO_DMA
877880
bool

‎arch/x86/kernel/vmlinux.lds.S

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ SECTIONS
143143
#endif
144144
} :text = 0x9090
145145

146+
/*
147+
* If the kernel text is XO, make sure no data shares the page with the
148+
* kernel text.
149+
*/
150+
#ifdef CONFIG_XO_TEXT
151+
. = ALIGN(PAGE_SIZE);
152+
#endif
153+
146154
/* End of text section */
147155
_etext = .;
148156

0 commit comments

Image for: 0 commit comments
Comments
 (0)