All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Jan Kiszka" <jan.kiszka@siemens.com>,
	linux-kernel@vger.kernel.org,
	"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
	stable@vger.kernel.org, "Borislav Petkov" <bp@suse.de>,
	"Ingo Molnar" <mingo@kernel.org>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Andy Lutomirski" <luto@kernel.org>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	"Jason A. Donenfeld" <Jason@zx2c4.com>,
	"kvm ML" <kvm@vger.kernel.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>,
	"Rik van Riel" <riel@surriel.com>, x86-ml <x86@kernel.org>,
	cip-dev <cip-dev@lists.cip-project.org>
Subject: Re: [cip-dev] [PATCH 4.9 18/22] x86/fpu: Disable bottom halves while loading FPU registers
Date: Fri, 24 Jul 2020 14:12:02 -0400	[thread overview]
Message-ID: <20200724181202.GG406581@sasha-vm> (raw)
In-Reply-To: <20200724174437.GB555114@kroah.com>

[-- Attachment #1: Type: text/plain, Size: 4398 bytes --]

On Fri, Jul 24, 2020 at 07:44:37PM +0200, Greg Kroah-Hartman wrote:
>On Fri, Jul 24, 2020 at 07:07:06PM +0200, Jan Kiszka wrote:
>> On 28.12.18 12:52, Greg Kroah-Hartman wrote:
>> > 4.9-stable review patch.  If anyone has any objections, please let me know.
>> >
>> > ------------------
>> >
>> > From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
>> >
>> > commit 68239654acafe6aad5a3c1dc7237e60accfebc03 upstream.
>> >
>> > The sequence
>> >
>> >    fpu->initialized = 1;		/* step A */
>> >    preempt_disable();		/* step B */
>> >    fpu__restore(fpu);
>> >    preempt_enable();
>> >
>> > in __fpu__restore_sig() is racy in regard to a context switch.
>> >
>> > For 32bit frames, __fpu__restore_sig() prepares the FPU state within
>> > fpu->state. To ensure that a context switch (switch_fpu_prepare() in
>> > particular) does not modify fpu->state it uses fpu__drop() which sets
>> > fpu->initialized to 0.
>> >
>> > After fpu->initialized is cleared, the CPU's FPU state is not saved
>> > to fpu->state during a context switch. The new state is loaded via
>> > fpu__restore(). It gets loaded into fpu->state from userland and
>> > ensured it is sane. fpu->initialized is then set to 1 in order to avoid
>> > fpu__initialize() doing anything (overwrite the new state) which is part
>> > of fpu__restore().
>> >
>> > A context switch between step A and B above would save CPU's current FPU
>> > registers to fpu->state and overwrite the newly prepared state. This
>> > looks like a tiny race window but the Kernel Test Robot reported this
>> > back in 2016 while we had lazy FPU support. Borislav Petkov made the
>> > link between that report and another patch that has been posted. Since
>> > the removal of the lazy FPU support, this race goes unnoticed because
>> > the warning has been removed.
>> >
>> > Disable bottom halves around the restore sequence to avoid the race. BH
>> > need to be disabled because BH is allowed to run (even with preemption
>> > disabled) and might invoke kernel_fpu_begin() by doing IPsec.
>> >
>> >   [ bp: massage commit message a bit. ]
>> >
>> > Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
>> > Signed-off-by: Borislav Petkov <bp@suse.de>
>> > Acked-by: Ingo Molnar <mingo@kernel.org>
>> > Acked-by: Thomas Gleixner <tglx@linutronix.de>
>> > Cc: Andy Lutomirski <luto@kernel.org>
>> > Cc: Dave Hansen <dave.hansen@linux.intel.com>
>> > Cc: "H. Peter Anvin" <hpa@zytor.com>
>> > Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>
>> > Cc: kvm ML <kvm@vger.kernel.org>
>> > Cc: Paolo Bonzini <pbonzini@redhat.com>
>> > Cc: Radim Krčmář <rkrcmar@redhat.com>
>> > Cc: Rik van Riel <riel@surriel.com>
>> > Cc: stable@vger.kernel.org
>> > Cc: x86-ml <x86@kernel.org>
>> > Link: http://lkml.kernel.org/r/20181120102635.ddv3fvavxajjlfqk@linutronix.de
>> > Link: https://lkml.kernel.org/r/20160226074940.GA28911@pd.tnic
>> > Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
>> > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> > ---
>> >   arch/x86/kernel/fpu/signal.c |    4 ++--
>> >   1 file changed, 2 insertions(+), 2 deletions(-)
>> >
>> > --- a/arch/x86/kernel/fpu/signal.c
>> > +++ b/arch/x86/kernel/fpu/signal.c
>> > @@ -342,10 +342,10 @@ static int __fpu__restore_sig(void __use
>> >   			sanitize_restored_xstate(tsk, &env, xfeatures, fx_only);
>> >   		}
>> > +		local_bh_disable();
>> >   		fpu->fpstate_active = 1;
>> > -		preempt_disable();
>> >   		fpu__restore(fpu);
>> > -		preempt_enable();
>> > +		local_bh_enable();
>> >   		return err;
>> >   	} else {
>> >
>> >
>>
>> Any reason why the backport stopped back than at 4.9? I just debugged this
>> out of a 4.4 kernel, and it is needed there as well. I'm happy to propose a
>> backport, would just appreciate a hint if the BH protection is needed also
>> there (my case was without BH).
>
>You are asking about something we did back in 2018.  I can't remember
>what I did last week :)
>
>If you provide a backport that works, I'll be glad to take it.  The
>current patch does not apply cleanly there at all.

The conflict was due to a missing rename back in 4.4: e4a81bfcaae1
("x86/fpu: Rename fpu::fpstate_active to fpu::initialized").

I've fixed up the patch and queued it for 4.4, thanks for pointing it
out Jan!

-- 
Thanks,
Sasha

[-- Attachment #2: Type: text/plain, Size: 419 bytes --]

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#5012): https://lists.cip-project.org/g/cip-dev/message/5012
Mute This Topic: https://lists.cip-project.org/mt/75770466/4520388
Group Owner: cip-dev+owner@lists.cip-project.org
Unsubscribe: https://lists.cip-project.org/g/cip-dev/leave/8129055/727948398/xyzzy  [cip-dev@archiver.kernel.org]
-=-=-=-=-=-=-=-=-=-=-=-

WARNING: multiple messages have this Message-ID (diff)
From: Sasha Levin <sashal@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Jan Kiszka" <jan.kiszka@siemens.com>,
	linux-kernel@vger.kernel.org,
	"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
	stable@vger.kernel.org, "Borislav Petkov" <bp@suse.de>,
	"Ingo Molnar" <mingo@kernel.org>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Andy Lutomirski" <luto@kernel.org>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	"Jason A. Donenfeld" <Jason@zx2c4.com>,
	"kvm ML" <kvm@vger.kernel.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>,
	"Rik van Riel" <riel@surriel.com>, x86-ml <x86@kernel.org>,
	cip-dev <cip-dev@lists.cip-project.org>
Subject: Re: [PATCH 4.9 18/22] x86/fpu: Disable bottom halves while loading FPU registers
Date: Fri, 24 Jul 2020 14:12:02 -0400	[thread overview]
Message-ID: <20200724181202.GG406581@sasha-vm> (raw)
In-Reply-To: <20200724174437.GB555114@kroah.com>

On Fri, Jul 24, 2020 at 07:44:37PM +0200, Greg Kroah-Hartman wrote:
>On Fri, Jul 24, 2020 at 07:07:06PM +0200, Jan Kiszka wrote:
>> On 28.12.18 12:52, Greg Kroah-Hartman wrote:
>> > 4.9-stable review patch.  If anyone has any objections, please let me know.
>> >
>> > ------------------
>> >
>> > From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
>> >
>> > commit 68239654acafe6aad5a3c1dc7237e60accfebc03 upstream.
>> >
>> > The sequence
>> >
>> >    fpu->initialized = 1;		/* step A */
>> >    preempt_disable();		/* step B */
>> >    fpu__restore(fpu);
>> >    preempt_enable();
>> >
>> > in __fpu__restore_sig() is racy in regard to a context switch.
>> >
>> > For 32bit frames, __fpu__restore_sig() prepares the FPU state within
>> > fpu->state. To ensure that a context switch (switch_fpu_prepare() in
>> > particular) does not modify fpu->state it uses fpu__drop() which sets
>> > fpu->initialized to 0.
>> >
>> > After fpu->initialized is cleared, the CPU's FPU state is not saved
>> > to fpu->state during a context switch. The new state is loaded via
>> > fpu__restore(). It gets loaded into fpu->state from userland and
>> > ensured it is sane. fpu->initialized is then set to 1 in order to avoid
>> > fpu__initialize() doing anything (overwrite the new state) which is part
>> > of fpu__restore().
>> >
>> > A context switch between step A and B above would save CPU's current FPU
>> > registers to fpu->state and overwrite the newly prepared state. This
>> > looks like a tiny race window but the Kernel Test Robot reported this
>> > back in 2016 while we had lazy FPU support. Borislav Petkov made the
>> > link between that report and another patch that has been posted. Since
>> > the removal of the lazy FPU support, this race goes unnoticed because
>> > the warning has been removed.
>> >
>> > Disable bottom halves around the restore sequence to avoid the race. BH
>> > need to be disabled because BH is allowed to run (even with preemption
>> > disabled) and might invoke kernel_fpu_begin() by doing IPsec.
>> >
>> >   [ bp: massage commit message a bit. ]
>> >
>> > Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
>> > Signed-off-by: Borislav Petkov <bp@suse.de>
>> > Acked-by: Ingo Molnar <mingo@kernel.org>
>> > Acked-by: Thomas Gleixner <tglx@linutronix.de>
>> > Cc: Andy Lutomirski <luto@kernel.org>
>> > Cc: Dave Hansen <dave.hansen@linux.intel.com>
>> > Cc: "H. Peter Anvin" <hpa@zytor.com>
>> > Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>
>> > Cc: kvm ML <kvm@vger.kernel.org>
>> > Cc: Paolo Bonzini <pbonzini@redhat.com>
>> > Cc: Radim Krčmář <rkrcmar@redhat.com>
>> > Cc: Rik van Riel <riel@surriel.com>
>> > Cc: stable@vger.kernel.org
>> > Cc: x86-ml <x86@kernel.org>
>> > Link: http://lkml.kernel.org/r/20181120102635.ddv3fvavxajjlfqk@linutronix.de
>> > Link: https://lkml.kernel.org/r/20160226074940.GA28911@pd.tnic
>> > Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
>> > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> > ---
>> >   arch/x86/kernel/fpu/signal.c |    4 ++--
>> >   1 file changed, 2 insertions(+), 2 deletions(-)
>> >
>> > --- a/arch/x86/kernel/fpu/signal.c
>> > +++ b/arch/x86/kernel/fpu/signal.c
>> > @@ -342,10 +342,10 @@ static int __fpu__restore_sig(void __use
>> >   			sanitize_restored_xstate(tsk, &env, xfeatures, fx_only);
>> >   		}
>> > +		local_bh_disable();
>> >   		fpu->fpstate_active = 1;
>> > -		preempt_disable();
>> >   		fpu__restore(fpu);
>> > -		preempt_enable();
>> > +		local_bh_enable();
>> >   		return err;
>> >   	} else {
>> >
>> >
>>
>> Any reason why the backport stopped back than at 4.9? I just debugged this
>> out of a 4.4 kernel, and it is needed there as well. I'm happy to propose a
>> backport, would just appreciate a hint if the BH protection is needed also
>> there (my case was without BH).
>
>You are asking about something we did back in 2018.  I can't remember
>what I did last week :)
>
>If you provide a backport that works, I'll be glad to take it.  The
>current patch does not apply cleanly there at all.

The conflict was due to a missing rename back in 4.4: e4a81bfcaae1
("x86/fpu: Rename fpu::fpstate_active to fpu::initialized").

I've fixed up the patch and queued it for 4.4, thanks for pointing it
out Jan!

-- 
Thanks,
Sasha

  reply	other threads:[~2020-07-24 18:12 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-28 11:52 [PATCH 4.9 00/22] 4.9.148-stable review Greg Kroah-Hartman
2018-12-28 11:52 ` [PATCH 4.9 01/22] block: break discard submissions into the user defined size Greg Kroah-Hartman
2018-12-28 11:52 ` [PATCH 4.9 02/22] block: fix infinite loop if the device loses discard capability Greg Kroah-Hartman
2018-12-28 11:52 ` [PATCH 4.9 03/22] ib_srpt: Fix a use-after-free in __srpt_close_all_ch() Greg Kroah-Hartman
2018-12-28 11:52 ` [PATCH 4.9 04/22] USB: hso: Fix OOB memory access in hso_probe/hso_get_config_data Greg Kroah-Hartman
2018-12-28 11:52 ` [PATCH 4.9 05/22] xhci: Dont prevent USB2 bus suspend in state check intended for USB3 only Greg Kroah-Hartman
2018-12-28 11:52 ` [PATCH 4.9 06/22] USB: serial: option: add GosunCn ZTE WeLink ME3630 Greg Kroah-Hartman
2018-12-28 11:52 ` [PATCH 4.9 07/22] USB: serial: option: add HP lt4132 Greg Kroah-Hartman
2018-12-28 11:52 ` [PATCH 4.9 08/22] USB: serial: option: add Simcom SIM7500/SIM7600 (MBIM mode) Greg Kroah-Hartman
2018-12-28 11:52 ` [PATCH 4.9 09/22] USB: serial: option: add Fibocom NL668 series Greg Kroah-Hartman
2018-12-28 11:52 ` [PATCH 4.9 10/22] USB: serial: option: add Telit LN940 series Greg Kroah-Hartman
2018-12-28 11:52 ` [PATCH 4.9 11/22] mmc: core: Reset HPI enabled state during re-init and in case of errors Greg Kroah-Hartman
2018-12-28 11:52 ` [PATCH 4.9 12/22] mmc: core: Allow BKOPS and CACHE ctrl even if no HPI support Greg Kroah-Hartman
2018-12-28 11:52 ` [PATCH 4.9 13/22] mmc: core: Use a minimum 1600ms timeout when enabling CACHE ctrl Greg Kroah-Hartman
2018-12-28 11:52 ` [PATCH 4.9 14/22] mmc: omap_hsmmc: fix DMA API warning Greg Kroah-Hartman
2018-12-28 11:52 ` [PATCH 4.9 15/22] gpio: max7301: fix driver for use with CONFIG_VMAP_STACK Greg Kroah-Hartman
2018-12-28 11:52 ` [PATCH 4.9 16/22] Drivers: hv: vmbus: Return -EINVAL for the sys files for unopened channels Greg Kroah-Hartman
2018-12-28 11:52 ` [PATCH 4.9 17/22] x86/mtrr: Dont copy uninitialized gentry fields back to userspace Greg Kroah-Hartman
2018-12-28 11:52 ` [PATCH 4.9 18/22] x86/fpu: Disable bottom halves while loading FPU registers Greg Kroah-Hartman
2020-07-24 17:07   ` [cip-dev] " Jan Kiszka
2020-07-24 17:07     ` Jan Kiszka
2020-07-24 17:44     ` [cip-dev] " Greg Kroah-Hartman
2020-07-24 17:44       ` Greg Kroah-Hartman
2020-07-24 18:12       ` Sasha Levin [this message]
2020-07-24 18:12         ` Sasha Levin
2018-12-28 11:52 ` [PATCH 4.9 19/22] ubifs: Handle re-linking of inodes correctly while recovery Greg Kroah-Hartman
2018-12-28 11:52 ` [PATCH 4.9 20/22] panic: avoid deadlocks in re-entrant console drivers Greg Kroah-Hartman
2018-12-28 11:52 ` [PATCH 4.9 21/22] proc/sysctl: dont return ENOMEM on lookup when a table is unregistering Greg Kroah-Hartman
2018-12-28 11:52 ` [PATCH 4.9 22/22] drm/ioctl: Fix Spectre v1 vulnerabilities Greg Kroah-Hartman
2018-12-28 18:12 ` [PATCH 4.9 00/22] 4.9.148-stable review Dan Rue
2018-12-28 20:10 ` shuah
2018-12-28 21:27 ` Guenter Roeck

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=20200724181202.GG406581@sasha-vm \
    --to=sashal@kernel.org \
    --cc=Jason@zx2c4.com \
    --cc=bigeasy@linutronix.de \
    --cc=bp@suse.de \
    --cc=cip-dev@lists.cip-project.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hpa@zytor.com \
    --cc=jan.kiszka@siemens.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=riel@surriel.com \
    --cc=rkrcmar@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --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.