]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
x86/module: Deal with GOT based stack cookie load on Clang < 17
authorArd Biesheuvel <ardb@kernel.org>
Thu, 23 Jan 2025 19:07:38 +0000 (14:07 -0500)
committerIngo Molnar <mingo@kernel.org>
Tue, 18 Feb 2025 09:15:05 +0000 (10:15 +0100)
commit78c4374ef8b842c6abf195d6f963853c7ec464d2
tree189d6478e12933789e896952192cf2225550e7d3
parentcb7927fda002ca49ae62e2782c1692acc7b80c67
x86/module: Deal with GOT based stack cookie load on Clang < 17

Clang versions before 17 will not honour -fdirect-access-external-data
for the load of the stack cookie emitted into each function's prologue
and epilogue.

This is not an issue for the core kernel, as the linker will relax these
loads into LEA instructions that take the address of __stack_chk_guard
directly. For modules, however, we need to work around this, by dealing
with R_X86_64_REX_GOTPCRELX relocations that refer to __stack_chk_guard.

In this case, given that this is a GOT load, the reference should not
refer to __stack_chk_guard directly, but to a memory location that holds
its address. So take the address of __stack_chk_guard into a static
variable, and fix up the relocations to refer to that.

[ mingo: Fix broken R_X86_64_GOTPCRELX definition. ]

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Brian Gerst <brgerst@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20250123190747.745588-7-brgerst@gmail.com
arch/x86/include/asm/elf.h
arch/x86/kernel/module.c