From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933576AbdIYHaf (ORCPT ); Mon, 25 Sep 2017 03:30:35 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:33063 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932135AbdIYHad (ORCPT ); Mon, 25 Sep 2017 03:30:33 -0400 X-Google-Smtp-Source: AOwi7QDk2zz55+rwG9usJ2UQSA+0yJPb6WRdFILJthiIh0cXSmWkceqIqz7+dwoBwfns8ZEklx1oZg== Date: Mon, 25 Sep 2017 09:30:29 +0200 From: Ingo Molnar To: Eric Biggers Cc: linux-kernel@vger.kernel.org, Andrew Morton , Andy Lutomirski , Borislav Petkov , Dave Hansen , Fenghua Yu , "H . Peter Anvin" , Linus Torvalds , Oleg Nesterov , Peter Zijlstra , Rik van Riel , Thomas Gleixner , Yu-cheng Yu Subject: Re: [PATCH 03/10] x86/fpu: Use validate_xstate_header() to validate the xstate_header in sanitize_restored_xstate() Message-ID: <20170925073029.mi4w36uioan4njkt@gmail.com> References: <20170924105913.9157-1-mingo@kernel.org> <20170924105913.9157-4-mingo@kernel.org> <20170924185147.GA26260@zzz.localdomain> <20170924190242.hsbs7tqhvcalnczt@gmail.com> <20170924200853.GB26260@zzz.localdomain> <20170925061445.uzt5phqebwnvbhcb@gmail.com> <20170925072010.GA25510@zzz.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170925072010.GA25510@zzz.localdomain> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Eric Biggers wrote: > On Mon, Sep 25, 2017 at 08:14:45AM +0200, Ingo Molnar wrote: > > > > > > > > Could you please just send the delta patch against the whole tree to fix the bug? > > > > I'll worry about the patch dependencies and back-merge it to the proper place. > > > > > > > > > > The following diff against tip/master fixes the bug. Note: we *could* check > > > 'use_xsave()' instead of 'state_size > offsetof(struct xregs_state, header)', > > > but that might be confusing in the case where we couldn't find the xstate > > > information in the memory layout and only copy the fxregs_state, since then we'd > > > actually be validating the xsave_header which was already there, which shouldn't > > > ever fail. > > > > > > diff --git a/arch/x86/kernel/fpu/signal.c b/arch/x86/kernel/fpu/signal.c > > > index afe54247cf27..fb639e70048f 100644 > > > --- a/arch/x86/kernel/fpu/signal.c > > > +++ b/arch/x86/kernel/fpu/signal.c > > > @@ -331,7 +331,8 @@ static int __fpu__restore_sig(void __user *buf, void __user *buf_fx, int size) > > > err = copy_user_to_xstate(&fpu->state.xsave, buf_fx); > > > } else { > > > err = __copy_from_user(&fpu->state.xsave, buf_fx, state_size); > > > - if (!err) > > > + > > > + if (!err && state_size > offsetof(struct xregs_state, header)) > > > err = validate_xstate_header(&fpu->state.xsave.header); > > > } > > > > I.e. a better check would be to check that the whole header can be accessed: > > > > state_size >= offsetof(struct xregs_state, header) + sizeof(struct xstate_header) > > > > Not that there should ever be a 'state_size' that points inside the header - so in > > the end I back-merged your original (and tested ...) version. > > > > Well, actually we'd need to validate the header if userspace overwrote any part > of it. > > But more importantly, I think the state_size check needs to go into the first > patch (the one that's Cc'ed to stable as it fixes the real bug), since > ->xcomp_bv is part of the xstate_header. So *before* we switch to > validate_xstate_header() in this patch, the code should already be: > > if (using_compacted_format()) { > err = copy_user_to_xstate(&fpu->state.xsave, buf_fx); > } else { > err = __copy_from_user(&fpu->state.xsave, buf_fx, state_size); > > /* xcomp_bv must be 0 when using uncompacted format */ > if (!err && > state_size > offsetof(struct xregs_state, header) && > fpu->state.xsave.header.xcomp_bv) > err = -EINVAL; > } Note that I think the whole series is more robust if it goes to -stable as-is, as the ABI aspect should not be underestimated either. Nevertheless I've backmerged the fix further to the original commit, to maintain bisectability. > Also can you please fix the commit title and message of this patch? It should > say "__fpu__restore_sig()", not "sanitize_restored_xstate()". Indeed - and I fixed that too. I have pushed out the latest tip:WIP.x86/fpu - no change in the end result tree, but different inner structure. Thanks, Ingo