]> git.ipfire.org Git - thirdparty/linux.git/commit
arm64: kernel: Manage absolute relocations in code built under pi/
authorArd Biesheuvel <ardb@kernel.org>
Wed, 14 Feb 2024 12:28:47 +0000 (13:28 +0100)
committerCatalin Marinas <catalin.marinas@arm.com>
Fri, 16 Feb 2024 12:42:28 +0000 (12:42 +0000)
commit48157aa39286b8eddfb81eeaab4d64d0231450e7
treeb4990c24508e8fd54a858d1462f71e450d3b1fe7
parent3567fa63cb5680d3e1e8375c547a0e305c8a0ff5
arm64: kernel: Manage absolute relocations in code built under pi/

The mini C runtime runs before relocations are processed, and so it
cannot rely on statically initialized pointer variables.

Add a check to ensure that such code does not get introduced by
accident, by going over the relocations in each object, identifying the
ones that operate on data sections that are part of the executable
image, and raising an error if any relocations of type R_AARCH64_ABS64
exist. Note that such relocations are permitted in other places (e.g.,
debug sections) and will never occur in compiler generated code sections
when using the small code model, so only check sections that have
SHF_ALLOC set and SHF_EXECINSTR cleared.

To accommodate cases where statically initialized symbol references are
unavoidable, introduce a special case for ELF input data sections that
have ".rodata.prel64" in their names, and in these cases, instead of
rejecting any encountered ABS64 relocations, convert them into PREL64
relocations, which don't require any runtime fixups. Note that the code
in question must still be modified to deal with this, as it needs to
convert the 64-bit signed offsets into absolute addresses before use.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20240214122845.2033971-46-ardb+git@google.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
arch/arm64/kernel/pi/Makefile
arch/arm64/kernel/pi/pi.h [new file with mode: 0644]
arch/arm64/kernel/pi/relacheck.c [new file with mode: 0644]