All of lore.kernel.org
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@alien8.de>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Qian Cai <cai@lca.pw>,
	dave.hansen@intel.com, tglx@linutronix.de, x86@kernel.org,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	luto@amacapital.net, hpa@zytor.com, mingo@kernel.org
Subject: Re: [PATCH v2] x86/fpu: Fault-in user stack if copy_fpstate_to_sigframe() fails
Date: Fri, 3 May 2019 08:04:34 +0200	[thread overview]
Message-ID: <20190503060434.GA5020@zn.tnic> (raw)
In-Reply-To: <20190502171139.mqtegctsg35cir2e@linutronix.de>

On Thu, May 02, 2019 at 07:11:39PM +0200, Sebastian Andrzej Siewior wrote:
> In the compacted form, XSAVES may save only the XMM+SSE state but skip
> FP (x87 state).
> 
> This is denoted by header->xfeatures = 6. The fastpath
> (copy_fpregs_to_sigframe()) does that but _also_ initialises the FP
> state (cwd to 0x37f, mxcsr as we do, remaining fields to 0).
> 
> The slowpath (copy_xstate_to_user()) leaves most of the FP
> state untouched. Only mxcsr and mxcsr_flags are set due to
> xfeatures_mxcsr_quirk(). Now that XFEATURE_MASK_FP is set
> unconditionally, see
> 
>   04944b793e18 ("x86: xsave: set FP, SSE bits in the xsave header in the user sigcontext"),
> 
> on return from the signal, random garbage is loaded as the FP state.
> 
> Instead of utilizing copy_xstate_to_user(), fault-in the user memory
> and retry the fast path. Ideally, the fast path succeeds on the second
> attempt but may be retried again if the memory is swapped out due
> to memory pressure. If the user memory can not be faulted-in then
> get_user_pages() returns an error so we don't loop forever.
> 
> Fault in memory via get_user_pages_unlocked() so
> copy_fpregs_to_sigframe() succeeds without a fault.
> 
> Fixes: 69277c98f5eef ("x86/fpu: Always store the registers in copy_fpstate_to_sigframe()")
> Reported-by: Kurt Kanzenbach <kurt.kanzenbach@linutronix.de>
> Suggested-by: Dave Hansen <dave.hansen@intel.com>
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
> v1…v2:
>    - s/get_user_pages()/get_user_pages_unlocked()/
>    - merge cleanups
> 
> I'm posting this all-in-one fix up replacing the original patch so we
> don't have a merge window with known bugs (that is the one that the
> patch was going the fix and the KASAN fallout that it introduced).
> 
>  arch/x86/kernel/fpu/signal.c | 31 +++++++++++++++----------------
>  1 file changed, 15 insertions(+), 16 deletions(-)

Queued to tip:WIP.x86/fpu for some hammering ontop ...

-- 
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.

  reply	other threads:[~2019-05-03  6:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-30 20:58 copy_fpstate_to_sigframe() use-after-free Qian Cai
2019-04-30 20:58 ` Qian Cai
2019-05-01  8:23 ` Borislav Petkov
2019-05-02 17:11   ` [PATCH v2] x86/fpu: Fault-in user stack if copy_fpstate_to_sigframe() fails Sebastian Andrzej Siewior
2019-05-03  6:04     ` Borislav Petkov [this message]
2019-05-01  9:00 ` [RFC PATCH] x86/fpu: Use get_user_pages_unlocked() to fault-in pages Sebastian Andrzej Siewior

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=20190503060434.GA5020@zn.tnic \
    --to=bp@alien8.de \
    --cc=bigeasy@linutronix.de \
    --cc=cai@lca.pw \
    --cc=dave.hansen@intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=luto@amacapital.net \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    --subject='Re: [PATCH v2] x86/fpu: Fault-in user stack if copy_fpstate_to_sigframe() fails' \
    /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

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.