linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86: fix .bss with -fdata-sections
@ 2019-04-15 16:49 Sami Tolvanen
  2019-04-15 17:33 ` Nick Desaulniers
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sami Tolvanen @ 2019-04-15 16:49 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, H . Peter Anvin,
	Nicholas Piggin, x86, linux-kernel
  Cc: Kees Cook, Nick Desaulniers, Sami Tolvanen

With LD_DEAD_CODE_DATA_ELIMINATION, we compile the kernel with
-fdata-sections, which also splits the .bss section. Use the
common BSS_MAIN macro in the linker script to properly merge all
the generated sections.

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
---
 arch/x86/kernel/vmlinux.lds.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index bad8c51fee6e..a5127b2c195f 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -362,7 +362,7 @@ SECTIONS
 	.bss : AT(ADDR(.bss) - LOAD_OFFSET) {
 		__bss_start = .;
 		*(.bss..page_aligned)
-		*(.bss)
+		*(BSS_MAIN)
 		BSS_DECRYPTED
 		. = ALIGN(PAGE_SIZE);
 		__bss_stop = .;
-- 
2.21.0.392.gf8f6787159e-goog


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

* Re: [PATCH] x86: fix .bss with -fdata-sections
  2019-04-15 16:49 [PATCH] x86: fix .bss with -fdata-sections Sami Tolvanen
@ 2019-04-15 17:33 ` Nick Desaulniers
  2019-04-16  3:23 ` Kees Cook
  2019-04-16  6:25 ` [tip:x86/urgent] x86/build/lto: Fix truncated " tip-bot for Sami Tolvanen
  2 siblings, 0 replies; 4+ messages in thread
From: Nick Desaulniers @ 2019-04-15 17:33 UTC (permalink / raw)
  To: Sami Tolvanen, Nicholas Piggin
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, H . Peter Anvin,
	x86, LKML, Kees Cook

On Mon, Apr 15, 2019 at 9:50 AM Sami Tolvanen <samitolvanen@google.com> wrote:
>
> With LD_DEAD_CODE_DATA_ELIMINATION, we compile the kernel with
> -fdata-sections, which also splits the .bss section. Use the
> common BSS_MAIN macro in the linker script to properly merge all
> the generated sections.
>
> Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
> ---
>  arch/x86/kernel/vmlinux.lds.S | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
> index bad8c51fee6e..a5127b2c195f 100644
> --- a/arch/x86/kernel/vmlinux.lds.S
> +++ b/arch/x86/kernel/vmlinux.lds.S
> @@ -362,7 +362,7 @@ SECTIONS
>         .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
>                 __bss_start = .;
>                 *(.bss..page_aligned)
> -               *(.bss)
> +               *(BSS_MAIN)
>                 BSS_DECRYPTED
>                 . = ALIGN(PAGE_SIZE);
>                 __bss_stop = .;
> --
> 2.21.0.392.gf8f6787159e-goog
>

Thanks for the patch!  I checked as well that this issue doesn't exist
for .text, .data, .sdata, .rodata, and .sbss; just .bss had this
issue.  Looks like this is "no functional change" when
CONFIG_LD_DEAD_CODE_DATA_ELIMINATION is not set; it simply fixes the
case where CONFIG_LD_DEAD_CODE_DATA_ELIMINATION=y.
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

Nicholas,
I don't understand the comment about RODATA_MAIN from commit
266ff2a8f51f ("kbuild: Fix asm-generic/vmlinux.lds.h for
LD_DEAD_CODE_DATA_ELIMINATION").  It seems that there are no uses of
RODATA_MAIN in the kernel.  Can we remove its definition and that
comment? (That's neither here nor there for this patch).
-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH] x86: fix .bss with -fdata-sections
  2019-04-15 16:49 [PATCH] x86: fix .bss with -fdata-sections Sami Tolvanen
  2019-04-15 17:33 ` Nick Desaulniers
@ 2019-04-16  3:23 ` Kees Cook
  2019-04-16  6:25 ` [tip:x86/urgent] x86/build/lto: Fix truncated " tip-bot for Sami Tolvanen
  2 siblings, 0 replies; 4+ messages in thread
From: Kees Cook @ 2019-04-16  3:23 UTC (permalink / raw)
  To: Sami Tolvanen, Ingo Molnar
  Cc: Thomas Gleixner, Borislav Petkov, H . Peter Anvin,
	Nicholas Piggin, X86 ML, LKML, Kees Cook, Nick Desaulniers

On Mon, Apr 15, 2019 at 11:50 AM Sami Tolvanen <samitolvanen@google.com> wrote:
>
> With LD_DEAD_CODE_DATA_ELIMINATION, we compile the kernel with
> -fdata-sections, which also splits the .bss section. Use the
> common BSS_MAIN macro in the linker script to properly merge all
> the generated sections.
>
> Signed-off-by: Sami Tolvanen <samitolvanen@google.com>

Nice work tracking this down! :)

Reviewed-by: Kees Cook <keescook@chromium.org>

Nit/tweak/clarification for commit title:
    x86/build: Fix truncated .bss with -fdata-sections

-Kees

> ---
>  arch/x86/kernel/vmlinux.lds.S | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
> index bad8c51fee6e..a5127b2c195f 100644
> --- a/arch/x86/kernel/vmlinux.lds.S
> +++ b/arch/x86/kernel/vmlinux.lds.S
> @@ -362,7 +362,7 @@ SECTIONS
>         .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
>                 __bss_start = .;
>                 *(.bss..page_aligned)
> -               *(.bss)
> +               *(BSS_MAIN)
>                 BSS_DECRYPTED
>                 . = ALIGN(PAGE_SIZE);
>                 __bss_stop = .;
> --
> 2.21.0.392.gf8f6787159e-goog
>


-- 
Kees Cook

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

* [tip:x86/urgent] x86/build/lto: Fix truncated .bss with -fdata-sections
  2019-04-15 16:49 [PATCH] x86: fix .bss with -fdata-sections Sami Tolvanen
  2019-04-15 17:33 ` Nick Desaulniers
  2019-04-16  3:23 ` Kees Cook
@ 2019-04-16  6:25 ` tip-bot for Sami Tolvanen
  2 siblings, 0 replies; 4+ messages in thread
From: tip-bot for Sami Tolvanen @ 2019-04-16  6:25 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, torvalds, mingo, bp, npiggin, tglx, samitolvanen,
	keescook, hpa, peterz, ndesaulniers

Commit-ID:  6a03469a1edc94da52b65478f1e00837add869a3
Gitweb:     https://git.kernel.org/tip/6a03469a1edc94da52b65478f1e00837add869a3
Author:     Sami Tolvanen <samitolvanen@google.com>
AuthorDate: Mon, 15 Apr 2019 09:49:56 -0700
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 16 Apr 2019 08:20:55 +0200

x86/build/lto: Fix truncated .bss with -fdata-sections

With CONFIG_LD_DEAD_CODE_DATA_ELIMINATION=y, we compile the kernel with
-fdata-sections, which also splits the .bss section.

The new section, with a new .bss.* name, which pattern gets missed by the
main x86 linker script which only expects the '.bss' name. This results
in the discarding of the second part and a too small, truncated .bss
section and an unhappy, non-working kernel.

Use the common BSS_MAIN macro in the linker script to properly capture
and merge all the generated BSS sections.

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20190415164956.124067-1-samitolvanen@google.com
[ Extended the changelog. ]
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/vmlinux.lds.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index bad8c51fee6e..a5127b2c195f 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -362,7 +362,7 @@ SECTIONS
 	.bss : AT(ADDR(.bss) - LOAD_OFFSET) {
 		__bss_start = .;
 		*(.bss..page_aligned)
-		*(.bss)
+		*(BSS_MAIN)
 		BSS_DECRYPTED
 		. = ALIGN(PAGE_SIZE);
 		__bss_stop = .;

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

end of thread, other threads:[~2019-04-16  6:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-15 16:49 [PATCH] x86: fix .bss with -fdata-sections Sami Tolvanen
2019-04-15 17:33 ` Nick Desaulniers
2019-04-16  3:23 ` Kees Cook
2019-04-16  6:25 ` [tip:x86/urgent] x86/build/lto: Fix truncated " tip-bot for Sami Tolvanen

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).