From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933497AbcIOBzj (ORCPT ); Wed, 14 Sep 2016 21:55:39 -0400 Received: from mail-vk0-f42.google.com ([209.85.213.42]:36164 "EHLO mail-vk0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756264AbcIOBzg (ORCPT ); Wed, 14 Sep 2016 21:55:36 -0400 MIME-Version: 1.0 In-Reply-To: References: <1473886902-17902-1-git-send-email-khuey@kylehuey.com> <1473886902-17902-4-git-send-email-khuey@kylehuey.com> From: Andy Lutomirski Date: Wed, 14 Sep 2016 18:54:59 -0700 Message-ID: Subject: Re: [PATCH v2 3/3] x86,arch_prctl Add ARCH_[GET|SET]_CPUID for controlling the CPUID instruction To: Kyle Huey Cc: "Robert O'Callahan" , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , Shuah Khan , "Peter Zijlstra (Intel)" , Borislav Petkov , "Rafael J. Wysocki" , Len Brown , Srinivas Pandruvada , Aravind Gopalakrishnan , Alexander Shishkin , Vladimir Zapolskiy , Andy Lutomirski , Frederic Weisbecker , Dmitry Safonov , Kees Cook , "Michael S. Tsirkin" , Andrey Ryabinin , Jiri Slaby , Paul Gortmaker , Denys Vlasenko , Dave Hansen , "open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "open list:KERNEL SELFTEST FRAMEWORK" Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 14, 2016 at 6:47 PM, Kyle Huey wrote: > On Wed, Sep 14, 2016 at 6:29 PM, Andy Lutomirski wrote: >> On Wed, Sep 14, 2016 at 2:01 PM, Kyle Huey wrote: >>> + >>> +int set_cpuid_mode(struct task_struct *task, unsigned long val) >>> +{ >>> + /* Only disable/enable_cpuid() if it is supported on this hardware. */ >>> + bool cpuid_fault_supported = static_cpu_has(X86_FEATURE_CPUID_FAULT); >>> + >>> + if (val == ARCH_CPUID_ENABLE && cpuid_fault_supported) { >>> + if (task_no_new_privs(task) && test_thread_flag(TIF_NOCPUID)) >>> + return -EACCES; >> >> This check seems confused. If this flag were preserved on execve, >> it's the SIGSEGV mode that would need the check. > > Not sure I follow this one. no_new_privs should block transitions > from SIGSEGV to ENABLE, right? That's what this check does. It's the other way around entirely: if you make a change to your process context such that a subseqently execve()'d setuid program might malfunction, you've just done something dangerous. This is only okay, at least in newly-supported instances, if you are either privileged or if you have no_new_privs set. Having privilege makes it okay: unprivileged programs can't use it to subvert setuid programs. no_new_privs makes it safe as well: if no_new_privs is set, you can't gain privilege via execve(), so there's no attack surface. So, if you have execve() keep ARCH_CPUID_SIGSEGV set, then setting it that way in the first place should require privilege or no_new_privs. I personally favor resetting to ARCH_CPUID_ENABLE on execve() and not worrying about no_new_privs. Does that make sense?