Skip to content

Commit b388e57

Browse files
jpoimboebp3tk0v
authored andcommitted
x86/vdso: Fix rethunk patching for vdso-image-{32,64}.o
For CONFIG_RETHUNK kernels, objtool annotates all the function return sites so they can be patched during boot. By design, after apply_returns() is called, all tail-calls to the compiler-generated default return thunk (__x86_return_thunk) should be patched out and replaced with whatever's needed for any mitigations (or lack thereof). The commit 4461438 ("x86/retpoline: Ensure default return thunk isn't used at runtime") adds a runtime check and a WARN_ONCE() if the default return thunk ever gets executed after alternatives have been applied. This warning is a sanity check to make sure objtool and apply_returns() are doing their job. As Nathan reported, that check found something: Unpatched return thunk in use. This should not happen! WARNING: CPU: 0 PID: 1 at arch/x86/kernel/cpu/bugs.c:2856 __warn_thunk+0x27/0x40 RIP: 0010:__warn_thunk+0x27/0x40 Call Trace: <TASK> ? show_regs ? __warn ? __warn_thunk ? report_bug ? console_unlock ? handle_bug ? exc_invalid_op ? asm_exc_invalid_op ? ia32_binfmt_init ? __warn_thunk warn_thunk_thunk do_one_initcall kernel_init_freeable ? __pfx_kernel_init kernel_init ret_from_fork ? __pfx_kernel_init ret_from_fork_asm </TASK> Boris debugged to find that the unpatched return site was in init_vdso_image_64(), and its translation unit wasn't being analyzed by objtool, so it never got annotated. So it got ignored by apply_returns(). This is only a minor issue, as this function is only called during boot. Still, objtool needs full visibility to the kernel. Fix it by enabling objtool on vdso-image-{32,64}.o. Note this problem can only be seen with !CONFIG_X86_KERNEL_IBT, as that requires objtool to run individually on all translation units rather on vmlinux.o. [ bp: Massage commit message. ] Reported-by: Nathan Chancellor <nathan@kernel.org> Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/20240215032049.GA3944823@dev-arch.thelio-3990X
1 parent 4589f19 commit b388e57

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

arch/x86/entry/vdso/Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,19 @@ obj-y += vma.o extable.o
3434
KASAN_SANITIZE_vma.o := y
3535
UBSAN_SANITIZE_vma.o := y
3636
KCSAN_SANITIZE_vma.o := y
37-
OBJECT_FILES_NON_STANDARD_vma.o := n
38-
OBJECT_FILES_NON_STANDARD_extable.o := n
37+
38+
OBJECT_FILES_NON_STANDARD_extable.o := n
39+
OBJECT_FILES_NON_STANDARD_vdso-image-32.o := n
40+
OBJECT_FILES_NON_STANDARD_vdso-image-64.o := n
41+
OBJECT_FILES_NON_STANDARD_vdso32-setup.o := n
42+
OBJECT_FILES_NON_STANDARD_vma.o := n
3943

4044
# vDSO images to build
4145
vdso_img-$(VDSO64-y) += 64
4246
vdso_img-$(VDSOX32-y) += x32
4347
vdso_img-$(VDSO32-y) += 32
4448

4549
obj-$(VDSO32-y) += vdso32-setup.o
46-
OBJECT_FILES_NON_STANDARD_vdso32-setup.o := n
4750

4851
vobjs := $(foreach F,$(vobjs-y),$(obj)/$F)
4952
vobjs32 := $(foreach F,$(vobjs32-y),$(obj)/$F)

0 commit comments

Comments
 (0)