lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 20 Nov 2018 09:15:54 +0100
From:   Peter Zijlstra <peterz@...radead.org>
To:     Andy Lutomirski <luto@...nel.org>
Cc:     x86@...nel.org, LKML <linux-kernel@...r.kernel.org>,
        Yu-cheng Yu <yu-cheng.yu@...el.com>,
        Dave Hansen <dave.hansen@...ux.intel.com>,
        Borislav Petkov <bp@...en8.de>
Subject: Re: [PATCH 01/13] x86/fault: Check user_mode(regs) when avoiding an
 mmap_sem deadlock

On Mon, Nov 19, 2018 at 02:45:25PM -0800, Andy Lutomirski wrote:
> The fault-handling code that takes mmap_sem needs to avoid a
> deadlock that could occur if the kernel took a bad (OOPS-worthy)
> page fault on a user address while holding mmap_sem.  This can only
> happen if the faulting instruction was in the kernel
> (i.e. user_mode(regs)).  Rather than checking the sw_error_code

 !user_mode(regs), surely, as the patch actually does.

> (which will have the USER bit set if the fault was a USER-permission
> access *or* if user_mode(regs)), just check user_mode(regs)
> directly.
> 
> The old code would have malfunctioned if the kernel executed a bogus
> WRUSS instruction while holding mmap_sem.  Fortunately, that is
> extremely unlikely in current kernels, which don't use WRUSS.
> 
> Signed-off-by: Andy Lutomirski <luto@...nel.org>
> ---
>  arch/x86/mm/fault.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
> index 71d4b9d4d43f..91d4d2722f2e 100644
> --- a/arch/x86/mm/fault.c
> +++ b/arch/x86/mm/fault.c
> @@ -1344,13 +1344,10 @@ void do_user_addr_fault(struct pt_regs *regs,
>  	 * Only do the expensive exception table search when we might be at
>  	 * risk of a deadlock.  This happens if we
>  	 * 1. Failed to acquire mmap_sem, and
> -	 * 2. The access did not originate in userspace.  Note: either the
> -	 *    hardware or earlier page fault code may set X86_PF_USER
> -	 *    in sw_error_code.
> +	 * 2. The access did not originate in userspace.
>  	 */
>  	if (unlikely(!down_read_trylock(&mm->mmap_sem))) {
> -		if (!(sw_error_code & X86_PF_USER) &&
> -		    !search_exception_tables(regs->ip)) {
> +		if (!user_mode(regs) && !search_exception_tables(regs->ip)) {
>  			/*
>  			 * Fault from code in kernel from
>  			 * which we do not expect faults.
> -- 
> 2.17.2
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ