From: Greg KH <gregkh@linuxfoundation.org>
To: Michael Neuling <mikey@neuling.org>
Cc: gromero@linux.ibm.com, mpe@ellerman.id.au, stable@vger.kernel.org
Subject: Re: [PATCH 4.19] powerpc/tm: Fix restoring FP/VMX facility incorrectly on interrupts
Date: Wed, 11 Sep 2019 10:09:03 +0100 [thread overview]
Message-ID: <20190911090903.GA30714@kroah.com> (raw)
In-Reply-To: <07d47bd664b13cf5cdc0361a59b26f9e448e2079.camel@neuling.org>
On Wed, Sep 11, 2019 at 10:13:27AM +1000, Michael Neuling wrote:
> When in userspace and MSR FP=0 the hardware FP state is unrelated to
> the current process. This is extended for transactions where if tbegin
> is run with FP=0, the hardware checkpoint FP state will also be
> unrelated to the current process. Due to this, we need to ensure this
> hardware checkpoint is updated with the correct state before we enable
> FP for this process.
>
> Unfortunately we get this wrong when returning to a process from a
> hardware interrupt. A process that starts a transaction with FP=0 can
> take an interrupt. When the kernel returns back to that process, we
> change to FP=1 but with hardware checkpoint FP state not updated. If
> this transaction is then rolled back, the FP registers now contain the
> wrong state.
>
> The process looks like this:
> Userspace: Kernel
>
> Start userspace
> with MSR FP=0 TM=1
> < -----
> ...
> tbegin
> bne
> Hardware interrupt
> ---- >
> <do_IRQ...>
> ....
> ret_from_except
> restore_math()
> /* sees FP=0 */
> restore_fp()
> tm_active_with_fp()
> /* sees FP=1 (Incorrect) */
> load_fp_state()
> FP = 0 -> 1
> < -----
> Return to userspace
> with MSR TM=1 FP=1
> with junk in the FP TM checkpoint
> TM rollback
> reads FP junk
>
> When returning from the hardware exception, tm_active_with_fp() is
> incorrectly making restore_fp() call load_fp_state() which is setting
> FP=1.
>
> The fix is to remove tm_active_with_fp().
>
> tm_active_with_fp() is attempting to handle the case where FP state
> has been changed inside a transaction. In this case the checkpointed
> and transactional FP state is different and hence we must restore the
> FP state (ie. we can't do lazy FP restore inside a transaction that's
> used FP). It's safe to remove tm_active_with_fp() as this case is
> handled by restore_tm_state(). restore_tm_state() detects if FP has
> been using inside a transaction and will set load_fp and call
> restore_math() to ensure the FP state (checkpoint and transaction) is
> restored.
>
> This is a data integrity problem for the current process as the FP
> registers are corrupted. It's also a security problem as the FP
> registers from one process may be leaked to another.
>
> Similarly for VMX.
>
> A simple testcase to replicate this will be posted to
> tools/testing/selftests/powerpc/tm/tm-poison.c
>
> This fixes CVE-2019-15031.
>
> Fixes: a7771176b439 ("powerpc: Don't enable FP/Altivec if not checkpointed")
> Cc: stable@vger.kernel.org # 4.15+
> Signed-off-by: Gustavo Romero <gromero@linux.ibm.com>
> Signed-off-by: Michael Neuling <mikey@neuling.org>
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
> Link: https://lore.kernel.org/r/20190904045529.23002-2-gromero@linux.vnet.ibm.com
> ---
> Greg, This is a backport for v4.19 only since the original patch didn't
> apply.
>
> Commit a8318c13e79badb92bc6640704a64cc022a6eb97 upstream.
Now queued up, thanks.
greg k-h
next prev parent reply other threads:[~2019-09-11 9:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-10 11:27 FAILED: patch "[PATCH] powerpc/tm: Fix restoring FP/VMX facility incorrectly on" failed to apply to 4.19-stable tree gregkh
2019-09-11 0:13 ` [PATCH 4.19] powerpc/tm: Fix restoring FP/VMX facility incorrectly on interrupts Michael Neuling
2019-09-11 9:09 ` Greg KH [this message]
2019-09-11 9:23 ` Sasha Levin
2019-09-11 9:34 ` Michael Neuling
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=20190911090903.GA30714@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=gromero@linux.ibm.com \
--cc=mikey@neuling.org \
--cc=mpe@ellerman.id.au \
--cc=stable@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).