]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
s390: Add stackprotector support
authorHeiko Carstens <hca@linux.ibm.com>
Mon, 17 Nov 2025 14:09:53 +0000 (15:09 +0100)
committerHeiko Carstens <hca@linux.ibm.com>
Mon, 24 Nov 2025 10:45:21 +0000 (11:45 +0100)
commitf5730d44e05efb43a5cb64e5eb04e24994bbb50f
tree452349b7820c4531d56c494ff54c55da5b1c429a
parent1d7764cfe33626f8487febbcb2ad2acc9bd14c2c
s390: Add stackprotector support

Stackprotector support was previously unavailable on s390 because by
default compilers generate code which is not suitable for the kernel:
the canary value is accessed via thread local storage, where the address
of thread local storage is within access registers 0 and 1.

Using those registers also for the kernel would come with a significant
performance impact and more complicated kernel entry/exit code, since
access registers contents would have to be exchanged on every kernel entry
and exit.

With the upcoming gcc 16 release new compiler options will become available
which allow to generate code suitable for the kernel. [1]

Compiler option -mstack-protector-guard=global instructs gcc to generate
stackprotector code that refers to a global stackprotector canary value via
symbol __stack_chk_guard. Access to this value is guaranteed to occur via
larl and lgrl instructions.

Furthermore, compiler option -mstack-protector-guard-record generates a
section containing all code addresses that reference the canary value.

To allow for per task canary values the instructions which load the address
of __stack_chk_guard are patched so they access a lowcore field instead: a
per task canary value is available within the task_struct of each task, and
is written to the per-cpu lowcore location on each context switch.

Also add sanity checks and debugging option to be consistent with other
kernel code patching mechanisms.

Full debugging output can be enabled with the following kernel command line
options:

debug_stackprotector
bootdebug
ignore_loglevel
earlyprintk
dyndbg="file stackprotector.c +p"

Example debug output:

stackprot: 0000021e402d4edac010005a9ae3 -> c01f00070240

where "<insn address>: <old insn> -> <new insn>".

[1] gcc commit 0cd1f03939d5 ("s390: Support global stack protector")

Reviewed-by: Sven Schnelle <svens@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
18 files changed:
arch/s390/Kconfig
arch/s390/Makefile
arch/s390/boot/Makefile
arch/s390/boot/boot.h
arch/s390/boot/ipl_parm.c
arch/s390/boot/stackprotector.c [new file with mode: 0644]
arch/s390/boot/startup.c
arch/s390/include/asm/arch-stackprotector.h [new file with mode: 0644]
arch/s390/include/asm/lowcore.h
arch/s390/include/asm/stackprotector.h [new file with mode: 0644]
arch/s390/kernel/Makefile
arch/s390/kernel/asm-offsets.c
arch/s390/kernel/entry.S
arch/s390/kernel/module.c
arch/s390/kernel/smp.c
arch/s390/kernel/stackprotector.c [new file with mode: 0644]
arch/s390/kernel/vdso64/Makefile
arch/s390/kernel/vmlinux.lds.S