linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: x86@kernel.org, joao@overdrivepizza.com, hjl.tools@gmail.com,
	jpoimboe@redhat.com, andrew.cooper3@citrix.com
Cc: linux-kernel@vger.kernel.org, peterz@infradead.org,
	ndesaulniers@google.com, keescook@chromium.org,
	samitolvanen@google.com, mark.rutland@arm.com,
	alyssa.milburn@intel.com, mbenes@suse.cz, rostedt@goodmis.org,
	mhiramat@kernel.org, alexei.starovoitov@gmail.com
Subject: [PATCH v3 26/39] x86/ibt: Annotate text references
Date: Thu, 03 Mar 2022 12:23:47 +0100	[thread overview]
Message-ID: <20220303112826.543131850@infradead.org> (raw)
In-Reply-To: 20220303112321.422525803@infradead.org

Annotate away some of the generic code references. This is things
where we take the address of a symbol for exception handling or return
addresses (eg. context switch).

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 arch/x86/entry/entry_64.S            |    6 ++++++
 arch/x86/entry/entry_64_compat.S     |    1 +
 arch/x86/kernel/alternative.c        |    9 +++++++--
 arch/x86/kernel/head_64.S            |    4 ++++
 arch/x86/kernel/kprobes/core.c       |    1 +
 arch/x86/kernel/relocate_kernel_64.S |    2 ++
 arch/x86/lib/error-inject.c          |    2 ++
 arch/x86/lib/retpoline.S             |    1 +
 8 files changed, 24 insertions(+), 2 deletions(-)

--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -277,6 +277,7 @@ SYM_FUNC_END(__switch_to_asm)
 .pushsection .text, "ax"
 SYM_CODE_START(ret_from_fork)
 	UNWIND_HINT_EMPTY
+	ANNOTATE_NOENDBR // copy_thread
 	movq	%rax, %rdi
 	call	schedule_tail			/* rdi: 'prev' task parameter */
 
@@ -569,6 +570,7 @@ SYM_CODE_END(\asmsym)
 	.align 16
 	.globl __irqentry_text_end
 __irqentry_text_end:
+	ANNOTATE_NOENDBR
 
 SYM_CODE_START_LOCAL(common_interrupt_return)
 SYM_INNER_LABEL(swapgs_restore_regs_and_return_to_usermode, SYM_L_GLOBAL)
@@ -650,6 +652,7 @@ SYM_INNER_LABEL(early_xen_iret_patch, SY
 #endif
 
 SYM_INNER_LABEL(native_irq_return_iret, SYM_L_GLOBAL)
+	ANNOTATE_NOENDBR // exc_double_fault
 	/*
 	 * This may fault.  Non-paranoid faults on return to userspace are
 	 * handled by fixup_bad_iret.  These include #SS, #GP, and #NP.
@@ -744,6 +747,7 @@ SYM_FUNC_START(asm_load_gs_index)
 	FRAME_BEGIN
 	swapgs
 .Lgs_change:
+	ANNOTATE_NOENDBR // error_entry
 	movl	%edi, %gs
 2:	ALTERNATIVE "", "mfence", X86_BUG_SWAPGS_FENCE
 	swapgs
@@ -1322,6 +1326,7 @@ SYM_CODE_START(asm_exc_nmi)
 #endif
 
 repeat_nmi:
+	ANNOTATE_NOENDBR // this code
 	/*
 	 * If there was a nested NMI, the first NMI's iret will return
 	 * here. But NMIs are still enabled and we can take another
@@ -1350,6 +1355,7 @@ SYM_CODE_START(asm_exc_nmi)
 	.endr
 	subq	$(5*8), %rsp
 end_repeat_nmi:
+	ANNOTATE_NOENDBR // this code
 
 	/*
 	 * Everything below this point can be preempted by a nested NMI.
--- a/arch/x86/entry/entry_64_compat.S
+++ b/arch/x86/entry/entry_64_compat.S
@@ -148,6 +148,7 @@ SYM_INNER_LABEL(entry_SYSENTER_compat_af
 	popfq
 	jmp	.Lsysenter_flags_fixed
 SYM_INNER_LABEL(__end_entry_SYSENTER_compat, SYM_L_GLOBAL)
+	ANNOTATE_NOENDBR // is_sysenter_singlestep
 SYM_CODE_END(entry_SYSENTER_compat)
 
 /*
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -713,6 +713,7 @@ asm (
 "	.pushsection	.init.text, \"ax\", @progbits\n"
 "	.type		int3_magic, @function\n"
 "int3_magic:\n"
+	ANNOTATE_NOENDBR
 "	movl	$1, (%" _ASM_ARG1 ")\n"
 	ASM_RET
 "	.size		int3_magic, .-int3_magic\n"
@@ -724,16 +725,19 @@ extern void int3_selftest_ip(void); /* d
 static int __init
 int3_exception_notify(struct notifier_block *self, unsigned long val, void *data)
 {
+	unsigned long selftest = (unsigned long)&int3_selftest_ip;
 	struct die_args *args = data;
 	struct pt_regs *regs = args->regs;
 
+	OPTIMIZER_HIDE_VAR(selftest);
+
 	if (!regs || user_mode(regs))
 		return NOTIFY_DONE;
 
 	if (val != DIE_INT3)
 		return NOTIFY_DONE;
 
-	if (regs->ip - INT3_INSN_SIZE != (unsigned long)&int3_selftest_ip)
+	if (regs->ip - INT3_INSN_SIZE != selftest)
 		return NOTIFY_DONE;
 
 	int3_emulate_call(regs, (unsigned long)&int3_magic);
@@ -757,7 +761,8 @@ static void __init int3_selftest(void)
 	 * then trigger the INT3, padded with NOPs to match a CALL instruction
 	 * length.
 	 */
-	asm volatile ("int3_selftest_ip: int3; nop; nop; nop; nop\n\t"
+	asm volatile (ANNOTATE_NOENDBR
+		      "int3_selftest_ip: int3; nop; nop; nop; nop\n\t"
 		      : ASM_CALL_CONSTRAINT
 		      : __ASM_SEL_RAW(a, D) (&val)
 		      : "memory");
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -99,6 +99,7 @@ SYM_CODE_END(startup_64)
 
 SYM_CODE_START(secondary_startup_64)
 	UNWIND_HINT_EMPTY
+	ANNOTATE_NOENDBR
 	/*
 	 * At this point the CPU runs in 64bit mode CS.L = 1 CS.D = 0,
 	 * and someone has loaded a mapped page table.
@@ -127,6 +128,7 @@ SYM_CODE_START(secondary_startup_64)
 	 */
 SYM_INNER_LABEL(secondary_startup_64_no_verify, SYM_L_GLOBAL)
 	UNWIND_HINT_EMPTY
+	ANNOTATE_NOENDBR
 
 	/*
 	 * Retrieve the modifier (SME encryption mask if SME is active) to be
@@ -192,6 +194,7 @@ SYM_INNER_LABEL(secondary_startup_64_no_
 	jmp	*%rax
 1:
 	UNWIND_HINT_EMPTY
+	ANNOTATE_NOENDBR // above
 
 	/*
 	 * We must switch to a new descriptor in kernel space for the GDT
@@ -299,6 +302,7 @@ SYM_INNER_LABEL(secondary_startup_64_no_
 	pushq	%rax		# target address in negative space
 	lretq
 .Lafter_lret:
+	ANNOTATE_NOENDBR
 SYM_CODE_END(secondary_startup_64)
 
 #include "verify_cpu.S"
--- a/arch/x86/kernel/kprobes/core.c
+++ b/arch/x86/kernel/kprobes/core.c
@@ -1040,6 +1040,7 @@ asm(
 	".type __kretprobe_trampoline, @function\n"
 	"__kretprobe_trampoline:\n"
 #ifdef CONFIG_X86_64
+	ANNOTATE_NOENDBR
 	/* Push a fake return address to tell the unwinder it's a kretprobe. */
 	"	pushq $__kretprobe_trampoline\n"
 	UNWIND_HINT_FUNC
--- a/arch/x86/kernel/relocate_kernel_64.S
+++ b/arch/x86/kernel/relocate_kernel_64.S
@@ -42,6 +42,7 @@
 	.code64
 SYM_CODE_START_NOALIGN(relocate_kernel)
 	UNWIND_HINT_EMPTY
+	ANNOTATE_NOENDBR
 	/*
 	 * %rdi indirection_page
 	 * %rsi page_list
@@ -223,6 +224,7 @@ SYM_CODE_END(identity_mapped)
 
 SYM_CODE_START_LOCAL_NOALIGN(virtual_mapped)
 	UNWIND_HINT_EMPTY
+	ANNOTATE_NOENDBR // RET target, above
 	movq	RSP(%r8), %rsp
 	movq	CR4(%r8), %rax
 	movq	%rax, %cr4
--- a/arch/x86/lib/error-inject.c
+++ b/arch/x86/lib/error-inject.c
@@ -3,6 +3,7 @@
 #include <linux/linkage.h>
 #include <linux/error-injection.h>
 #include <linux/kprobes.h>
+#include <linux/objtool.h>
 
 asmlinkage void just_return_func(void);
 
@@ -11,6 +12,7 @@ asm(
 	".type just_return_func, @function\n"
 	".globl just_return_func\n"
 	"just_return_func:\n"
+		ANNOTATE_NOENDBR
 		ASM_RET
 	".size just_return_func, .-just_return_func\n"
 );
--- a/arch/x86/lib/retpoline.S
+++ b/arch/x86/lib/retpoline.S
@@ -55,6 +55,7 @@ SYM_INNER_LABEL(__x86_indirect_thunk_\re
 
 	.align RETPOLINE_THUNK_SIZE
 SYM_CODE_START(__x86_indirect_thunk_array)
+	ANNOTATE_NOENDBR // apply_retpolines
 
 #define GEN(reg) THUNK reg
 #include <asm/GEN-for-each-reg.h>



  parent reply	other threads:[~2022-03-03 11:33 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-03 11:23 [PATCH v3 00/39] x86: Kernel IBT Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 01/39] static_call: Avoid building empty .static_call_sites Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 02/39] x86/module: Fix the paravirt vs alternative order Peter Zijlstra
2022-03-08 13:58   ` [tip: x86/urgent] " tip-bot2 for Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 03/39] objtool: Add --dry-run Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 04/39] x86/ibt: Base IBT bits Peter Zijlstra
2022-03-07 11:17   ` Peter Zijlstra
2022-03-07 12:25     ` Joao Moreira
2022-03-07 18:19       ` Nick Desaulniers
2022-03-03 11:23 ` [PATCH v3 05/39] x86/ibt: Add ANNOTATE_NOENDBR Peter Zijlstra
2022-03-04 18:59   ` Josh Poimboeuf
2022-03-04 20:22     ` Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 06/39] x86/text-patching: Make text_gen_insn() play nice with ANNOTATE_NOENDBR Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 07/39] x86/ibt,paravirt: Use text_gen_insn() for paravirt_patch() Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 08/39] x86/entry: Cleanup PARAVIRT Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 09/39] x86/entry,xen: Early rewrite of restore_regs_and_return_to_kernel() Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 10/39] x86/ibt,xen: Sprinkle the ENDBR Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 11/39] x86/ibt,entry: Sprinkle ENDBR dust Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 12/39] x86/linkage: Add ENDBR to SYM_FUNC_START*() Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 13/39] x86/ibt,paravirt: Sprinkle ENDBR Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 14/39] x86/ibt,crypto: Add ENDBR for the jump-table entries Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 15/39] x86/ibt,kvm: Add ENDBR to fastops Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 16/39] x86/ibt,ftrace: Search for __fentry__ location Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 17/39] x86/livepatch: Validate " Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 18/39] x86/ibt,ftrace: Make function-graph play nice Peter Zijlstra
2022-03-04 17:51   ` Josh Poimboeuf
2022-03-04 19:48     ` Peter Zijlstra
2022-03-04 21:03       ` Josh Poimboeuf
2022-03-04 21:44         ` Peter Zijlstra
2022-03-04 22:05           ` Josh Poimboeuf
2022-03-04 23:08       ` David Laight
2022-03-03 11:23 ` [PATCH v3 19/39] x86/ibt,kprobes: Cure sym+0 equals fentry woes Peter Zijlstra
2022-03-07  9:44   ` Masami Hiramatsu
2022-03-03 11:23 ` [PATCH v3 20/39] x86/ibt,bpf: Add ENDBR instructions to prologue and trampoline Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 21/39] x86/ibt,ftrace: Add ENDBR to samples/ftrace Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 22/39] x86/ibt: Add IBT feature, MSR and #CP handling Peter Zijlstra
2022-03-04 17:57   ` Josh Poimboeuf
2022-03-04 20:38     ` Peter Zijlstra
2022-03-04 18:07   ` Josh Poimboeuf
2022-03-04 20:39     ` Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 23/39] x86/alternative: Simplify int3_selftest_ip Peter Zijlstra
2022-03-04 18:02   ` Josh Poimboeuf
2022-03-04 18:09     ` Josh Poimboeuf
2022-03-03 11:23 ` [PATCH v3 24/39] x86/ibt: Disable IBT around firmware Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 25/39] x86/bugs: Disable Retpoline when IBT Peter Zijlstra
2022-03-04 17:39   ` Josh Poimboeuf
2022-03-03 11:23 ` Peter Zijlstra [this message]
2022-03-03 11:23 ` [PATCH v3 27/39] x86/ibt,ftrace: Annotate ftrace code patching Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 28/39] x86/ibt,sev: Annotations Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 29/39] x86/ibt: Dont generate ENDBR in .discard.text Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 30/39] x86/ibt: Ensure module init/exit points have references Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 31/39] objtool: Rename --duplicate to --lto Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 32/39] Kbuild: Allow whole module objtool runs Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 33/39] objtool: Read the NOENDBR annotation Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 34/39] objtool: Have WARN_FUNC fall back to sym+off Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 35/39] objtool: Add IBT/ENDBR decoding Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 36/39] objtool: Validate IBT assumptions Peter Zijlstra
2022-03-03 11:23 ` [PATCH v3 37/39] objtool: Optionally WARN about unused ANNOTATE_NOENDBR Peter Zijlstra
2022-03-04 18:27   ` Josh Poimboeuf
2022-03-03 11:23 ` [PATCH v3 38/39] objtool: Find unused ENDBR instructions Peter Zijlstra
2022-03-03 11:24 ` [PATCH v3 39/39] x86/alternative: Use .ibt_endbr_seal to seal indirect calls Peter Zijlstra
2022-03-04 19:09 ` [PATCH v3 00/39] x86: Kernel IBT Josh Poimboeuf
2022-03-04 20:22   ` Peter Zijlstra
2022-03-04 21:39   ` Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220303112826.543131850@infradead.org \
    --to=peterz@infradead.org \
    --cc=alexei.starovoitov@gmail.com \
    --cc=alyssa.milburn@intel.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=hjl.tools@gmail.com \
    --cc=joao@overdrivepizza.com \
    --cc=jpoimboe@redhat.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mbenes@suse.cz \
    --cc=mhiramat@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=rostedt@goodmis.org \
    --cc=samitolvanen@google.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).