All of lore.kernel.org
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@alien8.de>
To: Lai Jiangshan <jiangshanlai@gmail.com>
Cc: linux-kernel@vger.kernel.org, x86@kernel.org,
	Lai Jiangshan <laijs@linux.alibaba.com>,
	Andy Lutomirski <luto@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"H. Peter Anvin" <hpa@zytor.com>, Oleg Nesterov <oleg@redhat.com>,
	"Chang S. Bae" <chang.seok.bae@intel.com>,
	Jan Kiszka <jan.kiszka@siemens.com>,
	Joerg Roedel <jroedel@suse.de>,
	Tom Lendacky <thomas.lendacky@amd.com>
Subject: Re: [PATCH 3/3] x86/sev: The code for returning to user space is also in syscall gap
Date: Tue, 14 Dec 2021 22:51:27 +0100	[thread overview]
Message-ID: <YbkR36Vpb1h5SlMZ@zn.tnic> (raw)
In-Reply-To: <20211213042215.3096-4-jiangshanlai@gmail.com>

+ Tom and leaving the whole mail un-trimmed for him.

On Mon, Dec 13, 2021 at 12:22:15PM +0800, Lai Jiangshan wrote:
> From: Lai Jiangshan <laijs@linux.alibaba.com>
> 
> When returning to user space, the %rsp is user controlled value.

And?

I'd expect to see here some text analyzing the couple of instructions
between those new labels you've added and whether a #VC can happen
there.

> Signed-off-by: Lai Jiangshan <laijs@linux.alibaba.com>
> ---
>  arch/x86/entry/entry_64.S        | 2 ++
>  arch/x86/entry/entry_64_compat.S | 2 ++
>  arch/x86/include/asm/proto.h     | 4 ++++
>  arch/x86/include/asm/ptrace.h    | 4 ++++
>  4 files changed, 12 insertions(+)
> 
> diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
> index e23319ad3f42..44dadea935f7 100644
> --- a/arch/x86/entry/entry_64.S
> +++ b/arch/x86/entry/entry_64.S
> @@ -213,8 +213,10 @@ syscall_return_via_sysret:
>  
>  	popq	%rdi
>  	popq	%rsp
> +SYM_INNER_LABEL(entry_SYSRETQ_unsafe_stack, SYM_L_GLOBAL)
>  	swapgs
>  	sysretq
> +SYM_INNER_LABEL(entry_SYSRETQ_end, SYM_L_GLOBAL)
>  SYM_CODE_END(entry_SYSCALL_64)
>  
>  /*
> diff --git a/arch/x86/entry/entry_64_compat.S b/arch/x86/entry/entry_64_compat.S
> index 0051cf5c792d..98afdf92f360 100644
> --- a/arch/x86/entry/entry_64_compat.S
> +++ b/arch/x86/entry/entry_64_compat.S
> @@ -293,6 +293,7 @@ sysret32_from_system_call:
>  	 * code.  We zero R8-R10 to avoid info leaks.
>           */
>  	movq	RSP-ORIG_RAX(%rsp), %rsp
> +SYM_INNER_LABEL(entry_SYSRETL_compat_unsafe_stack, SYM_L_GLOBAL)
>  
>  	/*
>  	 * The original userspace %rsp (RSP-ORIG_RAX(%rsp)) is stored
> @@ -310,6 +311,7 @@ sysret32_from_system_call:
>  	xorl	%r10d, %r10d
>  	swapgs
>  	sysretl
> +SYM_INNER_LABEL(entry_SYSRETL_compat_end, SYM_L_GLOBAL)
>  SYM_CODE_END(entry_SYSCALL_compat)
>  
>  /*
> diff --git a/arch/x86/include/asm/proto.h b/arch/x86/include/asm/proto.h
> index feed36d44d04..f042cfc9938f 100644
> --- a/arch/x86/include/asm/proto.h
> +++ b/arch/x86/include/asm/proto.h
> @@ -13,6 +13,8 @@ void syscall_init(void);
>  #ifdef CONFIG_X86_64
>  void entry_SYSCALL_64(void);
>  void entry_SYSCALL_64_safe_stack(void);
> +void entry_SYSRETQ_unsafe_stack(void);
> +void entry_SYSRETQ_end(void);
>  long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2);
>  #endif
>  
> @@ -28,6 +30,8 @@ void entry_SYSENTER_compat(void);
>  void __end_entry_SYSENTER_compat(void);
>  void entry_SYSCALL_compat(void);
>  void entry_SYSCALL_compat_safe_stack(void);
> +void entry_SYSRETL_compat_unsafe_stack(void);
> +void entry_SYSRETL_compat_end(void);
>  void entry_INT80_compat(void);
>  #ifdef CONFIG_XEN_PV
>  void xen_entry_INT80_compat(void);
> diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
> index 703663175a5a..b3d2ba13cee2 100644
> --- a/arch/x86/include/asm/ptrace.h
> +++ b/arch/x86/include/asm/ptrace.h
> @@ -186,9 +186,13 @@ static __always_inline bool ip_within_syscall_gap(struct pt_regs *regs)
>  	bool ret = (regs->ip >= (unsigned long)entry_SYSCALL_64 &&
>  		    regs->ip <  (unsigned long)entry_SYSCALL_64_safe_stack);
>  
> +	ret = ret || (regs->ip >= (unsigned long)entry_SYSRETQ_unsafe_stack &&
> +		      regs->ip <  (unsigned long)entry_SYSRETQ_end);
>  #ifdef CONFIG_IA32_EMULATION
>  	ret = ret || (regs->ip >= (unsigned long)entry_SYSCALL_compat &&
>  		      regs->ip <  (unsigned long)entry_SYSCALL_compat_safe_stack);
> +	ret = ret || (regs->ip >= (unsigned long)entry_SYSRETL_compat_unsafe_stack &&
> +		      regs->ip <  (unsigned long)entry_SYSRETL_compat_end);
>  #endif
>  
>  	return ret;
> -- 
> 2.19.1.6.gb485710b
> 

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

  reply	other threads:[~2021-12-14 21:51 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-13  4:22 [PATCH 0/3] x86/entry: Fix 3 suspicious bugs Lai Jiangshan
2021-12-13  4:22 ` [PATCH 1/3] X86/db: Change __this_cpu_read() to this_cpu_read() in hw_breakpoint_active() Lai Jiangshan
2021-12-13 19:09   ` Borislav Petkov
2021-12-14  2:51     ` Lai Jiangshan
2021-12-14  9:33       ` Borislav Petkov
2021-12-13 19:46   ` Peter Zijlstra
2021-12-13  4:22 ` [PATCH 2/3] x86/hw_breakpoint: Add stack_canary to hw_breakpoints denylist Lai Jiangshan
2021-12-13 19:57   ` Peter Zijlstra
2021-12-13  4:22 ` [PATCH 3/3] x86/sev: The code for returning to user space is also in syscall gap Lai Jiangshan
2021-12-14 21:51   ` Borislav Petkov [this message]
2021-12-17 10:05     ` Joerg Roedel
2021-12-17 10:30       ` Borislav Petkov
2021-12-17 11:00         ` Joerg Roedel
2022-01-18 10:32           ` Borislav Petkov
2022-01-18 15:37             ` Lai Jiangshan
2022-04-12 13:00     ` Lai Jiangshan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YbkR36Vpb1h5SlMZ@zn.tnic \
    --to=bp@alien8.de \
    --cc=chang.seok.bae@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jan.kiszka@siemens.com \
    --cc=jiangshanlai@gmail.com \
    --cc=jroedel@suse.de \
    --cc=laijs@linux.alibaba.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=oleg@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=thomas.lendacky@amd.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.