Skip to content

Commit 8ada478

Browse files
ardbiesheuvelgregkh
authored andcommitted
vmlinux.lds: Ensure that const vars with relocations are mapped R/O
commit 68f3ea7ee199ef77551e090dfef5a49046ea8443 upstream. In the kernel, there are architectures (x86, arm64) that perform boot-time relocation (for KASLR) without relying on PIE codegen. In this case, all const global objects are emitted into .rodata, including const objects with fields that will be fixed up by the boot-time relocation code. This implies that .rodata (and .text in some cases) need to be writable at boot, but they will usually be mapped read-only as soon as the boot completes. When using PIE codegen, the compiler will emit const global objects into .data.rel.ro rather than .rodata if the object contains fields that need such fixups at boot-time. This permits the linker to annotate such regions as requiring read-write access only at load time, but not at execution time (in user space), while keeping .rodata truly const (in user space, this is important for reducing the CoW footprint of dynamic executables). This distinction does not matter for the kernel, but it does imply that const data will end up in writable memory if the .data.rel.ro sections are not treated in a special way, as they will end up in the writable .data segment by default. So emit .data.rel.ro into the .rodata segment. Cc: [email protected] Signed-off-by: Ard Biesheuvel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 1489b2d commit 8ada478

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

include/asm-generic/vmlinux.lds.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@
461461
. = ALIGN((align)); \
462462
.rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
463463
__start_rodata = .; \
464-
*(.rodata) *(.rodata.*) \
464+
*(.rodata) *(.rodata.*) *(.data.rel.ro*) \
465465
SCHED_DATA \
466466
RO_AFTER_INIT_DATA /* Read only after init */ \
467467
. = ALIGN(8); \

0 commit comments

Comments
 (0)