From patchwork Sat Sep 23 10:17:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ingo Molnar X-Patchwork-Id: 9967461 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1F001602CB for ; Sat, 23 Sep 2017 10:18:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D9CB28843 for ; Sat, 23 Sep 2017 10:18:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0108628BDA; Sat, 23 Sep 2017 10:18:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 46F9A2891E for ; Sat, 23 Sep 2017 10:18:16 +0000 (UTC) Received: (qmail 20073 invoked by uid 550); 23 Sep 2017 10:17:48 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 20052 invoked from network); 23 Sep 2017 10:17:47 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=+Su/K0yeqCTYVVQSo4sI5EujbvS7QOrme/2BGgn6aYM=; b=lxRNXiWZIHEEG/9e/bGOglPFD+At/+L7yoh2xgnpJGL7UhtDDp1+qGzwTQrkNWPRge +2CkjUPYcvUxymU3BwNVRsf8S78EI7CDpkmzbvbO7CbRzIvS05eNYFYBTHBZnJMzs8fT 0Sr3IA8GJonctkXBlz3+aHi8s14NmL7VxbshVVXpXegUE6WxHxgMPALO3oRIUTO2utWT z/p7rGzE0PpYA2n8hRJPqgBiavEF7SMLELcDH6dEd9vDpOrYAgKICDUzVdWm0Vmjq3Zk hc0Lt4Q5ttcf8vnU8/0P4U63HMilRAVlGhw3ClLsEJvSrpej6wZbq4y7JZAuWXq0kkUE ysCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=+Su/K0yeqCTYVVQSo4sI5EujbvS7QOrme/2BGgn6aYM=; b=PhABT7Y/Cbln0iZOV4vYcsXCn47seQHGInV8aGDa1xymyFfMBQTCVyXJxs8EehLswe I2+vfhZip6Kzqt5ke8m8ootK+l3hUYTAhFDqgDwHB6C6zlS+uTpIrrgyFtSbO1pVPnu1 pru+1VPpbPKUKrYmHQzRI2H3x4VG2py8X9U2IfbBFkpyBrV9RByMMXCyY9uhnVQX63Fl XT8BFfAWrEDgEmgXxqGYUOIYPahYiHCAll8SmfSXIiweWuaolNkmFmbF0oYCLr1Gq54C ZFYKMGu+HyeSttgbqO2ifmHoyuGmLlZwNO2WIUrCUHE9loJXnQCaoxyxPwmNCXtKJflp EMog== X-Gm-Message-State: AHPjjUgDSXC0Bu5fiKwlcKPRDGDXC/2dT/LvOy9CSDn9KsiJI60J3mK7 ts+fLVeqEItWGFAEXZgZsb4= X-Google-Smtp-Source: AOwi7QDaD4zi9r7eYMORlsmX7DyHWbp6F2v9JFSGeZkizj8hwxOrITTb4bEnY51AzHZEd7xmPrEHOw== X-Received: by 10.223.131.194 with SMTP id 60mr1335055wre.218.1506161856277; Sat, 23 Sep 2017 03:17:36 -0700 (PDT) Sender: Ingo Molnar Date: Sat, 23 Sep 2017 12:17:33 +0200 From: Ingo Molnar To: Eric Biggers Cc: x86@kernel.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, Andy Lutomirski , Dave Hansen , Dmitry Vyukov , Fenghua Yu , Kevin Hao , Oleg Nesterov , Wanpeng Li , Yu-cheng Yu , Michael Halcrow , Eric Biggers Message-ID: <20170923101733.kyq2avp6om2d2s3n@gmail.com> References: <20170921185239.88398-1-ebiggers3@gmail.com> <20170922053314.wryoupq2vgrel24c@gmail.com> <20170922170724.GA103935@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170922170724.GA103935@gmail.com> User-Agent: NeoMutt/20170113 (1.7.2) Subject: [kernel-hardening] [PATCH] x86/fpu: Simplify fpu__activate_fpstate_read() X-Virus-Scanned: ClamAV using ClamSMTP * Eric Biggers wrote: > On Fri, Sep 22, 2017 at 07:33:14AM +0200, Ingo Molnar wrote: > > > > * Eric Biggers wrote: > > > > > From: Eric Biggers > > > > > > This series fixes the bug found by syzkaller where the ptrace syscall > > > can be used to set invalid bits in a task's FPU state. I also found > > > that an equivalent bug was reachable using the sigreturn syscall, so the > > > first patch fixes the bug in both cases. > > > > > > The other two patches start validating the other parts of the > > > xstate_header and make it so that invalid FPU states can no longer be > > > abused to leak the FPU registers of other processes. > > > > > > Changes since v2: > > > - Use an exception handler to handle invalid FPU states > > > (suggested by Andy Lutomirski) > > > - Check the size of xstate_header.reserved at build time > > > (suggested by Dave Hansen) > > > > > > Eric Biggers (3): > > > x86/fpu: don't let userspace set bogus xcomp_bv > > > x86/fpu: tighten validation of user-supplied xstate_header > > > x86/fpu: reinitialize FPU registers if restoring FPU state fails > > > > > > arch/x86/include/asm/fpu/internal.h | 51 +++++++++++-------------------------- > > > arch/x86/include/asm/fpu/xstate.h | 25 ++++++++++++++++++ > > > arch/x86/kernel/fpu/regset.c | 20 +++++++-------- > > > arch/x86/kernel/fpu/signal.c | 15 ++++++++--- > > > arch/x86/kernel/fpu/xstate.c | 27 ++++++++------------ > > > arch/x86/mm/extable.c | 24 +++++++++++++++++ > > > 6 files changed, 94 insertions(+), 68 deletions(-) > > > > Ok - could you please rebase these to to tip:master that is at: > > > > git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git master > > > > In particular this has a WIP.x86/fpu branch with FPU fixes+changes queued up but > > not merged upstream (yet), which conflict with these changes. I'd like to merge > > them all together. > > > > Working on it, but there is a problem with current tip. PTRACE_GETREGSET is > causing the following warning: Yes, the warning should be harmless, and I fixed it locally earlier today - does the patch below solve it for you as well? Thanks, Ingo ============================> Subject: x86/fpu: Simplify fpu__activate_fpstate_read() From: Ingo Molnar Date: Sat Sep 23 11:41:23 CEST 2017 fpu__activate_fpstate_read() can only ever be called for a non-current, non-executing (stopped) task - so make sure this is checked via a warning and remove the current-task logic. This also fixes an incorrect (but harmless) warning triggered by of the earlier patches. Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Fenghua Yu Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Oleg Nesterov Cc: Peter Zijlstra Cc: Thomas Gleixner Signed-off-by: Ingo Molnar --- arch/x86/kernel/fpu/core.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) Index: linux/arch/x86/kernel/fpu/core.c =================================================================== --- linux.orig/arch/x86/kernel/fpu/core.c +++ linux/arch/x86/kernel/fpu/core.c @@ -256,26 +256,18 @@ EXPORT_SYMBOL_GPL(fpu__activate_curr); * * If the task has not used the FPU before then initialize its * fpstate. - * - * If the task has used the FPU before then save it. */ void fpu__activate_fpstate_read(struct fpu *fpu) { - /* - * If fpregs are active (in the current CPU), then - * copy them to the fpstate: - */ - if (fpu->fpstate_active) { - fpu__save(fpu); - } else { - if (!fpu->fpstate_active) { - fpstate_init(&fpu->state); - trace_x86_fpu_init_state(fpu); + WARN_ON_FPU(fpu == ¤t->thread.fpu); + + if (!fpu->fpstate_active) { + fpstate_init(&fpu->state); + trace_x86_fpu_init_state(fpu); - trace_x86_fpu_activate_state(fpu); - /* Safe to do for current and for stopped child tasks: */ - fpu->fpstate_active = 1; - } + trace_x86_fpu_activate_state(fpu); + /* Safe to do for current and for stopped child tasks: */ + fpu->fpstate_active = 1; } }