From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S937050AbdIZIqX (ORCPT ); Tue, 26 Sep 2017 04:46:23 -0400 Received: from terminus.zytor.com ([65.50.211.136]:40515 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966350AbdIZIqS (ORCPT ); Tue, 26 Sep 2017 04:46:18 -0400 Date: Tue, 26 Sep 2017 01:37:29 -0700 From: tip-bot for Eric Biggers Message-ID: Cc: mingo@kernel.org, haokexin@gmail.com, peterz@infradead.org, linux-kernel@vger.kernel.org, riel@redhat.com, keescook@chromium.org, ebiggers3@gmail.com, mhalcrow@google.com, fenghua.yu@intel.com, luto@amacapital.net, yu-cheng.yu@intel.com, luto@kernel.org, ebiggers@google.com, tglx@linutronix.de, oleg@redhat.com, dvyukov@google.com, hpa@zytor.com, dave.hansen@linux.intel.com, wanpeng.li@hotmail.com, bp@alien8.de, torvalds@linux-foundation.org, akpm@linux-foundation.org Reply-To: yu-cheng.yu@intel.com, ebiggers@google.com, luto@kernel.org, riel@redhat.com, linux-kernel@vger.kernel.org, mingo@kernel.org, haokexin@gmail.com, peterz@infradead.org, luto@amacapital.net, fenghua.yu@intel.com, mhalcrow@google.com, keescook@chromium.org, ebiggers3@gmail.com, torvalds@linux-foundation.org, akpm@linux-foundation.org, hpa@zytor.com, dave.hansen@linux.intel.com, tglx@linutronix.de, oleg@redhat.com, dvyukov@google.com, bp@alien8.de, wanpeng.li@hotmail.com In-Reply-To: <20170924105913.9157-10-mingo@kernel.org> References: <20170924105913.9157-10-mingo@kernel.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/fpu] x86/fpu: Use validate_xstate_header() to validate the xstate_header in copy_user_to_xstate() Git-Commit-ID: 98c0fad9d60e8b2cd47e15b7bee7df343648f5bb X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 98c0fad9d60e8b2cd47e15b7bee7df343648f5bb Gitweb: http://git.kernel.org/tip/98c0fad9d60e8b2cd47e15b7bee7df343648f5bb Author: Eric Biggers AuthorDate: Sun, 24 Sep 2017 12:59:12 +0200 Committer: Ingo Molnar CommitDate: Tue, 26 Sep 2017 09:43:48 +0200 x86/fpu: Use validate_xstate_header() to validate the xstate_header in copy_user_to_xstate() Tighten the checks in copy_user_to_xstate(). Signed-off-by: Eric Biggers Cc: Andrew Morton Cc: Andy Lutomirski Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Dave Hansen Cc: Dmitry Vyukov Cc: Eric Biggers Cc: Fenghua Yu Cc: Kees Cook Cc: Kevin Hao Cc: Linus Torvalds Cc: Michael Halcrow Cc: Oleg Nesterov Cc: Peter Zijlstra Cc: Rik van Riel Cc: Thomas Gleixner Cc: Wanpeng Li Cc: Yu-cheng Yu Cc: kernel-hardening@lists.openwall.com Link: http://lkml.kernel.org/r/20170924105913.9157-10-mingo@kernel.org Signed-off-by: Ingo Molnar --- arch/x86/kernel/fpu/xstate.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index b6d78b7..f1d5476 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -1188,16 +1188,15 @@ int copy_kernel_to_xstate(struct xregs_state *xsave, const void *kbuf) } /* - * Convert from a ptrace standard-format user-space buffer to kernel XSAVES format - * and copy to the target thread. This is called from xstateregs_set() and - * there we check the CPU has XSAVES and a whole standard-sized buffer - * exists. + * Convert from a ptrace or sigreturn standard-format user-space buffer to + * kernel XSAVES format and copy to the target thread. This is called from + * xstateregs_set(), as well as potentially from the sigreturn() and + * rt_sigreturn() system calls. */ int copy_user_to_xstate(struct xregs_state *xsave, const void __user *ubuf) { unsigned int offset, size; int i; - u64 allowed_features; struct xstate_header hdr; offset = offsetof(struct xregs_state, header); @@ -1206,12 +1205,7 @@ int copy_user_to_xstate(struct xregs_state *xsave, const void __user *ubuf) if (__copy_from_user(&hdr, ubuf + offset, size)) return -EFAULT; - /* - * Reject if the user sets any disabled or supervisor features: - */ - allowed_features = xfeatures_mask & ~XFEATURE_MASK_SUPERVISOR; - - if (hdr.xfeatures & ~allowed_features) + if (validate_xstate_header(&hdr)) return -EINVAL; for (i = 0; i < XFEATURE_MAX; i++) {