x86/objtool: Teach objtool about ERET[US]
authorH. Peter Anvin (Intel) <hpa@zytor.com>
Tue, 5 Dec 2023 10:49:59 +0000 (02:49 -0800)
committerBorislav Petkov (AMD) <bp@alien8.de>
Wed, 31 Jan 2024 21:00:30 +0000 (22:00 +0100)
Update the objtool decoder to know about the ERET[US] instructions
(type INSN_CONTEXT_SWITCH).

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Signed-off-by: Xin Li <xin3.li@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Tested-by: Shan Kang <shan.kang@intel.com>
Link: https://lore.kernel.org/r/20231205105030.8698-11-xin3.li@intel.com
tools/objtool/arch/x86/decode.c

index e327cd8271352264ff2eb389d82948d502f77465..3a1d80a7878d335b490df2fd17accc6d961b9879 100644 (file)
@@ -509,11 +509,20 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
 
                if (op2 == 0x01) {
 
-                       if (modrm == 0xca)
-                               insn->type = INSN_CLAC;
-                       else if (modrm == 0xcb)
-                               insn->type = INSN_STAC;
-
+                       switch (insn_last_prefix_id(&ins)) {
+                       case INAT_PFX_REPE:
+                       case INAT_PFX_REPNE:
+                               if (modrm == 0xca)
+                                       /* eretu/erets */
+                                       insn->type = INSN_CONTEXT_SWITCH;
+                               break;
+                       default:
+                               if (modrm == 0xca)
+                                       insn->type = INSN_CLAC;
+                               else if (modrm == 0xcb)
+                                       insn->type = INSN_STAC;
+                               break;
+                       }
                } else if (op2 >= 0x80 && op2 <= 0x8f) {
 
                        insn->type = INSN_JUMP_CONDITIONAL;