x86/cfi: Use symmetric SYM_START and SYM_END in __CFI_TYPE()
PATCH 1/1 x86/cfi: Use symmetric SYM_START and SYM_END in __CFI_TYPE()
Commit ccace936eec7 ("x86: Add types to indirectly called assembly functions") introduced a x86-specific implementation of __CFI_TYPE() using an asymmetric combination of SYM_START() and SYM_FUNC_END() to add a symbol to the KCFI type identifier that precedes a function.
This asymmetric combination is an issue if SYM_FUNC_END() ever gets extended in a way that requires it to be used symmetrically with SYM_FUNC_START*(). For instance to emit DWARF CFI directives that denote the start/end of a function. [1]
Use SYM_END() with SYM_T_FUNC instead. No functional change, as the generic implementation of SYM_FUNC_END(name) expands into SYM_END(name, SYM_T_FUNC).
---
Notes (jremus):
This patch applies on top of linus' tree (9716c086c8e8):
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
I verified as follows that in x86-64 builds of vmlinux using Clang with kCFI enabled without and with my patch applied vmlinux.o only differs in relocations targeting .rodata.str* and a few symbols in .rodata shifted (both likely due to differences in string merging):
$ objdump -d vmlinux.o > vmlinux.o.{old|new}.objdump $ readelf -Wa vmlinux.o > vmlinux.o.{old|new}.readelf $ diff -u vmlinux.o.old.objdump vmlinux.o.new.objdump [no differences]
$ diff -u0 vmlinux.o.old.readelf vmlinux.o.new.readelf | \
grep --invert-match -E "\.rodata\.str|@@"
[see above]
arch/x86/include/asm/linkage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/asm/linkage.h +1 -1
@@ -103,7 +103,7 @@ .byte 0xb8 ASM_NL \ .long __kcfi_typeid_##name ASM_NL \ CFI_POST_PADDING \ - SYM_FUNC_END(__cfi_##name) + SYM_END(__cfi_##name, SYM_T_FUNC)/* UML needs to be able to override memcpy() and friends for KASAN. */ #ifdef CONFIG_UML
Signature · 1 line
2.53.0
Quoted 10 lines · Jens Remus
Commit
ccace936eec7("x86: Add types to indirectly called assembly functions") introduced a x86-specific implementation of__CFI_TYPE()using an asymmetric combination ofSYM_START()andSYM_FUNC_END()to add a symbol to the KCFI type identifier that precedes a function.This asymmetric combination is an issue if
SYM_FUNC_END()ever gets extended in a way that requires it to be used symmetrically with SYM_FUNC_START*(). For instance to emit DWARF CFI directives that denote the start/end of a function. [1]
Quoted 7 lines
Use
SYM_END()withSYM_T_FUNCinstead. No functional change, as the generic implementation ofSYM_FUNC_END(name)expands intoSYM_END(name, SYM_T_FUNC).Reported-by Sashiko <[email protected]>Signed-off-by Jens Remus <[email protected]>
Quoted 10 lines · Jens Remus
Commit
ccace936eec7("x86: Add types to indirectly called assembly functions") introduced a x86-specific implementation of__CFI_TYPE()using an asymmetric combination ofSYM_START()andSYM_FUNC_END()to add a symbol to the KCFI type identifier that precedes a function.This asymmetric combination is an issue if
SYM_FUNC_END()ever gets extended in a way that requires it to be used symmetrically with SYM_FUNC_START*(). For instance to emit DWARF CFI directives that denote the start/end of a function. [1]
Quoted 7 lines
Use
SYM_END()withSYM_T_FUNCinstead. No functional change, as the generic implementation ofSYM_FUNC_END(name)expands intoSYM_END(name, SYM_T_FUNC).Reported-by Sashiko <[email protected]>Signed-off-by Jens Remus <[email protected]>
Quoted 39 lines
---
Notes (jremus):
This patch applies on top of linus' tree (9716c086c8e8):
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.gitmasterI verified as follows that in x86-64 builds of vmlinux using Clang with kCFI enabled without and with my patch applied vmlinux.o only differs in relocations targeting .rodata.str* and a few symbols in .rodata shifted (both likely due to differences in string merging):
$ objdump -d vmlinux.o > vmlinux.o.{old|new}.objdump $ readelf -Wa vmlinux.o > vmlinux.o.{old|new}.readelf $ diff -u vmlinux.o.old.objdump vmlinux.o.new.objdump [no differences]
$ diff -u0 vmlinux.o.old.readelf vmlinux.o.new.readelf | \
grep --invert-match -E "\.rodata\.str|@@"
[see above]arch/x86/include/asm/linkage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/include/asm/linkage.h +1
-1@@ -103,7 +103,7 @@ .byte 0xb8 ASM_NL \ .long __kcfi_typeid_##name ASM_NL \ CFI_POST_PADDING \ - SYM_FUNC_END(__cfi_##name) + SYM_END(__cfi_##name, SYM_T_FUNC)/* UML needs to be able to override memcpy() and friends for KASAN. */ #ifdef CONFIG_UML Signature · 1 line
2.53.0
Signature · 2 lines
Cheers, Nathan
The following commit has been merged into the x86/cleanups branch of tip:
The following commit has been merged into the x86/cleanups branch of tip:
Commit-ID: 0cfdf974f133e0ff17ed80e7895adbe7889d9522 Gitweb: https://git.kernel.org/tip/0cfdf974f133e0ff17ed80e7895adbe7889d9522 Author: Jens Remus <[email protected]> AuthorDate: Thu, 11 Jun 2026 17:57:15 +02:00 Committer: Borislav Petkov (AMD) <[email protected]> CommitterDate: Sun, 28 Jun 2026 15:22:26 -07:00
x86/cfi: Use symmetric SYM_START and SYM_END in __CFI_TYPE()
Commit
ccace936eec7 ("x86: Add types to indirectly called assembly functions")
introduced a x86-specific implementation of __CFI_TYPE() using an asymmetric combination of SYM_START() and SYM_FUNC_END() to add a symbol to the KCFI type identifier that precedes a function.
This asymmetric combination is an issue if SYM_FUNC_END() ever gets extended in a way that requires it to be used symmetrically with SYM_FUNC_START*(). For instance to emit DWARF CFI directives that denote the start/end of a function. [1]
Use SYM_END() with SYM_T_FUNC instead. No functional change, as the generic implementation of SYM_FUNC_END(name) expands into SYM_END(name, SYM_T_FUNC).
--- arch/x86/include/asm/linkage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/asm/linkage.h +1 -1
@@ -103,7 +103,7 @@ .byte 0xb8 ASM_NL \ .long __kcfi_typeid_##name ASM_NL \ CFI_POST_PADDING \ - SYM_FUNC_END(__cfi_##name) + SYM_END(__cfi_##name, SYM_T_FUNC)/* UML needs to be able to override memcpy() and friends for KASAN. */ #ifdef CONFIG_UML