Skip to content

Commit 545ac14

Browse files
joergroedelsuryasaimadhu
authored andcommitted
x86/sev-es: Check regs->sp is trusted before adjusting #VC IST stack
The code in the NMI handler to adjust the #VC handler IST stack is needed in case an NMI hits when the #VC handler is still using its IST stack. But the check for this condition also needs to look if the regs->sp value is trusted, meaning it was not set by user-space. Extend the check to not use regs->sp when the NMI interrupted user-space code or the SYSCALL gap. Fixes: 315562c ("x86/sev-es: Adjust #VC IST Stack on entering NMI handler") Reported-by: Andy Lutomirski <[email protected]> Signed-off-by: Joerg Roedel <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Cc: [email protected] # 5.10+ Link: https://lkml.kernel.org/r/[email protected]
1 parent 78a81d8 commit 545ac14

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

arch/x86/kernel/sev-es.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,18 @@ static void __init setup_vc_stacks(int cpu)
121121
cea_set_pte((void *)vaddr, pa, PAGE_KERNEL);
122122
}
123123

124-
static __always_inline bool on_vc_stack(unsigned long sp)
124+
static __always_inline bool on_vc_stack(struct pt_regs *regs)
125125
{
126+
unsigned long sp = regs->sp;
127+
128+
/* User-mode RSP is not trusted */
129+
if (user_mode(regs))
130+
return false;
131+
132+
/* SYSCALL gap still has user-mode RSP */
133+
if (ip_within_syscall_gap(regs))
134+
return false;
135+
126136
return ((sp >= __this_cpu_ist_bottom_va(VC)) && (sp < __this_cpu_ist_top_va(VC)));
127137
}
128138

@@ -144,7 +154,7 @@ void noinstr __sev_es_ist_enter(struct pt_regs *regs)
144154
old_ist = __this_cpu_read(cpu_tss_rw.x86_tss.ist[IST_INDEX_VC]);
145155

146156
/* Make room on the IST stack */
147-
if (on_vc_stack(regs->sp))
157+
if (on_vc_stack(regs))
148158
new_ist = ALIGN_DOWN(regs->sp, 8) - sizeof(old_ist);
149159
else
150160
new_ist = old_ist - sizeof(old_ist);

0 commit comments

Comments
 (0)