From patchwork Fri Jun 7 14:29:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 10981985 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 919D676 for ; Fri, 7 Jun 2019 14:29:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FFF426222 for ; Fri, 7 Jun 2019 14:29:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D675285C8; Fri, 7 Jun 2019 14:29:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D6F32675C for ; Fri, 7 Jun 2019 14:29:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729345AbfFGO3g convert rfc822-to-8bit (ORCPT ); Fri, 7 Jun 2019 10:29:36 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:50189 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729080AbfFGO3f (ORCPT ); Fri, 7 Jun 2019 10:29:35 -0400 Received: from bigeasy by Galois.linutronix.de with local (Exim 4.80) (envelope-from ) id 1hZFro-00051M-7T; Fri, 07 Jun 2019 16:29:16 +0200 Date: Fri, 7 Jun 2019 16:29:16 +0200 From: Sebastian Andrzej Siewior To: Eric Biggers , x86-ml Cc: Borislav Petkov , Dave Hansen , Thomas Gleixner , Andy Lutomirski , "H. Peter Anvin" , Ingo Molnar , Jann Horn , "Jason A. Donenfeld" , kvm ML , Paolo Bonzini , Radim =?utf-8?b?S3LEjW3DocWZ?= , Rik van Riel , linux-kernel@vger.kernel.org Subject: [PATCH] x86/fpu: Update kernel's FPU state before using for the fsave header Message-ID: <20190607142915.y52mfmgk5lvhll7n@linutronix.de> References: <20190604185358.GA820@sol.localdomain> <20190605140405.2nnpqslnjpfe2ig2@linutronix.de> <20190605173256.GA86462@gmail.com> <20190606173026.ty7c4cvftrvfrwy3@linutronix.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190606173026.ty7c4cvftrvfrwy3@linutronix.de> User-Agent: NeoMutt/20180716 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In commit 39388e80f9b0c ("x86/fpu: Don't save fxregs for ia32 frames in copy_fpstate_to_sigframe()") I removed the statement | if (ia32_fxstate) | copy_fxregs_to_kernel(fpu); and argued that is was wrongly merged because the content was already saved in kernel's state and the content. This was wrong: It is required to write it back because it is only saved on the user-stack and save_fsave_header() reads it from task's FPU-state. I missed that part… Save x87 FPU state unless thread's FPU registers are already up to date. Fixes: 39388e80f9b0c ("x86/fpu: Don't save fxregs for ia32 frames in copy_fpstate_to_sigframe()") Reported-by: Eric Biggers Signed-off-by: Sebastian Andrzej Siewior Tested-by: Eric Biggers --- arch/x86/kernel/fpu/signal.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/x86/kernel/fpu/signal.c b/arch/x86/kernel/fpu/signal.c index 060d6188b4533..0071b794ed193 100644 --- a/arch/x86/kernel/fpu/signal.c +++ b/arch/x86/kernel/fpu/signal.c @@ -62,6 +62,11 @@ static inline int save_fsave_header(struct task_struct *tsk, void __user *buf) struct user_i387_ia32_struct env; struct _fpstate_32 __user *fp = buf; + fpregs_lock(); + if (!test_thread_flag(TIF_NEED_FPU_LOAD)) + copy_fxregs_to_kernel(&tsk->thread.fpu); + fpregs_unlock(); + convert_from_fxsr(&env, tsk); if (__copy_to_user(buf, &env, sizeof(env)) ||