Skip to content

Commit 78a81d8

Browse files
joergroedelsuryasaimadhu
authored andcommitted
x86/sev-es: Introduce ip_within_syscall_gap() helper
Introduce a helper to check whether an exception came from the syscall gap and use it in the SEV-ES code. Extend the check to also cover the compatibility SYSCALL entry path. Fixes: 315562c ("x86/sev-es: Adjust #VC IST Stack on entering NMI handler") 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 5d5675d commit 78a81d8

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

arch/x86/entry/entry_64_compat.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ SYM_CODE_START(entry_SYSCALL_compat)
210210
/* Switch to the kernel stack */
211211
movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp
212212

213+
SYM_INNER_LABEL(entry_SYSCALL_compat_safe_stack, SYM_L_GLOBAL)
214+
213215
/* Construct struct pt_regs on stack */
214216
pushq $__USER32_DS /* pt_regs->ss */
215217
pushq %r8 /* pt_regs->sp */

arch/x86/include/asm/proto.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ void __end_SYSENTER_singlestep_region(void);
2525
void entry_SYSENTER_compat(void);
2626
void __end_entry_SYSENTER_compat(void);
2727
void entry_SYSCALL_compat(void);
28+
void entry_SYSCALL_compat_safe_stack(void);
2829
void entry_INT80_compat(void);
2930
#ifdef CONFIG_XEN_PV
3031
void xen_entry_INT80_compat(void);

arch/x86/include/asm/ptrace.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ struct pt_regs {
9494
#include <asm/paravirt_types.h>
9595
#endif
9696

97+
#include <asm/proto.h>
98+
9799
struct cpuinfo_x86;
98100
struct task_struct;
99101

@@ -175,6 +177,19 @@ static inline bool any_64bit_mode(struct pt_regs *regs)
175177
#ifdef CONFIG_X86_64
176178
#define current_user_stack_pointer() current_pt_regs()->sp
177179
#define compat_user_stack_pointer() current_pt_regs()->sp
180+
181+
static inline bool ip_within_syscall_gap(struct pt_regs *regs)
182+
{
183+
bool ret = (regs->ip >= (unsigned long)entry_SYSCALL_64 &&
184+
regs->ip < (unsigned long)entry_SYSCALL_64_safe_stack);
185+
186+
#ifdef CONFIG_IA32_EMULATION
187+
ret = ret || (regs->ip >= (unsigned long)entry_SYSCALL_compat &&
188+
regs->ip < (unsigned long)entry_SYSCALL_compat_safe_stack);
189+
#endif
190+
191+
return ret;
192+
}
178193
#endif
179194

180195
static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)

arch/x86/kernel/traps.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,8 +694,7 @@ asmlinkage __visible noinstr struct pt_regs *vc_switch_off_ist(struct pt_regs *r
694694
* In the SYSCALL entry path the RSP value comes from user-space - don't
695695
* trust it and switch to the current kernel stack
696696
*/
697-
if (regs->ip >= (unsigned long)entry_SYSCALL_64 &&
698-
regs->ip < (unsigned long)entry_SYSCALL_64_safe_stack) {
697+
if (ip_within_syscall_gap(regs)) {
699698
sp = this_cpu_read(cpu_current_top_of_stack);
700699
goto sync;
701700
}

0 commit comments

Comments
 (0)