Skip to content

Commit efc72a6

Browse files
jpoimboePeter Zijlstra
authored andcommitted
lkdtm: Disable return thunks in rodata.c
The following warning was seen: WARNING: CPU: 0 PID: 0 at arch/x86/kernel/alternative.c:557 apply_returns (arch/x86/kernel/alternative.c:557 (discriminator 1)) Modules linked in: CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.19.0-rc4-00008-gee88d363d156 #1 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.0-debian-1.16.0-4 04/01/2014 RIP: 0010:apply_returns (arch/x86/kernel/alternative.c:557 (discriminator 1)) Code: ff ff 74 cb 48 83 c5 04 49 39 ee 0f 87 81 fe ff ff e9 22 ff ff ff 0f 0b 48 83 c5 04 49 39 ee 0f 87 6d fe ff ff e9 0e ff ff ff <0f> 0b 48 83 c5 04 49 39 ee 0f 87 59 fe ff ff e9 fa fe ff ff 48 89 The warning happened when apply_returns() failed to convert "JMP __x86_return_thunk" to RET. It was instead a JMP to nowhere, due to the thunk relocation not getting resolved. That rodata.o code is objcopy'd to .rodata, and later memcpy'd, so relocations don't work (and are apparently silently ignored). LKDTM is only used for testing, so the naked RET should be fine. So just disable return thunks for that file. While at it, disable objtool and KCSAN for the file. Fixes: 0b53c37 ("x86/retpoline: Use -mfunction-return") Reported-by: kernel test robot <[email protected]> Debugged-by: Peter Zijlstra <[email protected]> Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/lkml/Ys58BxHxoDZ7rfpr@xsang-OptiPlex-9020/
1 parent eb23b5e commit efc72a6

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

arch/x86/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ RETHUNK_CFLAGS := -mfunction-return=thunk-extern
2727
RETPOLINE_CFLAGS += $(RETHUNK_CFLAGS)
2828
endif
2929

30+
export RETHUNK_CFLAGS
3031
export RETPOLINE_CFLAGS
3132
export RETPOLINE_VDSO_CFLAGS
3233

drivers/misc/lkdtm/Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ lkdtm-$(CONFIG_LKDTM) += cfi.o
1313
lkdtm-$(CONFIG_LKDTM) += fortify.o
1414
lkdtm-$(CONFIG_PPC_64S_HASH_MMU) += powerpc.o
1515

16-
KASAN_SANITIZE_rodata.o := n
1716
KASAN_SANITIZE_stackleak.o := n
18-
KCOV_INSTRUMENT_rodata.o := n
19-
CFLAGS_REMOVE_rodata.o += $(CC_FLAGS_LTO)
17+
18+
KASAN_SANITIZE_rodata.o := n
19+
KCSAN_SANITIZE_rodata.o := n
20+
KCOV_INSTRUMENT_rodata.o := n
21+
OBJECT_FILES_NON_STANDARD_rodata.o := y
22+
CFLAGS_REMOVE_rodata.o += $(CC_FLAGS_LTO) $(RETHUNK_CFLAGS)
2023

2124
OBJCOPYFLAGS :=
2225
OBJCOPYFLAGS_rodata_objcopy.o := \

0 commit comments

Comments
 (0)