ARM: cfi: Fix compilation corner case
PATCH 1/1 ARM: cfi: Fix compilation corner case
When enabling expert mode CONFIG_EXPERT and using that power user mode to disable the branch prediction hardening !CONFIG_HARDEN_BRANCH_PREDICTOR, the picky assembly linker in CLANG notices that some assembly in proc-v7.S does not have corresponding C call sites, i.e. the prototypes in proc-v7-bugs.c are enclosed in ifdef CONFIG_HARDEN_BRANCH_PREDICTOR so this assembly:
SYM_TYPED_FUNC_START(cpu_v7_smc_switch_mm)SYM_TYPED_FUNC_START(cpu_v7_hvc_switch_mm)
Results in:
ld.lld: error: undefined symbol: __kcfi_typeid_cpu_v7_smc_switch_mm
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
referenced by proc-v7.S:94 (
.../arch/arm/mm/proc-v7.S:94) arch/arm/mm/proc-v7.o:(.text+0x108) in archive vmlinux.a
ld.lld: error: undefined symbol: __kcfi_typeid_cpu_v7_hvc_switch_mm
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
referenced by proc-v7.S:105 (
.../arch/arm/mm/proc-v7.S:105) arch/arm/mm/proc-v7.o:(.text+0x124) in archive vmlinux.a
Fix this by adding an additional requirement that CONFIG_HARDEN_BRANCH_PREDICTOR has to be enabled to compile these assembly calls.
I suppose it wasn't a problem before because the linker is not so picky that other assembly symbols are actually being used.
--- arch/arm/mm/proc-v7.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mm/proc-v7.S +1 -1
@@ -94,7 +94,7 @@ SYM_TYPED_FUNC_START(cpu_v7_dcache_clean_area) ret lr SYM_FUNC_END(cpu_v7_dcache_clean_area) -#ifdef CONFIG_ARM_PSCI +#if defined(CONFIG_ARM_PSCI) && defined(CONFIG_HARDEN_BRANCH_PREDICTOR) .arch_extension sec SYM_TYPED_FUNC_START(cpu_v7_smc_switch_mm) stmfd sp!, {r0 - r3}
---
base-commit: 9852d85ec9d492ebef56dc5f229416c925758edc
change-id: 20241107-fix-kcfi-bug-ae3b08cbc167
Best regards,
Signature · 1 line
Linus Walleij <[email protected]>
Quoted 21 lines · Linus Walleij
When enabling expert mode
CONFIG_EXPERTand using that power user mode to disable the branch prediction hardening !CONFIG_HARDEN_BRANCH_PREDICTOR, the picky assembly linker in CLANG notices that some assembly inproc-v7.Sdoes not have corresponding C call sites, i.e. the prototypes inproc-v7-bugs.care enclosed in ifdefCONFIG_HARDEN_BRANCH_PREDICTORso this assembly:
SYM_TYPED_FUNC_START(cpu_v7_smc_switch_mm)SYM_TYPED_FUNC_START(cpu_v7_hvc_switch_mm)Results in:
ld.lld: error: undefined symbol:
__kcfi_typeid_cpu_v7_smc_switch_mmQuoted 2 lines
Quoted 2 lines
Quoted 2 lines
referenced by proc-v7.S:94 (
.../arch/arm/mm/proc-v7.S:94) arch/arm/mm/proc-v7.o:(.text+0x108) in archive vmlinux.ald.lld: error: undefined symbol:
__kcfi_typeid_cpu_v7_hvc_switch_mmQuoted 2 lines
Quoted 2 lines
Quoted 2 lines
referenced by proc-v7.S:105 (
.../arch/arm/mm/proc-v7.S:105) arch/arm/mm/proc-v7.o:(.text+0x124) in archive vmlinux.a
Quoted 7 lines
Fix this by adding an additional requirement that
CONFIG_HARDEN_BRANCH_PREDICTORhas to be enabled to compile these assembly calls.I suppose it wasn't a problem before because the linker is not so picky that other assembly symbols are actually being used.
I think this has been a problem since the original CFI change, so I think it is worth dropping this block; it is more likely that CONFIG_HARDEN_BRANCH_PREDICTOR is not often disabled outside of randconfig, so it is hard to hit this issue in practice. As far as I can tell, this is totally expected with the given configuration. SYM_TYPED_FUNC_START makes use of __kcfi_typeid_<func>, which the compiler generates for address-taken function declarations, but in this configuration, cpu_v7_smc_switch_mm() and cpu_v7_hvc_switch_mm() have no actual uses aside from their definition, so the compiler does not generate these symbols, resulting in the link time error above. Perhaps some of this could be encorporated into the beginning of the commit message to make the issue a little more clear and less like the compiler is at fault here ("the picky assembly linker" stands out a bit to me there).
Quoted 3 lines
Reported-by kernel test robot <[email protected]>Signed-off-by Linus Walleij <[email protected]>
Regardless of the commit message nits, this seems like the right thing to do.
Quoted 26 lines
--- arch/arm/mm/proc-v7.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/arm/mm/proc-v7.S +1
-2@@ -94,7 +94,7 @@ SYM_TYPED_FUNC_START(cpu_v7_dcache_clean_area) ret lr SYM_FUNC_END(cpu_v7_dcache_clean_area) -#ifdef CONFIG_ARM_PSCI +#if defined(CONFIG_ARM_PSCI) && defined(CONFIG_HARDEN_BRANCH_PREDICTOR) .arch_extension sec SYM_TYPED_FUNC_START(cpu_v7_smc_switch_mm) stmfd sp!, {r0 - r3} ---base-commit:
9852d85ec9d492ebef56dc5f229416c925758edc
change-id: 20241107-fix-kcfi-bug-ae3b08cbc167Best regards,
Signature · 1 line
Linus Walleij <[email protected]>
Quoted 4 lines · Nathan Chancellor
Regardless of the commit message nits, this seems like the right thing to do.
Reviewed-by Nathan Chancellor <[email protected]>
Thanks Nathan, I dropped all the annoying complaints about pickiness in the commit message (after all, compilers should be picky, it's a defining trait...) and put the patch into Russell's arfmlpatch tracker.
Yours,
Linus Walleij