Skip to content

Commit 2d7ce49

Browse files
jpoimboebp3tk0v
authored andcommitted
x86/retpoline: Make sure there are no unconverted return thunks due to KCSAN
Enabling CONFIG_KCSAN leads to unconverted, default return thunks to remain after patching. As David Kaplan describes in his debugging of the issue, it is caused by a couple of KCSAN-generated constructors which aren't processed by objtool: "When KCSAN is enabled, GCC generates lots of constructor functions named _sub_I_00099_0 which call __tsan_init and then return. The returns in these are generally annotated normally by objtool and fixed up at runtime. But objtool runs on vmlinux.o and vmlinux.o does not include a couple of object files that are in vmlinux, like init/version-timestamp.o and .vmlinux.export.o, both of which contain _sub_I_00099_0 functions. As a result, the returns in these functions are not annotated, and the panic occurs when we call one of them in do_ctors and it uses the default return thunk. This difference can be seen by counting the number of these functions in the object files: $ objdump -d vmlinux.o|grep -c "<_sub_I_00099_0>:" 2601 $ objdump -d vmlinux|grep -c "<_sub_I_00099_0>:" 2603 If these functions are only run during kernel boot, there is no speculation concern." Fix it by disabling KCSAN on version-timestamp.o and .vmlinux.export.o so the extra functions don't get generated. KASAN and GCOV are already disabled for those files. [ bp: Massage commit message. ] Closes: https://lore.kernel.org/lkml/[email protected]/ Reported-by: Nathan Chancellor <[email protected]> Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Nick Desaulniers <[email protected]> Acked-by: Marco Elver <[email protected]> Tested-by: Nathan Chancellor <[email protected]> Link: https://lore.kernel.org/r/20231017165946.v4i2d4exyqwqq3bx@treble
1 parent 321a145 commit 2d7ce49

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

init/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,5 @@ include/generated/utsversion.h: FORCE
6060
$(obj)/version-timestamp.o: include/generated/utsversion.h
6161
CFLAGS_version-timestamp.o := -include include/generated/utsversion.h
6262
KASAN_SANITIZE_version-timestamp.o := n
63+
KCSAN_SANITIZE_version-timestamp.o := n
6364
GCOV_PROFILE_version-timestamp.o := n

scripts/Makefile.vmlinux

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ quiet_cmd_cc_o_c = CC $@
1919

2020
ifdef CONFIG_MODULES
2121
KASAN_SANITIZE_.vmlinux.export.o := n
22+
KCSAN_SANITIZE_.vmlinux.export.o := n
2223
GCOV_PROFILE_.vmlinux.export.o := n
2324
targets += .vmlinux.export.o
2425
vmlinux: .vmlinux.export.o

0 commit comments

Comments
 (0)