All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Thomas Garnier <thgarnie@google.com>
Cc: "Nicolas Pitre" <nicolas.pitre@linaro.org>,
	"Peter Zijlstra" <a.p.zijlstra@chello.nl>,
	"Michal Hocko" <mhocko@suse.com>,
	"kvm list" <kvm@vger.kernel.org>,
	"Radim Krčmář" <rkrcmar@redhat.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Catalin Marinas" <catalin.marinas@arm.com>,
	"Christopher Li" <sparse@chrisli.org>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"David Howells" <dhowells@redhat.com>,
	"Paul Gortmaker" <paul.gortmaker@windriver.com>,
	"Pavel Machek" <pavel@ucw.cz>, "H . Peter Anvin" <hpa@zytor.com>,
	"Kernel Hardening" <kernel-hardening@lists.openwall.com>,
	"Christoph Lameter" <cl@linux.com>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Kees Cook" <keescook@chromium.org>,
	"the arch/x86 maintainers" <x86@kernel.org>,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Matthew Wilcox" <mawilcox@microsoft.com>,
	"Peter Foley" <pefoley2@pefoley.com>
Subject: Re: x86: PIE support and option to extend KASLR randomization
Date: Wed, 16 Aug 2017 17:12:35 +0200	[thread overview]
Message-ID: <20170816151235.oamkdva6cwpc4cex__28917.9200576202$1502896486$gmane$org@gmail.com> (raw)
In-Reply-To: <CAJcbSZE+TiY2whT94WqCJNXzR=2ATOHcQ10H5RqBZA1j=k1VHQ@mail.gmail.com>


* Thomas Garnier <thgarnie@google.com> wrote:

> On Tue, Aug 15, 2017 at 12:56 AM, Ingo Molnar <mingo@kernel.org> wrote:
> >
> > * Thomas Garnier <thgarnie@google.com> wrote:
> >
> >> > Do these changes get us closer to being able to build the kernel as truly
> >> > position independent, i.e. to place it anywhere in the valid x86-64 address
> >> > space? Or any other advantages?
> >>
> >> Yes, PIE allows us to put the kernel anywhere in memory. It will allow us to
> >> have a full randomized address space where position and order of sections are
> >> completely random. There is still some work to get there but being able to build
> >> a PIE kernel is a significant step.
> >
> > So I _really_ dislike the whole PIE approach, because of the huge slowdown:
> >
> > +config RANDOMIZE_BASE_LARGE
> > +       bool "Increase the randomization range of the kernel image"
> > +       depends on X86_64 && RANDOMIZE_BASE
> > +       select X86_PIE
> > +       select X86_MODULE_PLTS if MODULES
> > +       default n
> > +       ---help---
> > +         Build the kernel as a Position Independent Executable (PIE) and
> > +         increase the available randomization range from 1GB to 3GB.
> > +
> > +         This option impacts performance on kernel CPU intensive workloads up
> > +         to 10% due to PIE generated code. Impact on user-mode processes and
> > +         typical usage would be significantly less (0.50% when you build the
> > +         kernel).
> > +
> > +         The kernel and modules will generate slightly more assembly (1 to 2%
> > +         increase on the .text sections). The vmlinux binary will be
> > +         significantly smaller due to less relocations.
> >
> > To put 10% kernel overhead into perspective: enabling this option wipes out about
> > 5-10 years worth of painstaking optimizations we've done to keep the kernel fast
> > ... (!!)
> 
> Note that 10% is the high-bound of a CPU intensive workload.

Note that the 8-10% hackbench or even a 2%-4% range would be 'huge' in terms of 
modern kernel performance. In many cases we are literally applying cycle level 
optimizations that are barely measurable. A 0.1% speedup in linear execution speed 
is already a big success.

> I am going to start doing performance testing on -mcmodel=large to see if it is 
> faster than -fPIE.

Unfortunately mcmodel=large looks pretty heavy too AFAICS, at the machine 
instruction level.

Function calls look like this:

 -mcmodel=medium:

   757:   e8 98 ff ff ff          callq  6f4 <test_code>

 -mcmodel=large

   77b:   48 b8 10 f7 df ff ff    movabs $0xffffffffffdff710,%rax
   782:   ff ff ff 
   785:   48 8d 04 03             lea    (%rbx,%rax,1),%rax
   789:   ff d0                   callq  *%rax

And we'd do this for _EVERY_ function call in the kernel. That kind of crap is 
totally unacceptable.

> > I think the fundamental flaw is the assumption that we need a PIE executable 
> > to have a freely relocatable kernel on 64-bit CPUs.
> >
> > Have you considered a kernel with -mcmodel=small (or medium) instead of -fpie 
> > -mcmodel=large? We can pick a random 2GB window in the (non-kernel) canonical 
> > x86-64 address space to randomize the location of kernel text. The location of 
> > modules can be further randomized within that 2GB window.
> 
> -model=small/medium assume you are on the low 32-bit. It generates instructions 
> where the virtual addresses have the high 32-bit to be zero.

How are these assumptions hardcoded by GCC? Most of the instructions should be 
relocatable straight away, as most call/jump/branch instructions are RIP-relative.

I.e. is there no GCC code generation mode where code can be placed anywhere in the 
canonical address space, yet call and jump distance is within 31 bits so that the 
generated code is fast?

Thanks,

	Ingo

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2017-08-16 15:12 UTC|newest]

Thread overview: 221+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-10 17:25 x86: PIE support and option to extend KASLR randomization Thomas Garnier
2017-08-10 17:25 ` [kernel-hardening] " Thomas Garnier
2017-08-10 17:25 ` [RFC v2 01/23] x86/crypto: Adapt assembly for PIE support Thomas Garnier
2017-08-10 17:25   ` [kernel-hardening] " Thomas Garnier
2017-08-10 17:25 ` [RFC v2 02/23] x86: Use symbol name on bug table " Thomas Garnier
2017-08-10 17:25   ` [kernel-hardening] " Thomas Garnier
2017-08-10 17:25 ` [RFC v2 03/23] x86: Use symbol name in jump " Thomas Garnier
2017-08-10 17:25   ` [kernel-hardening] " Thomas Garnier
2017-08-10 17:25 ` [RFC v2 04/23] x86: Add macro to get symbol address " Thomas Garnier
2017-08-10 17:25   ` [kernel-hardening] " Thomas Garnier
2017-08-10 17:25 ` [RFC v2 05/23] xen: Adapt assembly " Thomas Garnier
2017-08-10 17:25   ` [kernel-hardening] " Thomas Garnier
2017-08-10 17:25 ` [RFC v2 06/23] kvm: " Thomas Garnier
2017-08-10 17:25   ` [kernel-hardening] " Thomas Garnier
2017-08-10 17:25 ` [RFC v2 07/23] x86: relocate_kernel - " Thomas Garnier
2017-08-10 17:25   ` [kernel-hardening] " Thomas Garnier
2017-08-10 17:26 ` [RFC v2 08/23] x86/entry/64: " Thomas Garnier
2017-08-10 17:26   ` [kernel-hardening] " Thomas Garnier
2017-08-10 17:26 ` [RFC v2 09/23] x86: pm-trace - " Thomas Garnier
2017-08-10 17:26   ` [kernel-hardening] " Thomas Garnier
2017-08-10 17:26 ` [RFC v2 10/23] x86/CPU: " Thomas Garnier
2017-08-10 17:26   ` [kernel-hardening] " Thomas Garnier
2017-08-10 17:26 ` [RFC v2 11/23] x86/acpi: " Thomas Garnier
2017-08-10 17:26   ` [kernel-hardening] " Thomas Garnier
2017-08-10 17:26 ` [RFC v2 12/23] x86/boot/64: " Thomas Garnier
2017-08-10 17:26   ` [kernel-hardening] " Thomas Garnier
2017-08-10 17:26 ` [RFC v2 13/23] x86/power/64: " Thomas Garnier
2017-08-10 17:26   ` [kernel-hardening] " Thomas Garnier
2017-08-11 12:36   ` Pavel Machek
2017-08-11 12:36   ` Pavel Machek
2017-08-11 12:36     ` [kernel-hardening] " Pavel Machek
2017-08-11 15:09     ` Thomas Garnier
2017-08-11 15:09       ` [kernel-hardening] " Thomas Garnier
2017-08-11 15:09     ` Thomas Garnier
2017-08-10 17:26 ` [RFC v2 14/23] x86/paravirt: " Thomas Garnier
2017-08-10 17:26   ` [kernel-hardening] " Thomas Garnier
2017-08-10 17:26 ` [RFC v2 15/23] x86/boot/64: Use _text in a global " Thomas Garnier
2017-08-10 17:26   ` [kernel-hardening] " Thomas Garnier
2017-08-10 17:26 ` [RFC v2 16/23] x86/percpu: Adapt percpu " Thomas Garnier
2017-08-10 17:26   ` [kernel-hardening] " Thomas Garnier
2017-08-10 17:26 ` [RFC v2 17/23] compiler: Option to default to hidden symbols Thomas Garnier
2017-08-10 17:26   ` [kernel-hardening] " Thomas Garnier
2017-08-10 17:26 ` [RFC v2 18/23] x86/relocs: Handle DYN relocations for PIE support Thomas Garnier
2017-08-10 17:26   ` [kernel-hardening] " Thomas Garnier
2017-08-10 17:26 ` [RFC v2 19/23] x86: Support global stack cookie Thomas Garnier
2017-08-10 17:26   ` [kernel-hardening] " Thomas Garnier
2017-08-10 17:26 ` [RFC v2 20/23] x86/pie: Add option to build the kernel as PIE for x86_64 Thomas Garnier
2017-08-10 17:26   ` [kernel-hardening] " Thomas Garnier
2017-08-10 17:26 ` [RFC v2 21/23] x86/relocs: Add option to generate 64-bit relocations Thomas Garnier
2017-08-10 17:26   ` [kernel-hardening] " Thomas Garnier
2017-08-10 17:26 ` [RFC v2 22/23] x86/module: Add support for mcmodel large and PLTs Thomas Garnier
2017-08-10 17:26   ` [kernel-hardening] " Thomas Garnier
2017-08-10 17:26 ` [RFC v2 23/23] x86/kaslr: Add option to extend KASLR range from 1GB to 3GB Thomas Garnier
2017-08-10 17:26   ` [kernel-hardening] " Thomas Garnier
2017-08-11 12:41 ` x86: PIE support and option to extend KASLR randomization Ingo Molnar
2017-08-11 12:41   ` [kernel-hardening] " Ingo Molnar
2017-08-11 15:09   ` Thomas Garnier
2017-08-11 15:09   ` Thomas Garnier
2017-08-11 15:09     ` [kernel-hardening] " Thomas Garnier
2017-08-15  7:56     ` Ingo Molnar
2017-08-15  7:56     ` Ingo Molnar
2017-08-15  7:56       ` [kernel-hardening] " Ingo Molnar
2017-08-15 12:15       ` Jordan Glover
2017-08-15 13:42         ` Rik van Riel
2017-08-15 14:20       ` Thomas Garnier
2017-08-15 14:20       ` Thomas Garnier
2017-08-15 14:20         ` [kernel-hardening] " Thomas Garnier
2017-08-15 14:47         ` Daniel Micay
2017-08-15 14:47         ` Daniel Micay
2017-08-15 14:47           ` [kernel-hardening] " Daniel Micay
2017-08-15 14:58           ` Thomas Garnier
2017-08-15 14:58           ` Thomas Garnier
2017-08-15 14:58             ` [kernel-hardening] " Thomas Garnier
2017-08-16 15:12         ` Ingo Molnar [this message]
2017-08-16 15:12         ` Ingo Molnar
2017-08-16 15:12           ` [kernel-hardening] " Ingo Molnar
2017-08-16 16:09           ` Christopher Lameter
2017-08-16 16:09           ` Christopher Lameter
2017-08-16 16:09             ` [kernel-hardening] " Christopher Lameter
2017-08-16 16:26           ` Daniel Micay
2017-08-16 16:26             ` [kernel-hardening] " Daniel Micay
2017-08-16 16:32             ` Ard Biesheuvel
2017-08-16 16:32             ` Ard Biesheuvel
2017-08-16 16:32               ` [kernel-hardening] " Ard Biesheuvel
2017-08-16 16:26           ` Daniel Micay
2017-08-16 16:57           ` Thomas Garnier
2017-08-16 16:57           ` Thomas Garnier
2017-08-16 16:57             ` [kernel-hardening] " Thomas Garnier
2017-08-17  8:09             ` Ingo Molnar
2017-08-17  8:09             ` Ingo Molnar
2017-08-17  8:09               ` [kernel-hardening] " Ingo Molnar
2017-08-17 14:10               ` Thomas Garnier
2017-08-17 14:10               ` Thomas Garnier
2017-08-17 14:10                 ` [kernel-hardening] " Thomas Garnier
2017-08-24 21:13                 ` Thomas Garnier
2017-08-24 21:13                 ` Thomas Garnier
2017-08-24 21:13                   ` [kernel-hardening] " Thomas Garnier
2017-08-24 21:42                   ` Linus Torvalds
2017-08-24 21:42                   ` Linus Torvalds
2017-08-24 21:42                     ` [kernel-hardening] " Linus Torvalds
2017-08-25 15:35                     ` Thomas Garnier
2017-08-25 15:35                       ` [kernel-hardening] " Thomas Garnier
2017-08-25 15:35                     ` Thomas Garnier
2017-08-25  1:07                   ` Steven Rostedt
2017-08-25  1:07                     ` [kernel-hardening] " Steven Rostedt
2017-08-25  8:04                   ` Ingo Molnar
2017-08-25  8:04                   ` Ingo Molnar
2017-08-25  8:04                     ` [kernel-hardening] " Ingo Molnar
2017-08-25 15:05                     ` Thomas Garnier
2017-08-25 15:05                     ` Thomas Garnier
2017-08-25 15:05                       ` [kernel-hardening] " Thomas Garnier
2017-08-29 19:34                       ` Thomas Garnier
2017-08-29 19:34                         ` [kernel-hardening] " Thomas Garnier
2017-09-21 15:59                         ` Ingo Molnar
2017-09-21 15:59                           ` [kernel-hardening] " Ingo Molnar
2017-09-21 16:10                           ` Ard Biesheuvel
2017-09-21 16:10                           ` Ard Biesheuvel
2017-09-21 16:10                             ` [kernel-hardening] " Ard Biesheuvel
2017-09-21 21:21                             ` Thomas Garnier
2017-09-21 21:21                             ` Thomas Garnier
2017-09-21 21:21                               ` [kernel-hardening] " Thomas Garnier
2017-09-22  4:24                               ` Markus Trippelsdorf
2017-09-22  4:24                                 ` [kernel-hardening] " Markus Trippelsdorf
2017-09-22 14:38                                 ` Thomas Garnier
2017-09-22 14:38                                   ` [kernel-hardening] " Thomas Garnier
2017-09-22 14:38                                 ` Thomas Garnier
2017-09-22 23:55                               ` Thomas Garnier
2017-09-22 23:55                               ` Thomas Garnier
2017-09-22 23:55                                 ` [kernel-hardening] " Thomas Garnier
2017-09-21 21:16                           ` Thomas Garnier
2017-09-21 21:16                             ` [kernel-hardening] " Thomas Garnier
2017-09-22  0:06                             ` Thomas Garnier
2017-09-22  0:06                             ` Thomas Garnier
2017-09-22  0:06                               ` [kernel-hardening] " Thomas Garnier
2017-09-22 16:32                             ` Ingo Molnar
2017-09-22 16:32                               ` [kernel-hardening] " Ingo Molnar
2017-09-22 18:08                               ` Thomas Garnier
2017-09-22 18:08                               ` Thomas Garnier
2017-09-22 18:08                                 ` [kernel-hardening] " Thomas Garnier
2017-09-23  9:43                                 ` Ingo Molnar
2017-09-23  9:43                                   ` [kernel-hardening] " Ingo Molnar
2017-10-02 20:28                                   ` Thomas Garnier
2017-10-02 20:28                                   ` Thomas Garnier
2017-10-02 20:28                                     ` [kernel-hardening] " Thomas Garnier
2017-09-23  9:43                                 ` Ingo Molnar
2017-09-22 18:38                               ` H. Peter Anvin
2017-09-22 18:38                                 ` [kernel-hardening] " H. Peter Anvin
2017-09-22 18:57                                 ` Kees Cook
2017-09-22 18:57                                   ` [kernel-hardening] " Kees Cook
2017-09-22 19:06                                   ` H. Peter Anvin
2017-09-22 19:06                                     ` [kernel-hardening] " H. Peter Anvin
2017-09-22 22:19                                     ` hjl.tools
2017-09-22 22:30                                     ` hjl.tools
2017-09-22 19:06                                   ` H. Peter Anvin
2017-09-22 18:57                                 ` Kees Cook
2017-09-22 18:59                                 ` Thomas Garnier
2017-09-22 18:59                                 ` Thomas Garnier
2017-09-22 18:59                                   ` [kernel-hardening] " Thomas Garnier
2017-09-23  9:49                                 ` Ingo Molnar
2017-09-23  9:49                                 ` Ingo Molnar
2017-09-23  9:49                                   ` [kernel-hardening] " Ingo Molnar
2017-09-22 18:38                               ` H. Peter Anvin
2017-09-22 16:32                             ` Ingo Molnar
2017-09-21 21:16                           ` Thomas Garnier
2017-09-21 15:59                         ` Ingo Molnar
2017-08-29 19:34                       ` Thomas Garnier
2017-08-17 14:12               ` Boris Lukashev
2017-08-17 14:12                 ` [kernel-hardening] " Boris Lukashev
2017-08-25 15:38                 ` Christopher Lameter
2017-08-25 15:38                   ` [kernel-hardening] " Christopher Lameter
2017-08-27 22:39                   ` Boris Lukashev
2017-08-27 22:39                   ` Boris Lukashev
2017-08-27 22:39                     ` [kernel-hardening] " Boris Lukashev
2017-08-25 15:38                 ` Christopher Lameter
2017-08-28  9:59                 ` Pavel Machek
2017-08-28  9:59                 ` Pavel Machek
2017-08-28  9:59                   ` [kernel-hardening] " Pavel Machek
2017-08-17 14:12               ` Boris Lukashev
2017-08-21 13:32           ` Peter Zijlstra
2017-08-21 13:32             ` [kernel-hardening] " Peter Zijlstra
2017-08-21 14:28             ` Peter Zijlstra
2017-08-21 14:28             ` Peter Zijlstra
2017-08-21 14:28               ` [kernel-hardening] " Peter Zijlstra
2017-09-22 18:27               ` H. Peter Anvin
2017-09-22 18:27                 ` [kernel-hardening] " H. Peter Anvin
2017-09-23 10:00                 ` Ingo Molnar
2017-09-23 10:00                   ` [kernel-hardening] " Ingo Molnar
2017-09-24 22:37                   ` Pavel Machek
2017-09-24 22:37                     ` [kernel-hardening] " Pavel Machek
2017-09-25  7:33                     ` Ingo Molnar
2017-09-25  7:33                     ` Ingo Molnar
2017-09-25  7:33                       ` [kernel-hardening] " Ingo Molnar
2017-10-06 10:39                       ` Pavel Machek
2017-10-06 10:39                       ` Pavel Machek
2017-10-06 10:39                         ` [kernel-hardening] " Pavel Machek
2017-10-20  8:13                         ` Ingo Molnar
2017-10-20  8:13                           ` [kernel-hardening] " Ingo Molnar
2017-10-20  8:13                         ` Ingo Molnar
2017-09-24 22:37                   ` Pavel Machek
2017-09-23 10:00                 ` Ingo Molnar
2017-09-22 18:27               ` H. Peter Anvin
2017-08-21 13:32           ` Peter Zijlstra
2017-08-21 14:31         ` Peter Zijlstra
2017-08-21 14:31           ` [kernel-hardening] " Peter Zijlstra
2017-08-21 15:57           ` Thomas Garnier
2017-08-21 15:57           ` Thomas Garnier
2017-08-21 15:57             ` [kernel-hardening] " Thomas Garnier
2017-08-28  1:26           ` H. Peter Anvin
2017-08-28  1:26             ` [kernel-hardening] " H. Peter Anvin
2017-08-28  1:26           ` H. Peter Anvin
2017-08-21 14:31         ` Peter Zijlstra
2017-08-11 12:41 ` Ingo Molnar
  -- strict thread matches above, loose matches on Subject: below --
2017-10-04 21:19 Thomas Garnier
2017-10-04 21:19 Thomas Garnier via Virtualization
2017-10-04 21:19 Thomas Garnier
2017-10-04 21:19 ` Thomas Garnier
2017-08-10 17:25 Thomas Garnier
2017-07-18 22:33 Thomas Garnier
2017-07-19 14:08 ` Christopher Lameter
2017-07-19 14:08 ` Christopher Lameter
2017-07-18 22:33 Thomas Garnier

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='20170816151235.oamkdva6cwpc4cex__28917.9200576202$1502896486$gmane$org@gmail.com' \
    --to=mingo@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=ast@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=cl@linux.com \
    --cc=daniel@iogearbox.net \
    --cc=dhowells@redhat.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=hpa@zytor.com \
    --cc=keescook@chromium.org \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=kvm@vger.kernel.org \
    --cc=mawilcox@microsoft.com \
    --cc=mhocko@suse.com \
    --cc=nicolas.pitre@linaro.org \
    --cc=paul.gortmaker@windriver.com \
    --cc=pavel@ucw.cz \
    --cc=pefoley2@pefoley.com \
    --cc=peterz@infradead.org \
    --cc=rkrcmar@redhat.com \
    --cc=sparse@chrisli.org \
    --cc=tglx@linutronix.de \
    --cc=thgarnie@google.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.