public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: ebiederm@xmission.com (Eric W. Biederman)
To: Willy Tarreau <w@1wt.eu>
Cc: linux-kernel@vger.kernel.org, x86@kernel.org, tglx@linutronix.de,
	gnomes@lxorguk.ukuu.org.uk, torvalds@linux-foundation.org
Subject: Re: [PATCH RFC 0/4] Per-task PTI activation
Date: Tue, 09 Jan 2018 09:31:27 -0600	[thread overview]
Message-ID: <87a7xnkq0g.fsf@xmission.com> (raw)
In-Reply-To: <1515427939-10999-1-git-send-email-w@1wt.eu> (Willy Tarreau's message of "Mon, 8 Jan 2018 17:12:15 +0100")

Willy Tarreau <w@1wt.eu> writes:

> Hi!
>
> I could experiment a bit with the possibility to enable/disable PTI per
> task. Please keep in mind that it's not my area of experitise at all, but
> doing so I could recover the initial performance without disabling PTI on
> the whole system.
>
> So what I did in this series consists in the following :
>   - addition of a new per-task TIF_NOPTI flag. Please note that I'm not
>     proud of the way I did it, as 32 flags were already taken. The flags
>     are declared as "long" so there are 32 more flags available on x86_64
>     but C and asm disagree on the type of 1<<32 so I had to declare the
>     hex value by hand... By the way I even suspect that _TIF_FSCHECK is
>     wrong once cast to a long, I think it causes sign extension into the
>     32 upper bits since it's supposed to be signed.
>
>   - addition of a set of arch_prctl() calls (ARCH_GET_NOPTI and
>     ARCH_SET_NOPTI), to check and change the activation of the
>     protection. The change requires CAP_SYS_RAWIO and can be done in
>     a wrapper (that's how I tested)
>
>   - the user PGD was marked with _PAGE_NX to prevent an accidental leak
>     of CR3 from not being detected. I obviously had to disable this since
>     in this case we do want such a user task to run without switching the
>     PGD. I think this could be performed per-task maybe. Another approach
>     might consist in dealing with 3 PGDs and using a different one for
>     unprotected tasks but that really starts to sound overkill.
>
>   - upon return to userspace, I check if the task's flags contain the
>     new TIF_NOPTI or not. If it does contain it, then we don't switch
>     the CR3.
>
>   - upon entry into the kernel from userspace, we can't access the task's
>     flags but we can already check if CR3 points to the kernel or user PGD,
>     and we refrain from switching if it's already the system one.
>
> By doing so I could recover the initial performance of haproxy in a VM,
> going from 12400 connections per second to 21000 once started with this
> trivial wrapper :
>
>   #include <asm/prctl.h>
>   #include <sys/prctl.h>
>   
>   #ifndef ARCH_SET_NOPTI
>   #define ARCH_SET_NOPTI 0x1022
>   #endif
>   
>   int main(int argc, char **argv)
>   {
>           arch_prctl(ARCH_SET_NOPTI, 1);
>           argv++;
>           return execvp(argv[0], argv);
>   }
>
> I have not yet run it on real hardware. Before trying to go a bit further
> I'd like to know if such an approach is acceptable or if I'm doing anything
> stupid and looking in the wrong direction.

Before this goes much farther I want to point something out.

When I have kpti protecting me it is the applications with that connect
to the network I worry about.  Until I get to a system with users that
don't trust each other local I don't have a reason to worry about these
attacks from local applications.

The dangerous scenario is someone exploting a buffer overflow, or
otherwise getting a network facing application to misbehave, and then
using these new attacks to assist in gaining privilege escalation.


Googling seems to indicate that there is about one issue a year found in
haproxy.  So this is not an unrealistic concern for the case you
mention.


So unless I am seeing things wrong this is a patchset designed to drop
your defensense on the most vulnerable applications.


Disably protection on the most vunerable applications is not behavior
I would encourage.  It seems better than disabling protection system
wide but only slightly.   I definitely don't think this is something we
want applications disabling themselves.

Certainly this is something that should look at no-new-privs and if
no-new-privs is set not allow disabling this protection.

Eric

  parent reply	other threads:[~2018-01-09 15:32 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-08 16:12 [PATCH RFC 0/4] Per-task PTI activation Willy Tarreau
2018-01-08 16:12 ` [PATCH RFC 1/4] x86/thread_info: add TIF_NOPTI to disable PTI per task Willy Tarreau
2018-01-08 16:57   ` Thomas Gleixner
2018-01-08 17:03     ` Willy Tarreau
2018-01-08 17:14       ` Ingo Molnar
2018-01-08 16:12 ` [PATCH RFC 2/4] x86/arch_prctl: add ARCH_GET_NOPTI and ARCH_SET_NOPTI to enable/disable PTI Willy Tarreau
2018-01-08 16:49   ` Peter Zijlstra
2018-01-08 16:56     ` Willy Tarreau
2018-01-08 17:02   ` Thomas Gleixner
2018-01-08 17:10     ` Willy Tarreau
2018-01-08 17:17     ` Ingo Molnar
2018-01-08 17:26       ` Thomas Gleixner
2018-01-08 17:46         ` Ingo Molnar
2018-01-08 17:05   ` Ingo Molnar
2018-01-08 17:19     ` Peter Zijlstra
2018-01-08 17:26       ` Ingo Molnar
2018-01-08 17:50   ` Borislav Petkov
2018-01-08 17:54   ` Linus Torvalds
2018-01-08 18:22     ` Willy Tarreau
2018-01-08 20:49       ` Thomas Gleixner
2018-01-08 21:03         ` Willy Tarreau
2018-01-08 20:35     ` Willy Tarreau
2018-01-08 16:12 ` [PATCH RFC 3/4] x86/pti: don't mark the user PGD with _PAGE_NX Willy Tarreau
2018-01-08 17:03   ` Dave Hansen
2018-01-08 17:17     ` Willy Tarreau
2018-01-08 17:23       ` Dave Hansen
2018-01-08 17:30         ` Peter Zijlstra
2018-01-08 17:49           ` Willy Tarreau
2018-01-08 17:21     ` Ingo Molnar
2018-01-08 23:05     ` Andy Lutomirski
2018-01-08 23:09       ` Kees Cook
2018-01-09  4:22       ` Willy Tarreau
2018-01-08 17:05   ` Thomas Gleixner
2018-01-08 17:28     ` Dave Hansen
2018-01-08 17:50       ` Ingo Molnar
2018-01-08 18:25         ` Alan Cox
2018-01-08 18:35           ` Ingo Molnar
2018-01-08 18:35           ` Linus Torvalds
2018-01-08 18:44         ` Dave Hansen
2018-01-08 16:12 ` [PATCH RFC 4/4] x86/entry/pti: don't switch PGD on tasks holding flag TIF_NOPTI Willy Tarreau
2018-01-08 17:11   ` Ingo Molnar
2018-01-08 17:20   ` Dave Hansen
2018-01-08 18:12     ` Willy Tarreau
2018-01-08 23:01   ` Andy Lutomirski
2018-01-08 16:59 ` [PATCH RFC 0/4] Per-task PTI activation Dave Hansen
2018-01-08 17:06   ` Willy Tarreau
2018-01-08 17:17     ` Dave Hansen
2018-01-08 17:13   ` Ingo Molnar
2018-01-09 15:31 ` Eric W. Biederman [this message]
2018-01-09 16:02   ` Willy Tarreau
2018-01-09 18:11     ` Zhi Wang
2018-01-09 21:07     ` Eric W. Biederman
2018-01-09 21:57       ` Willy Tarreau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a7xnkq0g.fsf@xmission.com \
    --to=ebiederm@xmission.com \
    --cc=gnomes@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=w@1wt.eu \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox