x86/insn: Stop decoding i64 instructions in x86-64 mode at opcode
authorMasami Hiramatsu (Google) <mhiramat@kernel.org>
Mon, 28 Apr 2025 01:48:20 +0000 (10:48 +0900)
committerIngo Molnar <mingo@kernel.org>
Tue, 6 May 2025 10:03:16 +0000 (12:03 +0200)
commit4b626015e1bf119cd31d7e62f9bd9eb1412fce7b
treef1d3986efb8aab54a688d816f6cac1c0e15fc3b9
parentca698ec2f07873a448d53c580795c4e023c75393
x86/insn: Stop decoding i64 instructions in x86-64 mode at opcode

In commit 2e044911be75 ("x86/traps: Decode 0xEA instructions as #UD")
FineIBT starts using 0xEA as an invalid instruction like UD2. But
insn decoder always returns the length of "0xea" instruction as 7
because it does not check the (i64) superscript.

The x86 instruction decoder should also decode 0xEA on x86-64 as
a one-byte invalid instruction by decoding the "(i64)" superscript tag.

This stops decoding instruction which has (i64) but does not have (o64)
superscript in 64-bit mode at opcode and skips other fields.

With this change, insn_decoder_test says 0xea is 1 byte length if
x86-64 (-y option means 64-bit):

   $ printf "0:\tea\t\n" | insn_decoder_test -y -v
   insn_decoder_test: success: Decoded and checked 1 instructions

Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/174580490000.388420.5225447607417115496.stgit@devnote2
arch/x86/include/asm/inat.h
arch/x86/lib/insn.c
arch/x86/lib/x86-opcode-map.txt
arch/x86/tools/gen-insn-attr-x86.awk
tools/arch/x86/include/asm/inat.h
tools/arch/x86/lib/insn.c
tools/arch/x86/lib/x86-opcode-map.txt
tools/arch/x86/tools/gen-insn-attr-x86.awk