From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753131AbdIXSvw (ORCPT ); Sun, 24 Sep 2017 14:51:52 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:34988 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752728AbdIXSvu (ORCPT ); Sun, 24 Sep 2017 14:51:50 -0400 X-Google-Smtp-Source: AOwi7QBVe1yjzthzfCrvcld0sLcQT2k5UyFTOvNHl8TBwWdFNP5KP15Q2dRU7WAgNOy0a2PgcdmT7g== Date: Sun, 24 Sep 2017 11:51:47 -0700 From: Eric Biggers To: Ingo Molnar 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: <20170924185147.GA26260@zzz.localdomain> References: <20170924105913.9157-1-mingo@kernel.org> <20170924105913.9157-4-mingo@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170924105913.9157-4-mingo@kernel.org> User-Agent: Mutt/1.9.0 (2017-09-02) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Sep 24, 2017 at 12:59:06PM +0200, Ingo Molnar wrote: > @@ -328,10 +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); > - > - /* xcomp_bv must be 0 when using uncompacted format */ > - if (!err && fpu->state.xsave.header.xcomp_bv) > - err = -EINVAL; > + if (!err) > + err = validate_xstate_header(&fpu->state.xsave.header); > } > Sorry, this is the buggy part. The problem is that this code runs even if XSAVE isn't being used --- and in that case the state size is 512 bytes or less, so the state doesn't actually include the xstate_header. So validate_xstate_header() was reading out of bounds and seeing invalid values. So I think we need to check use_xsave() here, but it really needs to be in the earlier patch which added the check for just ->xcomp_bv ("x86/fpu: Don't let userspace set bogus xcomp_bv"), not in this one. As far the split of patch 2/3 into these 10 patches, it looks fine (though it suddenly became a *lot* of patches!). One nit: the subject of this one really should say "__fpu__restore_sig()", not "sanitize_restored_xstate()". I can send a fixed series when I have a chance. Eric