linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] powerpc: fix alignment bug whithin the init sections
@ 2021-01-02 20:11 Ariel Marcovitch
  2021-01-11  7:06 ` Christophe Leroy
  2021-01-15 12:23 ` Michael Ellerman
  0 siblings, 2 replies; 3+ messages in thread
From: Ariel Marcovitch @ 2021-01-02 20:11 UTC (permalink / raw)
  To: mpe
  Cc: keescook, maskray, linux-kernel, npiggin, oss, paulus,
	ariel.marcovitch, naveen.n.rao, linuxppc-dev, dja

This is a bug that causes early crashes in builds with a
.exit.text section smaller than a page and a .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: 060ef9d89d18 ("powerpc32: PAGE_EXEC required for inittext")
Signed-off-by: Ariel Marcovitch <ariel.marcovitch@gmail.com>
---
 arch/powerpc/kernel/vmlinux.lds.S | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index 6db90cdf11da..b6c765d8e7ee 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -187,6 +187,11 @@ SECTIONS
 	.init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
 		_sinittext = .;
 		INIT_TEXT
+
+		/* .init.text might be RO so we must
+		* ensure this section ends in a page boundary.
+		*/
+		. = ALIGN(PAGE_SIZE);
 		_einittext = .;
 #ifdef CONFIG_PPC64
 		*(.tramp.ftrace.init);
@@ -200,6 +205,8 @@ SECTIONS
 		EXIT_TEXT
 	}
 
+	. = ALIGN(PAGE_SIZE);
+
 	.init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
 		INIT_DATA
 	}

base-commit: 2c85ebc57b3e1817b6ce1a6b703928e113a90442
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] powerpc: fix alignment bug whithin the init sections
  2021-01-02 20:11 [PATCH v2] powerpc: fix alignment bug whithin the init sections Ariel Marcovitch
@ 2021-01-11  7:06 ` Christophe Leroy
  2021-01-15 12:23 ` Michael Ellerman
  1 sibling, 0 replies; 3+ messages in thread
From: Christophe Leroy @ 2021-01-11  7:06 UTC (permalink / raw)
  To: Ariel Marcovitch, mpe
  Cc: keescook, maskray, linux-kernel, npiggin, oss, paulus,
	ariel.marcovitch, naveen.n.rao, linuxppc-dev, dja



Le 02/01/2021 à 21:11, Ariel Marcovitch a écrit :
> This is a bug that causes early crashes in builds with a
> .exit.text section smaller than a page and a .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: 060ef9d89d18 ("powerpc32: PAGE_EXEC required for inittext")
> Signed-off-by: Ariel Marcovitch <ariel.marcovitch@gmail.com>

Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>

> ---
>   arch/powerpc/kernel/vmlinux.lds.S | 7 +++++++
>   1 file changed, 7 insertions(+)
> 
> diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
> index 6db90cdf11da..b6c765d8e7ee 100644
> --- a/arch/powerpc/kernel/vmlinux.lds.S
> +++ b/arch/powerpc/kernel/vmlinux.lds.S
> @@ -187,6 +187,11 @@ SECTIONS
>   	.init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
>   		_sinittext = .;
>   		INIT_TEXT
> +
> +		/* .init.text might be RO so we must
> +		* ensure this section ends in a page boundary.
> +		*/
> +		. = ALIGN(PAGE_SIZE);
>   		_einittext = .;
>   #ifdef CONFIG_PPC64
>   		*(.tramp.ftrace.init);
> @@ -200,6 +205,8 @@ SECTIONS
>   		EXIT_TEXT
>   	}
>   
> +	. = ALIGN(PAGE_SIZE);
> +
>   	.init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
>   		INIT_DATA
>   	}
> 
> base-commit: 2c85ebc57b3e1817b6ce1a6b703928e113a90442
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] powerpc: fix alignment bug whithin the init sections
  2021-01-02 20:11 [PATCH v2] powerpc: fix alignment bug whithin the init sections Ariel Marcovitch
  2021-01-11  7:06 ` Christophe Leroy
@ 2021-01-15 12:23 ` Michael Ellerman
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2021-01-15 12:23 UTC (permalink / raw)
  To: Ariel Marcovitch, mpe
  Cc: keescook, maskray, linux-kernel, npiggin, oss, paulus,
	ariel.marcovitch, naveen.n.rao, linuxppc-dev, dja

On Sat, 2 Jan 2021 22:11:56 +0200, Ariel Marcovitch wrote:
> This is a bug that causes early crashes in builds with a
> .exit.text section smaller than a page and a .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
> 
> [...]

Applied to powerpc/fixes.

[1/1] powerpc: Fix alignment bug within the init sections
      https://git.kernel.org/powerpc/c/2225a8dda263edc35a0e8b858fe2945cf6240fde

cheers

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-01-15 12:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-02 20:11 [PATCH v2] powerpc: fix alignment bug whithin the init sections Ariel Marcovitch
2021-01-11  7:06 ` Christophe Leroy
2021-01-15 12:23 ` Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).