Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752786AbcD2UJL (ORCPT ); Fri, 29 Apr 2016 16:09:11 -0400 Received: from mga14.intel.com ([192.55.52.115]:29382 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752672AbcD2UJJ (ORCPT ); Fri, 29 Apr 2016 16:09:09 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,553,1455004800"; d="scan'208";a="965618956" Subject: Re: [PATCH v4 04/10] x86/xsaves: Introduce a new check that allows correct xstates copy from kernel to user directly To: Yu-cheng Yu , x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org References: Cc: Andy Lutomirski , Borislav Petkov , Sai Praneeth Prakhya , "Ravi V. Shankar" , Fenghua Yu From: Dave Hansen Message-ID: <5723BF63.2000100@linux.intel.com> Date: Fri, 29 Apr 2016 13:09:07 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1081 Lines: 27 On 03/04/2016 10:12 AM, Yu-cheng Yu wrote: > diff --git a/arch/x86/kernel/fpu/signal.c b/arch/x86/kernel/fpu/signal.c > index 0fbf60c..09945f1 100644 > --- a/arch/x86/kernel/fpu/signal.c > +++ b/arch/x86/kernel/fpu/signal.c > @@ -130,6 +130,45 @@ static inline int copy_fpregs_to_sigframe(struct xregs_state __user *buf) > return err; > } > > +static int may_copy_fpregs_to_sigframe(void) > +{ > + /* > + * In signal handling path, the kernel already checks if > + * FPU instructions have been used before it calls > + * copy_fpstate_to_sigframe(). We check this here again > + * to detect any potential mis-use and saving invalid > + * register values directly to a signal frame. > + */ > + WARN_ONCE(!current->thread.fpu.fpstate_active, > + "direct FPU save with no math use\n"); This is probably an OK check for this _particular_ context (since this context is all ready to copy_to_user() the fpu state). But is it good generally? Why couldn't you have a !fpstate_active thread that _was_ fpregs_active? Such a thread _could_ do a direct XSAVE with no issues.