linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/asm: Make asm export of __ref_stack_chk_guard unconditional
@ 2025-03-20 21:32 Ard Biesheuvel
  2025-03-20 23:14 ` Sami Tolvanen
  2025-03-21  7:39 ` [tip: x86/core] " tip-bot2 for Ard Biesheuvel
  0 siblings, 2 replies; 3+ messages in thread
From: Ard Biesheuvel @ 2025-03-20 21:32 UTC (permalink / raw)
  To: x86; +Cc: linux-kernel, samitolvanen, brgerst, Ard Biesheuvel

Clang does not tolerate the use of non-TLS symbols for the per-CPU stack
protector very well, and to work around this limitation, the symbol
passed via the -mstack-protector-guard-symbol= option is never defined
in C code, but only in the linker script, and it is exported from an
assembly file. This is necessary because Clang will fail to generate the
correct %GS based references in a compilation unit that includes a
non-TLS definition of the guard symbol being used to store the stack
cookie.

This problem is only triggered by symbol definitions, not by
declarations, but nonetheless, the declaration in <asm/asm-prototypes.h>
is conditional on __GENKSYMS__ being #define'd, so that only genksyms
will observe it, but for ordinary compilation, it will be invisible.

This is causing problems with the genksyms alternative gendwarfksyms,
which does not #define __GENKSYMS__, does not observe the symbol
declaration, and therefore lacks the information it needs to version it.
Adding the #define creates problems in other places, so that is not a
straight-forward solution. So take the easy way out, and drop the
conditional on __GENKSYMS__, as this is not really needed to begin with.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 arch/x86/include/asm/asm-prototypes.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/asm-prototypes.h b/arch/x86/include/asm/asm-prototypes.h
index 8d9e62725202..11c6fecc3ad7 100644
--- a/arch/x86/include/asm/asm-prototypes.h
+++ b/arch/x86/include/asm/asm-prototypes.h
@@ -20,6 +20,6 @@
 extern void cmpxchg8b_emu(void);
 #endif
 
-#if defined(__GENKSYMS__) && defined(CONFIG_STACKPROTECTOR)
+#ifdef CONFIG_STACKPROTECTOR
 extern unsigned long __ref_stack_chk_guard;
 #endif
-- 
2.47.2


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

* Re: [PATCH] x86/asm: Make asm export of __ref_stack_chk_guard unconditional
  2025-03-20 21:32 [PATCH] x86/asm: Make asm export of __ref_stack_chk_guard unconditional Ard Biesheuvel
@ 2025-03-20 23:14 ` Sami Tolvanen
  2025-03-21  7:39 ` [tip: x86/core] " tip-bot2 for Ard Biesheuvel
  1 sibling, 0 replies; 3+ messages in thread
From: Sami Tolvanen @ 2025-03-20 23:14 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: x86, linux-kernel, brgerst

On Thu, Mar 20, 2025 at 2:33 PM Ard Biesheuvel <ardb@kernel.org> wrote:
>
> Clang does not tolerate the use of non-TLS symbols for the per-CPU stack
> protector very well, and to work around this limitation, the symbol
> passed via the -mstack-protector-guard-symbol= option is never defined
> in C code, but only in the linker script, and it is exported from an
> assembly file. This is necessary because Clang will fail to generate the
> correct %GS based references in a compilation unit that includes a
> non-TLS definition of the guard symbol being used to store the stack
> cookie.
>
> This problem is only triggered by symbol definitions, not by
> declarations, but nonetheless, the declaration in <asm/asm-prototypes.h>
> is conditional on __GENKSYMS__ being #define'd, so that only genksyms
> will observe it, but for ordinary compilation, it will be invisible.
>
> This is causing problems with the genksyms alternative gendwarfksyms,
> which does not #define __GENKSYMS__, does not observe the symbol
> declaration, and therefore lacks the information it needs to version it.
> Adding the #define creates problems in other places, so that is not a
> straight-forward solution. So take the easy way out, and drop the
> conditional on __GENKSYMS__, as this is not really needed to begin with.
>
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> ---
>  arch/x86/include/asm/asm-prototypes.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/include/asm/asm-prototypes.h b/arch/x86/include/asm/asm-prototypes.h
> index 8d9e62725202..11c6fecc3ad7 100644
> --- a/arch/x86/include/asm/asm-prototypes.h
> +++ b/arch/x86/include/asm/asm-prototypes.h
> @@ -20,6 +20,6 @@
>  extern void cmpxchg8b_emu(void);
>  #endif
>
> -#if defined(__GENKSYMS__) && defined(CONFIG_STACKPROTECTOR)
> +#ifdef CONFIG_STACKPROTECTOR
>  extern unsigned long __ref_stack_chk_guard;
>  #endif

LGTM.

Reviewed-by: Sami Tolvanen <samitolvanen@google.com>

Sami

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

* [tip: x86/core] x86/asm: Make asm export of __ref_stack_chk_guard unconditional
  2025-03-20 21:32 [PATCH] x86/asm: Make asm export of __ref_stack_chk_guard unconditional Ard Biesheuvel
  2025-03-20 23:14 ` Sami Tolvanen
@ 2025-03-21  7:39 ` tip-bot2 for Ard Biesheuvel
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Ard Biesheuvel @ 2025-03-21  7:39 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Ard Biesheuvel, Ingo Molnar, Sami Tolvanen, x86, linux-kernel

The following commit has been merged into the x86/core branch of tip:

Commit-ID:     3e57612561138d7142721a83743fb8eb2bf09ec5
Gitweb:        https://git.kernel.org/tip/3e57612561138d7142721a83743fb8eb2bf09ec5
Author:        Ard Biesheuvel <ardb@kernel.org>
AuthorDate:    Thu, 20 Mar 2025 22:32:39 +01:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Fri, 21 Mar 2025 08:34:28 +01:00

x86/asm: Make asm export of __ref_stack_chk_guard unconditional

Clang does not tolerate the use of non-TLS symbols for the per-CPU stack
protector very well, and to work around this limitation, the symbol
passed via the -mstack-protector-guard-symbol= option is never defined
in C code, but only in the linker script, and it is exported from an
assembly file. This is necessary because Clang will fail to generate the
correct %GS based references in a compilation unit that includes a
non-TLS definition of the guard symbol being used to store the stack
cookie.

This problem is only triggered by symbol definitions, not by
declarations, but nonetheless, the declaration in <asm/asm-prototypes.h>
is conditional on __GENKSYMS__ being #define'd, so that only genksyms
will observe it, but for ordinary compilation, it will be invisible.

This is causing problems with the genksyms alternative gendwarfksyms,
which does not #define __GENKSYMS__, does not observe the symbol
declaration, and therefore lacks the information it needs to version it.
Adding the #define creates problems in other places, so that is not a
straight-forward solution. So take the easy way out, and drop the
conditional on __GENKSYMS__, as this is not really needed to begin with.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Sami Tolvanen <samitolvanen@google.com>
Link: https://lore.kernel.org/r/20250320213238.4451-2-ardb@kernel.org
---
 arch/x86/include/asm/asm-prototypes.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/asm-prototypes.h b/arch/x86/include/asm/asm-prototypes.h
index 8d9e627..11c6fec 100644
--- a/arch/x86/include/asm/asm-prototypes.h
+++ b/arch/x86/include/asm/asm-prototypes.h
@@ -20,6 +20,6 @@
 extern void cmpxchg8b_emu(void);
 #endif
 
-#if defined(__GENKSYMS__) && defined(CONFIG_STACKPROTECTOR)
+#ifdef CONFIG_STACKPROTECTOR
 extern unsigned long __ref_stack_chk_guard;
 #endif

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

end of thread, other threads:[~2025-03-21  7:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-20 21:32 [PATCH] x86/asm: Make asm export of __ref_stack_chk_guard unconditional Ard Biesheuvel
2025-03-20 23:14 ` Sami Tolvanen
2025-03-21  7:39 ` [tip: x86/core] " tip-bot2 for Ard Biesheuvel

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