Skip to content

Commit 2225a8d

Browse files
arielmarco-hzmpe
authored andcommitted
powerpc: Fix alignment bug within the init sections
This is a bug that causes early crashes in builds with an .exit.text section smaller than a page and an .init.text section that ends in the beginning of a physical page (this is kinda random, which might explain why this wasn't really encountered before). The init sections are ordered like this: .init.text .exit.text .init.data Currently, these sections aren't page aligned. Because the init code might become read-only at runtime and because the .init.text section can potentially reside on the same physical page as .init.data, the beginning of .init.data might be mapped read-only along with .init.text. Then when the kernel tries to modify a variable in .init.data (like kthreadd_done, used in kernel_init()) the kernel panics. To avoid this, make _einittext page aligned and also align .exit.text to make sure .init.data is always seperated from the text segments. Fixes: 060ef9d ("powerpc32: PAGE_EXEC required for inittext") Signed-off-by: Ariel Marcovitch <[email protected]> Reviewed-by: Christophe Leroy <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 3ce47d9 commit 2225a8d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

arch/powerpc/kernel/vmlinux.lds.S

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ SECTIONS
187187
.init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
188188
_sinittext = .;
189189
INIT_TEXT
190+
191+
/*
192+
*.init.text might be RO so we must ensure this section ends on
193+
* a page boundary.
194+
*/
195+
. = ALIGN(PAGE_SIZE);
190196
_einittext = .;
191197
#ifdef CONFIG_PPC64
192198
*(.tramp.ftrace.init);
@@ -200,6 +206,8 @@ SECTIONS
200206
EXIT_TEXT
201207
}
202208

209+
. = ALIGN(PAGE_SIZE);
210+
203211
INIT_DATA_SECTION(16)
204212

205213
. = ALIGN(8);

0 commit comments

Comments
 (0)