Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8273698imu; Fri, 28 Dec 2018 14:16:17 -0800 (PST) X-Google-Smtp-Source: AFSGD/XVGBf+kfzU/2FgXhyYGS/4YSckUYDEC56oKVH4nerW5KcQEJZS+w0VNrtXLOO/WbDCwrEj X-Received: by 2002:a62:6143:: with SMTP id v64mr29680941pfb.142.1546035377398; Fri, 28 Dec 2018 14:16:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546035377; cv=none; d=google.com; s=arc-20160816; b=kcnGWjWiOuODAFnmf2eiv74IFKLSDyxaeHAtQzhhB1sDFD+ACxUE4wwtRFeulx6ltL VkioZrPTbxgHiSHdjlCici2kSxx4rgrnE/8KdfKnB0yhmAdAhrj+NJRryjQQSAd0tkkk /zH0JtCZRGvtIF1sLf4ZaRNrLwQGrKTHEnoBPI/R/zzqUGotC50HUZsMwFMFoQ1z/rwm l0D5ZuD8ukkMgVoAQ1/TZd7RsiLcDcUoMzRRCrByQMRtDce1t4GDM7DRrFD8f5ilBhve n5Z+LnWqh/El8xSH/2Wi8bzq8WML7+AFvz2jNjAWpW3a/xiYrrcKLbXtV4Ym3pmCtEUQ X+Nw== 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=hp8Gd1XgcQVaIcO03pTJzGok7Mr8FgZ3CoTNRwZPFMg=; b=P0P7BCv1jGYP47I6Tv0vR3aeBbUDmRD+8GeLVgDzDfBmytt/jL2+rKDynOfzb+0NRU Xm1dO+erIibD8Pm5lHNyQrufri2OgJxy6fi4bYVpvQ+5Hq+cqB0RYtgtcoaG3VEg8gH8 5tHlcYnQKaq04P/K8v1sCnlIEshlieZgCAogGY/76ePp+VNqshiMAq1hepCn/nfvYGWp B1ewRIux0HgwWZcIue67gbW80Shso9lFd++hx0z/A6XtO6XR4fCd4VjkuElFgFtziEnF LYzLOK8Ym0LyL8KWkIwIoqxFTyj9Ec3HsL3epte6Y3QdFuNLWx9YYuG0kzwKtyEmzRTR 8MCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WKJEvYuA; 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 f124si41276242pfa.1.2018.12.28.14.16.02; Fri, 28 Dec 2018 14:16:17 -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=WKJEvYuA; 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 S1732997AbeL1MRk (ORCPT + 99 others); Fri, 28 Dec 2018 07:17:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:36676 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732983AbeL1MRh (ORCPT ); Fri, 28 Dec 2018 07:17:37 -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 0004D2148E; Fri, 28 Dec 2018 12:17:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1545999456; bh=vmvI8wkFgeMGJUu876+mwygyD/oZ/ZZeRSH6KKM24lI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WKJEvYuAOdZA0hV8oSuJMib+veDjUU334GIFpDKG/Qb4JCZifzC35dYjOv+dRA1pm MWu59LCMwjFv1rHteIjEEPNpDe85dGbjaBsTnRg8Q++iWhNPioT3AELZwBpKKiN6LT e5deC1cVZH8Zi7ygDrA+wQLpqE0gqj5P3h/3sC4I= 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.9 18/22] x86/fpu: Disable bottom halves while loading FPU registers Date: Fri, 28 Dec 2018 12:52:55 +0100 Message-Id: <20181228113127.414176417@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20181228113126.144310132@linuxfoundation.org> References: <20181228113126.144310132@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.9-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: Sebastian Andrzej Siewior 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 @@ -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 {