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 v2 28/39] x86/ibt,xen: Sprinkle the ENDBR
Date: Thu, 24 Feb 2022 15:52:06 +0100	[thread overview]
Message-ID: <20220224151323.661210297@infradead.org> (raw)
In-Reply-To: 20220224145138.952963315@infradead.org

Even though Xen currently doesn't advertise IBT, prepare for when it
will eventually do so and sprinkle the ENDBR dust accordingly.

Even though most of the entry points are IRET like, the CPL0
Hypervisor can set WAIT-FOR-ENDBR and demand ENDBR at these sites.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 arch/x86/entry/entry_64.S      |    1 +
 arch/x86/include/asm/segment.h |    2 +-
 arch/x86/kernel/head_64.S      |    1 +
 arch/x86/xen/enlighten_pv.c    |    3 +++
 arch/x86/xen/xen-asm.S         |   10 ++++++++++
 arch/x86/xen/xen-head.S        |    8 ++++++--
 6 files changed, 22 insertions(+), 3 deletions(-)

--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -822,6 +822,7 @@ SYM_CODE_END(exc_xen_hypervisor_callback
  */
 SYM_CODE_START(xen_failsafe_callback)
 	UNWIND_HINT_EMPTY
+	ENDBR
 	movl	%ds, %ecx
 	cmpw	%cx, 0x10(%rsp)
 	jne	1f
--- a/arch/x86/include/asm/segment.h
+++ b/arch/x86/include/asm/segment.h
@@ -283,7 +283,7 @@ static inline void vdso_read_cpunode(uns
  * pop %rcx; pop %r11; jmp early_idt_handler_array[i]; summing up to
  * max 8 bytes.
  */
-#define XEN_EARLY_IDT_HANDLER_SIZE 8
+#define XEN_EARLY_IDT_HANDLER_SIZE (8 + 4*HAS_KERNEL_IBT)
 
 #ifndef __ASSEMBLY__
 
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -389,6 +389,7 @@ SYM_CODE_START(early_idt_handler_array)
 	.fill early_idt_handler_array + i*EARLY_IDT_HANDLER_SIZE - ., 1, 0xcc
 	.endr
 SYM_CODE_END(early_idt_handler_array)
+	ANNOTATE_NOENDBR // early_idt_handler_array[NUM_EXCEPTION_VECTORS]
 
 SYM_CODE_START_LOCAL(early_idt_handler_common)
 	UNWIND_HINT_IRET_REGS offset=16
--- a/arch/x86/xen/enlighten_pv.c
+++ b/arch/x86/xen/enlighten_pv.c
@@ -624,6 +624,9 @@ static struct trap_array_entry trap_arra
 	TRAP_ENTRY(exc_coprocessor_error,		false ),
 	TRAP_ENTRY(exc_alignment_check,			false ),
 	TRAP_ENTRY(exc_simd_coprocessor_error,		false ),
+#ifdef CONFIG_X86_KERNEL_IBT
+	TRAP_ENTRY(exc_control_protection,		false ),
+#endif
 };
 
 static bool __ref get_trap_addr(void **addr, unsigned int ist)
--- a/arch/x86/xen/xen-asm.S
+++ b/arch/x86/xen/xen-asm.S
@@ -122,6 +122,7 @@ SYM_FUNC_END(xen_read_cr2_direct);
 .macro xen_pv_trap name
 SYM_CODE_START(xen_\name)
 	UNWIND_HINT_EMPTY
+	ENDBR
 	pop %rcx
 	pop %r11
 	jmp  \name
@@ -147,6 +148,9 @@ xen_pv_trap asm_exc_page_fault
 xen_pv_trap asm_exc_spurious_interrupt_bug
 xen_pv_trap asm_exc_coprocessor_error
 xen_pv_trap asm_exc_alignment_check
+#ifdef CONFIG_X86_KERNEL_IBT
+xen_pv_trap asm_exc_control_protection
+#endif
 #ifdef CONFIG_X86_MCE
 xen_pv_trap asm_xenpv_exc_machine_check
 #endif /* CONFIG_X86_MCE */
@@ -162,6 +166,7 @@ SYM_CODE_START(xen_early_idt_handler_arr
 	i = 0
 	.rept NUM_EXCEPTION_VECTORS
 	UNWIND_HINT_EMPTY
+	ENDBR
 	pop %rcx
 	pop %r11
 	jmp early_idt_handler_array + i*EARLY_IDT_HANDLER_SIZE
@@ -169,6 +174,7 @@ SYM_CODE_START(xen_early_idt_handler_arr
 	.fill xen_early_idt_handler_array + i*XEN_EARLY_IDT_HANDLER_SIZE - ., 1, 0xcc
 	.endr
 SYM_CODE_END(xen_early_idt_handler_array)
+	ANNOTATE_NOENDBR
 	__FINIT
 
 hypercall_iret = hypercall_page + __HYPERVISOR_iret * 32
@@ -231,6 +237,7 @@ SYM_CODE_END(xenpv_restore_regs_and_retu
 /* Normal 64-bit system call target */
 SYM_CODE_START(xen_syscall_target)
 	UNWIND_HINT_EMPTY
+	ENDBR
 	popq %rcx
 	popq %r11
 
@@ -250,6 +257,7 @@ SYM_CODE_END(xen_syscall_target)
 /* 32-bit compat syscall target */
 SYM_CODE_START(xen_syscall32_target)
 	UNWIND_HINT_EMPTY
+	ENDBR
 	popq %rcx
 	popq %r11
 
@@ -267,6 +275,7 @@ SYM_CODE_END(xen_syscall32_target)
 /* 32-bit compat sysenter target */
 SYM_CODE_START(xen_sysenter_target)
 	UNWIND_HINT_EMPTY
+	ENDBR
 	/*
 	 * NB: Xen is polite and clears TF from EFLAGS for us.  This means
 	 * that we don't need to guard against single step exceptions here.
@@ -290,6 +299,7 @@ SYM_CODE_END(xen_sysenter_target)
 SYM_CODE_START(xen_syscall32_target)
 SYM_CODE_START(xen_sysenter_target)
 	UNWIND_HINT_EMPTY
+	ENDBR
 	lea 16(%rsp), %rsp	/* strip %rcx, %r11 */
 	mov $-ENOSYS, %rax
 	pushq $0
--- a/arch/x86/xen/xen-head.S
+++ b/arch/x86/xen/xen-head.S
@@ -25,8 +25,11 @@
 SYM_CODE_START(hypercall_page)
 	.rept (PAGE_SIZE / 32)
 		UNWIND_HINT_FUNC
-		.skip 31, 0x90
-		RET
+		ANNOTATE_NOENDBR
+		/*
+		 * Xen will write the hypercall page, and sort out ENDBR.
+		 */
+		.skip 32, 0xcc
 	.endr
 
 #define HYPERCALL(n) \
@@ -74,6 +77,7 @@ SYM_CODE_END(startup_xen)
 .pushsection .text
 SYM_CODE_START(asm_cpu_bringup_and_idle)
 	UNWIND_HINT_EMPTY
+	ENDBR
 
 	call cpu_bringup_and_idle
 SYM_CODE_END(asm_cpu_bringup_and_idle)



  parent reply	other threads:[~2022-02-24 15:19 UTC|newest]

Thread overview: 183+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-24 14:51 [PATCH v2 00/39] x86: Kernel IBT Peter Zijlstra
2022-02-24 14:51 ` [PATCH v2 01/39] kbuild: Fix clang build Peter Zijlstra
2022-02-25  0:11   ` Kees Cook
2022-03-01 21:16   ` Nick Desaulniers
2022-03-02  0:47     ` Kees Cook
2022-03-02  0:53       ` Fangrui Song
2022-03-02 16:37     ` Nathan Chancellor
2022-03-02 18:40       ` Kees Cook
2022-03-02 19:18       ` Nick Desaulniers
2022-03-02 21:15         ` Nathan Chancellor
2022-03-02 22:07           ` Nick Desaulniers
2022-03-02 23:00           ` Kees Cook
2022-03-02 23:10           ` Peter Zijlstra
2022-02-24 14:51 ` [PATCH v2 02/39] static_call: Avoid building empty .static_call_sites Peter Zijlstra
2022-02-24 14:51 ` [PATCH v2 03/39] x86/module: Fix the paravirt vs alternative order Peter Zijlstra
2022-03-01 14:37   ` Miroslav Benes
2022-02-24 14:51 ` [PATCH v2 04/39] objtool: Add --dry-run Peter Zijlstra
2022-02-25  0:27   ` Kees Cook
2022-03-01 14:37   ` Miroslav Benes
2022-02-24 14:51 ` [PATCH v2 05/39] x86: Base IBT bits Peter Zijlstra
2022-02-25  0:35   ` Kees Cook
2022-02-25  0:46     ` Nathan Chancellor
2022-02-25 22:08       ` Nathan Chancellor
2022-02-26  0:29         ` Joao Moreira
2022-02-26  4:58           ` Kees Cook
2022-02-26  4:59             ` Fāng-ruì Sòng
2022-02-26  5:04               ` Kees Cook
2022-02-25 13:41     ` Peter Zijlstra
2022-02-24 14:51 ` [PATCH v2 06/39] x86/ibt: Add ANNOTATE_NOENDBR Peter Zijlstra
2022-02-25  0:36   ` Kees Cook
2022-02-24 14:51 ` [PATCH v2 07/39] x86/entry: Sprinkle ENDBR dust Peter Zijlstra
2022-02-24 22:37   ` Josh Poimboeuf
2022-02-25  0:42   ` Kees Cook
2022-02-25  9:22     ` Andrew Cooper
2022-02-24 14:51 ` [PATCH v2 08/39] x86/linkage: Add ENDBR to SYM_FUNC_START*() Peter Zijlstra
2022-02-25  0:45   ` Kees Cook
2022-02-24 14:51 ` [PATCH v2 09/39] x86/ibt,paravirt: Sprinkle ENDBR Peter Zijlstra
2022-02-25  0:47   ` Kees Cook
2022-02-24 14:51 ` [PATCH v2 10/39] x86/ibt,crypto: Add ENDBR for the jump-table entries Peter Zijlstra
2022-02-24 22:41   ` Josh Poimboeuf
2022-02-25  0:50   ` Kees Cook
2022-02-25 10:22     ` Peter Zijlstra
2022-02-24 14:51 ` [PATCH v2 11/39] x86/ibt,kvm: Add ENDBR to fastops Peter Zijlstra
2022-02-25  0:54   ` Kees Cook
2022-02-25 10:24     ` Peter Zijlstra
2022-02-25 13:09       ` David Laight
2022-02-24 14:51 ` [PATCH v2 12/39] x86/ibt,ftrace: Search for __fentry__ location Peter Zijlstra
2022-02-24 15:55   ` Masami Hiramatsu
2022-02-24 15:58     ` Steven Rostedt
2022-02-24 15:59       ` Steven Rostedt
2022-02-24 16:01       ` Steven Rostedt
2022-02-24 22:46         ` Josh Poimboeuf
2022-02-24 22:51           ` Steven Rostedt
2022-02-25  1:34       ` Masami Hiramatsu
2022-02-25  2:19         ` Steven Rostedt
2022-02-25 10:20           ` Masami Hiramatsu
2022-02-25 13:36             ` Steven Rostedt
2022-03-01 18:57               ` Naveen N. Rao
2022-03-01 19:20                 ` Steven Rostedt
2022-03-02 13:20                   ` Peter Zijlstra
2022-03-02 16:01                     ` Steven Rostedt
2022-03-02 19:47                       ` Steven Rostedt
2022-03-02 20:48                         ` Steven Rostedt
2022-03-02 20:51                         ` Peter Zijlstra
2022-03-03  9:45                           ` Naveen N. Rao
2022-03-03 13:04                             ` Peter Zijlstra
2022-03-03 14:34                               ` Steven Rostedt
2022-03-03 15:59                                 ` Peter Zijlstra
2022-03-06  3:48                                   ` Masami Hiramatsu
2022-03-09 11:47                                   ` Naveen N. Rao
2022-03-03 14:39                               ` Naveen N. Rao
2022-02-25  0:55   ` Kees Cook
2022-03-02 16:25   ` Naveen N. Rao
2022-02-24 14:51 ` [PATCH v2 13/39] x86/livepatch: Validate " Peter Zijlstra
2022-02-24 23:02   ` Josh Poimboeuf
2022-02-24 14:51 ` [PATCH v2 14/39] x86/ibt,ftrace: Make function-graph play nice Peter Zijlstra
2022-02-24 15:36   ` Peter Zijlstra
2022-02-24 15:42     ` Steven Rostedt
2022-02-24 23:09       ` Peter Zijlstra
2022-02-24 14:51 ` [PATCH v2 15/39] x86/ibt,kprobes: Fix more +0 assumptions Peter Zijlstra
2022-02-25  0:58   ` Kees Cook
2022-02-25  1:32   ` Masami Hiramatsu
2022-02-25 10:46     ` Peter Zijlstra
2022-02-25 13:42       ` Masami Hiramatsu
2022-02-25 15:41         ` Peter Zijlstra
2022-02-26  2:10           ` Masami Hiramatsu
2022-02-26 11:48             ` Peter Zijlstra
2022-02-25 14:14       ` Steven Rostedt
2022-02-26  7:09         ` Masami Hiramatsu
2022-02-28  6:07   ` Masami Hiramatsu
2022-02-28 23:25     ` Peter Zijlstra
2022-03-01  2:49       ` Masami Hiramatsu
2022-03-01  8:28         ` Peter Zijlstra
2022-03-01 17:19           ` Naveen N. Rao
2022-03-01 19:12             ` Peter Zijlstra
2022-03-01 20:05               ` Peter Zijlstra
2022-03-02 15:59                 ` Naveen N. Rao
2022-03-02 16:38                   ` Peter Zijlstra
2022-03-02 16:17                 ` Naveen N. Rao
2022-03-02 19:32                   ` Peter Zijlstra
2022-03-02 19:39                     ` Peter Zijlstra
2022-03-03 12:11                       ` Naveen N. Rao
2022-03-03  1:54                   ` Masami Hiramatsu
2022-03-02  0:11           ` Masami Hiramatsu
2022-03-02 10:25             ` Peter Zijlstra
2022-03-01 17:03       ` Naveen N. Rao
2022-02-24 14:51 ` [PATCH v2 16/39] x86/bpf: Add ENDBR instructions to prologue and trampoline Peter Zijlstra
2022-02-24 23:37   ` Josh Poimboeuf
2022-02-25  0:59     ` Kees Cook
2022-02-25 11:20     ` Peter Zijlstra
2022-02-25 12:24     ` Peter Zijlstra
2022-02-25 22:46       ` Josh Poimboeuf
2022-02-24 14:51 ` [PATCH v2 17/39] x86/ibt,ftrace: Add ENDBR to samples/ftrace Peter Zijlstra
2022-02-24 14:51 ` [PATCH v2 18/39] x86/ibt: Add IBT feature, MSR and #CP handling Peter Zijlstra
2022-02-24 23:55   ` Josh Poimboeuf
2022-02-25 10:51     ` Peter Zijlstra
2022-02-25 11:10       ` Peter Zijlstra
2022-02-25 23:51       ` Josh Poimboeuf
2022-02-26 11:55         ` Peter Zijlstra
2022-02-25  1:09   ` Kees Cook
2022-02-25 19:59   ` Edgecombe, Rick P
2022-03-01 15:14     ` Peter Zijlstra
2022-03-01 21:02       ` Peter Zijlstra
2022-03-01 23:13         ` Josh Poimboeuf
2022-03-02  1:59           ` Edgecombe, Rick P
2022-03-02 13:49             ` Peter Zijlstra
2022-03-02 18:38               ` Kees Cook
2022-02-24 14:51 ` [PATCH v2 19/39] x86: Disable IBT around firmware Peter Zijlstra
2022-02-25  1:10   ` Kees Cook
2022-02-24 14:51 ` [PATCH v2 20/39] x86/bugs: Disable Retpoline when IBT Peter Zijlstra
2022-02-25  1:11   ` Kees Cook
2022-02-25  2:22     ` Josh Poimboeuf
2022-02-25 10:55     ` Peter Zijlstra
2022-02-24 14:51 ` [PATCH v2 21/39] x86/ibt: Annotate text references Peter Zijlstra
2022-02-25  0:47   ` Josh Poimboeuf
2022-02-25 12:57     ` Peter Zijlstra
2022-02-25 13:04     ` Peter Zijlstra
2022-02-24 14:52 ` [PATCH v2 22/39] x86/ibt,ftrace: Annotate ftrace code patching Peter Zijlstra
2022-02-24 14:52 ` [PATCH v2 23/39] x86/ibt,sev: Annotations Peter Zijlstra
2022-02-24 14:52 ` [PATCH v2 24/39] x86/text-patching: Make text_gen_insn() IBT aware Peter Zijlstra
2022-02-25  0:49   ` Josh Poimboeuf
2022-02-24 14:52 ` [PATCH v2 25/39] x86/ibt,paravirt: Use text_gen_insn() for paravirt_patch() Peter Zijlstra
2022-02-24 14:52 ` [PATCH v2 26/39] x86/entry: Cleanup PARAVIRT Peter Zijlstra
2022-02-24 14:52 ` [PATCH v2 27/39] x86/entry,xen: Early rewrite of restore_regs_and_return_to_kernel() Peter Zijlstra
2022-02-24 17:51   ` Andrew Cooper
2022-02-24 14:52 ` Peter Zijlstra [this message]
2022-02-25  0:54   ` [PATCH v2 28/39] x86/ibt,xen: Sprinkle the ENDBR Josh Poimboeuf
2022-02-25 13:16     ` Peter Zijlstra
2022-02-24 14:52 ` [PATCH v2 29/39] objtool: Rename --duplicate to --lto Peter Zijlstra
2022-02-24 14:52 ` [PATCH v2 30/39] Kbuild: Allow whole module objtool runs Peter Zijlstra
2022-02-24 14:52 ` [PATCH v2 31/39] objtool: Read the NOENDBR annotation Peter Zijlstra
2022-02-24 14:52 ` [PATCH v2 32/39] x86/ibt: Dont generate ENDBR in .discard.text Peter Zijlstra
2022-02-24 14:52 ` [PATCH v2 33/39] objtool: Add IBT/ENDBR decoding Peter Zijlstra
2022-03-03 10:53   ` Miroslav Benes
2022-03-03 11:06     ` Andrew Cooper
2022-03-03 12:33       ` Miroslav Benes
2022-03-03 14:13         ` Peter Zijlstra
2022-02-24 14:52 ` [PATCH v2 34/39] objtool: Validate IBT assumptions Peter Zijlstra
2022-02-27  3:13   ` Josh Poimboeuf
2022-02-27 17:00     ` Peter Zijlstra
2022-02-27 22:20       ` Josh Poimboeuf
2022-02-28  9:47         ` Peter Zijlstra
2022-02-28 18:36           ` Josh Poimboeuf
2022-02-28 20:10             ` Peter Zijlstra
2022-02-28  9:26       ` Peter Zijlstra
2022-02-28 18:39         ` Josh Poimboeuf
2022-02-24 14:52 ` [PATCH v2 35/39] objtool: IBT fix direct JMP/CALL Peter Zijlstra
2022-02-24 14:52 ` [PATCH v2 36/39] objtool: Find unused ENDBR instructions Peter Zijlstra
2022-02-27  3:46   ` Josh Poimboeuf
2022-02-28 12:41     ` Peter Zijlstra
2022-02-28 17:36       ` Josh Poimboeuf
2022-02-24 14:52 ` [PATCH v2 37/39] x86/ibt: Finish --ibt-fix-direct on module loading Peter Zijlstra
2022-02-24 14:52 ` [PATCH v2 38/39] x86/ibt: Ensure module init/exit points have references Peter Zijlstra
2022-02-24 14:52 ` [PATCH v2 39/39] x86/alternative: Use .ibt_endbr_sites to seal indirect calls Peter Zijlstra
2022-02-24 20:26 ` [PATCH v2 00/39] x86: Kernel IBT Josh Poimboeuf
2022-02-25 15:28   ` Peter Zijlstra
2022-02-25 15:43     ` Peter Zijlstra
2022-02-25 17:26       ` Josh Poimboeuf
2022-02-25 17:32         ` Steven Rostedt
2022-02-25 19:53           ` Peter Zijlstra
2022-02-25 20:15             ` Josh Poimboeuf
2022-03-01 23:10     ` Josh Poimboeuf
2022-03-02 10:20       ` 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=20220224151323.661210297@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).