Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8100492imu; Tue, 4 Dec 2018 03:01:33 -0800 (PST) X-Google-Smtp-Source: AFSGD/Wb7Bw4ANwpKnEdQcpdlo+AVUucHrHOYBbeCWWNhAOa6MQ+LhvuikGb1xJav9tbzwf2Lh5e X-Received: by 2002:a65:40c5:: with SMTP id u5mr15771179pgp.46.1543921293156; Tue, 04 Dec 2018 03:01:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543921293; cv=none; d=google.com; s=arc-20160816; b=JwPtJCEUr1rmICyTb9IRXX4r5fkfz+af2eJ3oravYBOMQewdJhyQrCvYssAm92EDh4 WZtQuzN3iQfQ14HPPaZzGnULxXWv+97RhFSytNeiBdoNwly1LmDnMMUzlIRHKP9FC0iQ e1XI51LC9OdGw1mFq6ER9/62RkJGmGHEZT1KS4RZZBCU9S4EA0phb0hr6RGuyfestM5E xn/FfsVK0YIgenRmN/yV6NR0VU6SG4u3JpCodq4pS3WYp+RDSv9Vi4Gtu35OXbkcAMS2 yIyQPIjuDy95K6lit4IKRKJofXelSVT0iaGg8ZLT9hxPFIV80Msn+gCiQ7FgrglrUw57 m6+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=M4Dfkj+hvrb8rKUYFcjCHLv8Klx9l7sBy2MHzWry4eU=; b=W5p+1vEeJdzA8Xb2Gu47/VnIpAVDaM974GJszHYprTx72ADOUAPBdD0TnzqSCQR5gV m6NvvNfsYkRegFv1cXd4SE2A7j5txOlRO0yhkgMZoseHL5Esfs+V3hNWQeuIH2IPPcfO +3ti15F/cwpiNKyUa7KncAltnyId8H2W6MdKXzn3jWtYM3yVNJerBmyb0W855kX1Z2SV xeqSYmIqbKC5n7hjarBQ9pJ8GcyRyj0nnaZcgrFRYjsJsUgr/Nfbn0yExNKumSLOMth8 Xkz37ZInqsEQvXLfqEgSeGVaXm/xCdc8p/rlLfnB/hYYZlQhDMnL6gArXqbt7ERTIgue kLuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GGt55cSL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u11si16962501plr.392.2018.12.04.03.01.17; Tue, 04 Dec 2018 03:01:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GGt55cSL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726968AbeLDK6c (ORCPT + 99 others); Tue, 4 Dec 2018 05:58:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:42894 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726950AbeLDK62 (ORCPT ); Tue, 4 Dec 2018 05:58:28 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BE24B20878; Tue, 4 Dec 2018 10:58:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543921107; bh=ML1OiVbxe3eF22SmNq52Bs3ccvYXbG35giY9YDa4Gs4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GGt55cSLuUNxD7KPpr8/I/ZWRHnQQZXWHKojeigGOMIzxqpmIgJO0+pdbWPPV7g1o lQSpftKsgfwT1cM3JB/EAp7PhrFH8sOWT4wwC6cJxNG6SW8DkAiyJiQvboq+UvgsAu HNtmbjwqDzayxjfMcIzVAcWAzw8I1T2eyRF3xqK4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sebastian Andrzej Siewior , Borislav Petkov , Ingo Molnar , Thomas Gleixner , Andy Lutomirski , Dave Hansen , "H. Peter Anvin" , "Jason A. Donenfeld" , kvm ML , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Rik van Riel , x86-ml Subject: [PATCH 4.19 084/139] x86/fpu: Disable bottom halves while loading FPU registers Date: Tue, 4 Dec 2018 11:49:25 +0100 Message-Id: <20181204103653.723381425@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181204103649.950154335@linuxfoundation.org> References: <20181204103649.950154335@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sebastian Andrzej Siewior 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 Signed-off-by: Borislav Petkov Acked-by: Ingo Molnar Acked-by: Thomas Gleixner Cc: Andy Lutomirski Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: "Jason A. Donenfeld" Cc: kvm ML Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Rik van Riel Cc: stable@vger.kernel.org Cc: x86-ml Link: http://lkml.kernel.org/r/20181120102635.ddv3fvavxajjlfqk@linutronix.de Link: https://lkml.kernel.org/r/20160226074940.GA28911@pd.tnic Signed-off-by: Greg Kroah-Hartman --- 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 @@ -344,10 +344,10 @@ static int __fpu__restore_sig(void __use sanitize_restored_xstate(tsk, &env, xfeatures, fx_only); } + local_bh_disable(); fpu->initialized = 1; - preempt_disable(); fpu__restore(fpu); - preempt_enable(); + local_bh_enable(); return err; } else {