On Wed, Sep 14, 2016 at 6:54 PM, Andy Lutomirski <luto@xxxxxxxxxxxxxx> wrote: > On Wed, Sep 14, 2016 at 6:47 PM, Kyle Huey <me@xxxxxxxxxxxx> wrote: >> On Wed, Sep 14, 2016 at 6:29 PM, Andy Lutomirski <luto@xxxxxxxxxxxxxx> wrote: >>> On Wed, Sep 14, 2016 at 2:01 PM, Kyle Huey <me@xxxxxxxxxxxx> 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? Yes, ok. Robert and I agree that resetting does make the most sense. Using this usefully requires a ptrace supervisor (to catch the traps), which can easily inject a call to arch_prctl to reenable ARCH_CPUID_SIGSEGV when desired. - Kyle -- To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html