Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp11134628imu; Thu, 6 Dec 2018 12:08:29 -0800 (PST) X-Google-Smtp-Source: AFSGD/UlkJwXTuH2FdeYT6cvHyt8QN+GVXyN0TXk56uWcmpeqH4pS5La/KA7Ynkf6LIhiOgp0IO3 X-Received: by 2002:a63:e156:: with SMTP id h22mr24259960pgk.255.1544126909130; Thu, 06 Dec 2018 12:08:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544126909; cv=none; d=google.com; s=arc-20160816; b=ROnBOFIY3DqrgWmWy5y2ED5rPVDYwdsCi4LReRPcWlk0LxsAO8bvzWexRF0C8/iiYg HewHPOvHz1OB3V66x8AqVRfEdqrBRaOpuk9PSNV/nwHX8nZiTAox8ihG7U+8D/lBbCTb 890cxVL0BbU8LkT93svXSRojYknwphz3fGdgXvAjS0Es4MKUqk7YzWl/8tAQumUadi1h 5u2ItFvaxv9hXisTFdji04TSgud0RSKEJ55zWdLaBCxzSuFPRuyLCU2UK0lf8h2+b8Jo KgE5m1fZz+A18A0G5fmH/zwNTpBtBCexHXvSiG8g8wavjjpzXalDtJqywWIor1TfRmyj OcLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=vKDO1AONLDvHL6i7cURw2F4Xjrieo7pmPPnlSoIwetA=; b=BKyV8sr/7sJS5J/LmK4nRZdWQQo9GAgqoTzOPjDeg7Em4LBrz7AT+zdRKtr4r12p1d TY3ZAUVq2p1C3sRuRFpiqQeH6d2SkWapz08utAbjiOOGzmqZeOPNKn4W8IbG283TQXv9 kbhk5EBkIdQv+yRfeJP4Il5Akdu2OhLmG+H0CceNe2PG+9xXL8K2J1Um1doP3jTa0cuB 31H/LQcKlaEq07v8ukkMg4BU8jibFYknCUdJTP4Mn4UvjDD1VKtBYjYsXjz74Zf9r2sI fZHCYt2OWaTy3/rXcrdiEnMGhzUBYUwaWJ4tZzaZnj1vEQc2oVeGODMj8mLLdoAHLRRe q5dQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=l3E1w3G7; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1si1058962plb.103.2018.12.06.12.08.11; Thu, 06 Dec 2018 12:08:29 -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=@alien8.de header.s=dkim header.b=l3E1w3G7; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725965AbeLFUHb (ORCPT + 99 others); Thu, 6 Dec 2018 15:07:31 -0500 Received: from mail.skyhub.de ([5.9.137.197]:58704 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725927AbeLFUHb (ORCPT ); Thu, 6 Dec 2018 15:07:31 -0500 Received: from zn.tnic (p200300EC2BCE8F005573F8735857468A.dip0.t-ipconnect.de [IPv6:2003:ec:2bce:8f00:5573:f873:5857:468a]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 725181EC0BAD; Thu, 6 Dec 2018 21:07:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1544126849; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=vKDO1AONLDvHL6i7cURw2F4Xjrieo7pmPPnlSoIwetA=; b=l3E1w3G7ejtXkjvHnSED+VhnE4LweEbHoPrShyGasASEBSYfA0F5LVMp63Nyzx8R5TgH7E RXQyaHlBZtxDWgOvaBfhNXwcsgv5clO+DoA3jrAYq5LIFYDQdgosucjteIi8FHQfMtcieX OZ+ZUfOFGNqobPKTh6MmXxby7NCkbC0= Date: Thu, 6 Dec 2018 21:07:22 +0100 From: Borislav Petkov To: Sebastian Andrzej Siewior Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Andy Lutomirski , Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , kvm@vger.kernel.org, "Jason A. Donenfeld" , Rik van Riel , Dave Hansen Subject: Re: [PATCH 08/29] x86/fpu: Remove fpu->initialized usage in __fpu__restore_sig() Message-ID: <20181206200722.GF3986@zn.tnic> References: <20181128222035.2996-1-bigeasy@linutronix.de> <20181128222035.2996-9-bigeasy@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20181128222035.2996-9-bigeasy@linutronix.de> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 28, 2018 at 11:20:14PM +0100, Sebastian Andrzej Siewior wrote: > This is a preparation for the removal of the ->initialized member in the > fpu struct. > __fpu__restore_sig() is deactivating the FPU via fpu__drop() and then > setting manually ->initialized followed by fpu__restore(). The result is > that it is possible to manipulate fpu->state and the state of registers > won't be saved/restored on a context switch which would overwrite > fpu->state. > > Don't access the fpu->state while the content is read from user space > and examined / sanitized. Use a temporary kmalloc() buffer for the > preparation of the FPU registers and once the state is considered okay, > load it. Should something go wrong, return with an error and without > altering the original FPU registers. > > The removal of "fpu__initialize()" is a nop because fpu->initialized is > already set for the user task. > > Signed-off-by: Sebastian Andrzej Siewior > --- > arch/x86/include/asm/fpu/signal.h | 2 +- > arch/x86/kernel/fpu/regset.c | 5 ++-- > arch/x86/kernel/fpu/signal.c | 41 ++++++++++++------------------- > 3 files changed, 19 insertions(+), 29 deletions(-) ... > diff --git a/arch/x86/kernel/fpu/signal.c b/arch/x86/kernel/fpu/signal.c > index d99a8ee9e185e..9c35598697b94 100644 > --- a/arch/x86/kernel/fpu/signal.c > +++ b/arch/x86/kernel/fpu/signal.c > @@ -207,11 +207,11 @@ int copy_fpstate_to_sigframe(void __user *buf, void __user *buf_fx, int size) > } > > static inline void > -sanitize_restored_xstate(struct task_struct *tsk, > +sanitize_restored_xstate(union fpregs_state *state, > struct user_i387_ia32_struct *ia32_env, > u64 xfeatures, int fx_only) > { > - struct xregs_state *xsave = &tsk->thread.fpu.state.xsave; > + struct xregs_state *xsave = &state->xsave; > struct xstate_header *header = &xsave->header; > > if (use_xsave()) { > @@ -238,7 +238,7 @@ sanitize_restored_xstate(struct task_struct *tsk, > */ > xsave->i387.mxcsr &= mxcsr_feature_mask; > > - convert_to_fxsr(tsk, ia32_env); > + convert_to_fxsr(&state->fxsave, ia32_env); > } > } > > @@ -284,8 +284,6 @@ static int __fpu__restore_sig(void __user *buf, void __user *buf_fx, int size) > if (!access_ok(VERIFY_READ, buf, size)) > return -EACCES; > > - fpu__initialize(fpu); > - > if (!static_cpu_has(X86_FEATURE_FPU)) > return fpregs_soft_set(current, NULL, > 0, sizeof(struct user_i387_ia32_struct), > @@ -314,41 +312,34 @@ static int __fpu__restore_sig(void __user *buf, void __user *buf_fx, int size) > * thread's fpu state, reconstruct fxstate from the fsave > * header. Validate and sanitize the copied state. > */ > + union fpregs_state *state; > + void *tmp; > struct user_i387_ia32_struct env; > int err = 0; Sort those in reverse xmas order pls. Otherwise looks ok. -- Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.