Commit 32c52ec87d62 for kernel

commit 32c52ec87d6245ee2d12ed5dd509e40062939b50
Author: Lukas Zobernig <lukas.zobernig@gmail.com>
Date:   Fri Oct 16 15:04:35 2026 -1000

    x86/insn-eval: Fix shadowed segment index in get_seg_reg_override_idx()

    Commit 45e1dccc0653 ("x86/insn: Simplify for_each_insn_prefix()") made
    for_each_insn_prefix() declare its own loop counter named idx.
    get_seg_reg_override_idx() keeps its result in a local of the same name,
    so the assignments in the loop body now write the loop counter:

     - the function always returns INAT_SEG_REG_DEFAULT, so FS and GS
       overrides are ignored;

     - a CS override sets the counter to INAT_SEG_REG_CS (2), the increment
       makes it 3, and prefixes.bytes[3] holds the last prefix, 0x2e again,
       so the loop never terminates.

    The UMIP emulation reaches this from the #GP handler for user space: an
    SGDT, SIDT or SMSW with a memory operand and a CS prefix leaves the task
    spinning in the kernel, never returning to user space, with a SIGKILL
    that is never delivered.  Any user can thus tie up CPUs until reboot.
    With an FS or GS prefix, the emulated result is written to the wrong
    address.

    Rename the internal macro iterator variable.

    [ Lukas' original patch renamed the use site, I changed it to rename the
      iterator in the macro instead, but left Lukas' commit message and
      authorship   - Linus ]

    Fixes: 45e1dccc0653 ("x86/insn: Simplify for_each_insn_prefix()")
    Signed-off-by: Lukas Zobernig <lukas.zobernig@gmail.com>
    Acked-by: Peter Zijlstra <peterz@infradead.org>
    Acked-by: Borislav Petkov <bp@alien8.de>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

diff --git a/arch/x86/include/asm/insn.h b/arch/x86/include/asm/insn.h
index 846d21c1a7f8..8fb92da1a2c4 100644
--- a/arch/x86/include/asm/insn.h
+++ b/arch/x86/include/asm/insn.h
@@ -321,7 +321,7 @@ static inline int insn_offset_immediate(struct insn *insn)
  * are repeated, it cannot be used for looping over the prefixes.
  */
 #define for_each_insn_prefix(insn, prefix)	\
-	for (int idx = 0; idx < ARRAY_SIZE(insn->prefixes.bytes) && (prefix = insn->prefixes.bytes[idx]) != 0; idx++)
+	for (int __i = 0; __i < ARRAY_SIZE(insn->prefixes.bytes) && (prefix = insn->prefixes.bytes[__i]) != 0; __i++)

 #define POP_SS_OPCODE 0x1f
 #define MOV_SREG_OPCODE 0x8e
diff --git a/tools/arch/x86/include/asm/insn.h b/tools/arch/x86/include/asm/insn.h
index 8f10f2943370..1d2903508bbe 100644
--- a/tools/arch/x86/include/asm/insn.h
+++ b/tools/arch/x86/include/asm/insn.h
@@ -321,7 +321,7 @@ static inline int insn_offset_immediate(struct insn *insn)
  * are repeated, it cannot be used for looping over the prefixes.
  */
 #define for_each_insn_prefix(insn, prefix)	\
-	for (int idx = 0; idx < ARRAY_SIZE(insn->prefixes.bytes) && (prefix = insn->prefixes.bytes[idx]) != 0; idx++)
+	for (int __i = 0; __i < ARRAY_SIZE(insn->prefixes.bytes) && (prefix = insn->prefixes.bytes[__i]) != 0; __i++)

 #define POP_SS_OPCODE 0x1f
 #define MOV_SREG_OPCODE 0x8e