[PATCH v3 03/10] x86/traps: Decode 0xEA #UD

Peter Zijlstra posted 10 patches 10 months ago
There is a newer version of this series
[PATCH v3 03/10] x86/traps: Decode 0xEA #UD
Posted by Peter Zijlstra 10 months ago
FineIBT will start using 0xEA as #UD

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 arch/x86/include/asm/bug.h |    1 +
 arch/x86/kernel/traps.c    |   12 ++++++++++++
 2 files changed, 13 insertions(+)

--- a/arch/x86/include/asm/bug.h
+++ b/arch/x86/include/asm/bug.h
@@ -25,6 +25,7 @@
 #define BUG_UD2			0xfffe
 #define BUG_UD1			0xfffd
 #define BUG_UD1_UBSAN		0xfffc
+#define BUG_EA			0xffea
 
 #ifdef CONFIG_GENERIC_BUG
 
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -96,6 +96,7 @@ __always_inline int is_valid_bugaddr(uns
  * Check for UD1 or UD2, accounting for Address Size Override Prefixes.
  * If it's a UD1, further decode to determine its use:
  *
+ * FineIBT:      ea                      (bad)
  * UBSan{0}:     67 0f b9 00             ud1    (%eax),%eax
  * UBSan{10}:    67 0f b9 40 10          ud1    0x10(%eax),%eax
  * static_call:  0f b9 cc                ud1    %esp,%ecx
@@ -113,6 +114,10 @@ __always_inline int decode_bug(unsigned
 	v = *(u8 *)(addr++);
 	if (v == INSN_ASOP)
 		v = *(u8 *)(addr++);
+	if (v == 0xea) {
+		*len = addr - start;
+		return BUG_EA;
+	}
 	if (v != OPCODE_ESCAPE)
 		return BUG_NONE;
 
@@ -308,6 +313,13 @@ static noinstr bool handle_bug(struct pt
 		raw_local_irq_enable();
 
 	switch (ud_type) {
+	case BUG_EA:
+		if (handle_cfi_failure(regs) == BUG_TRAP_TYPE_WARN) {
+			regs->ip += ud_len;
+			handled = true;
+		}
+		break;
+
 	case BUG_UD2:
 		if (report_bug(regs->ip, regs) == BUG_TRAP_TYPE_WARN ||
 		    handle_cfi_failure(regs) == BUG_TRAP_TYPE_WARN) {
Re: [PATCH v3 03/10] x86/traps: Decode 0xEA #UD
Posted by Kees Cook 10 months ago
On Wed, Feb 19, 2025 at 05:21:10PM +0100, Peter Zijlstra wrote:
> FineIBT will start using 0xEA as #UD
> 
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>

Reviewed-by: Kees Cook <kees@kernel.org>

-- 
Kees Cook
Re: [PATCH v3 03/10] x86/traps: Decode 0xEA #UD
Posted by Andrew Cooper 10 months ago
On 19/02/2025 4:21 pm, Peter Zijlstra wrote:
> FineIBT will start using 0xEA as #UD
>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>

FINEIBT probably ought to gain a "depends on X86_64" too, or this is
going to go wrong in a very fun way.

~Andrew
Re: [PATCH v3 03/10] x86/traps: Decode 0xEA #UD
Posted by Peter Zijlstra 10 months ago
On Wed, Feb 19, 2025 at 04:47:10PM +0000, Andrew Cooper wrote:
> On 19/02/2025 4:21 pm, Peter Zijlstra wrote:
> > FineIBT will start using 0xEA as #UD
> >
> > Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> 
> FINEIBT probably ought to gain a "depends on X86_64" too, or this is
> going to go wrong in a very fun way.

It already is:

config X86_KERNEL_IBT
        depends on X86_64 && CC_HAS_IBT && HAVE_OBJTOOL


Nobody wants to touch i386 if they don't have to :-)