Commit 48eee6181d for qemu.org
commit 48eee6181d3a3e0372a8f316b2d5c2527927cca7
Author: NickSampanis <nicksampanis@gmail.com>
Date: Mon Oct 26 01:18:03 2026 +0200
target/i386/tcg: Fix 64-bit RSP truncation on far call through a call gate
In long mode, a call gate is 16 bytes and always has a 64-bit target.
For a same-privilege call through a call gate, which can also be reached
by a compatibility-mode caller, lcall_protected uses
get_sp_mask(SS.flags) even though the pushes are 8 bytes.
Consequently, the pushes and the stack pointer update (SET_ESP)
truncate RSP. This is the same bug as in the previous two patches.
Use the full stack pointer when shift == 2, the same as the
inner-privilege branch. This condition tests the gate's own size
rather than the caller's mode, which is why it checks shift == 2
instead of HF_CS64_MASK.
Signed-off-by: NickSampanis <nicksampanis@gmail.com>
Link: https://lore.kernel.org/r/20261025231803.870-4-nicksampanis@gmail.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
diff --git a/target/i386/tcg/seg_helper.c b/target/i386/tcg/seg_helper.c
index 87492a2f64..f11b55d136 100644
--- a/target/i386/tcg/seg_helper.c
+++ b/target/i386/tcg/seg_helper.c
@@ -1925,7 +1925,12 @@ void HELPER(lcall_protected)(CPUX86State *env, int new_cs, target_ulong new_eip,
/* to same privilege */
sa.mmu_index = x86_mmu_index_pl(env, cpl);
sa.sp = env->regs[R_ESP];
- sa.sp_mask = get_sp_mask(env->segs[R_SS].flags);
+#ifdef TARGET_X86_64
+ if (shift == 2) {
+ sa.sp_mask = -1;
+ } else
+#endif
+ sa.sp_mask = get_sp_mask(env->segs[R_SS].flags);
sa.ss_base = env->segs[R_SS].base;
/* push_size = (4 << shift); */
new_stack = 0;