From: Ingo Molnar <mingo@kernel.org>
To: Denys Vlasenko <dvlasenk@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>,
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
Boris Ostrovsky <boris.ostrovsky@oracle.com>,
David Vrabel <david.vrabel@citrix.com>,
Joerg Roedel <joro@8bytes.org>, Gleb Natapov <gleb@kernel.org>,
Paolo Bonzini <pbonzini@redhat.com>,
kvm@vger.kernel.org, x86@kernel.org,
linux-kernel@vger.kernel.org, Andy Lutomirski <luto@kernel.org>,
Brian Gerst <brgerst@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Borislav Petkov <bp@alien8.de>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Linus Torvalds <torvalds@linux-foundation.org>,
Andrew Morton <akpm@linux-foundation.org>,
Kees Cook <keescook@chromium.org>
Subject: Re: [PATCH] x86: Use entire page for the per-cpu GDT only if paravirt-enabled
Date: Tue, 29 Sep 2015 11:01:12 +0200 [thread overview]
Message-ID: <20150929090112.GA1400@gmail.com> (raw)
In-Reply-To: <56093657.8070409@redhat.com>
* Denys Vlasenko <dvlasenk@redhat.com> wrote:
> On 09/28/2015 09:58 AM, Ingo Molnar wrote:
> >
> > * Denys Vlasenko <dvlasenk@redhat.com> wrote:
> >
> >> On 09/26/2015 09:50 PM, H. Peter Anvin wrote:
> >>> NAK. We really should map the GDT read-only on all 64 bit systems,
> >>> since we can't hide the address from SLDT. Same with the IDT.
> >>
> >> Sorry, I don't understand your point.
> >
> > So the problem is that right now the SGDT instruction (which is unprivileged)
> > leaks the real address of the kernel image:
> >
> > fomalhaut:~> ./sgdt
> > SGDT: ffff88303fd89000 / 007f
> >
> > that 'ffff88303fd89000' is a kernel address.
>
> Thank you.
> I do know that SGDT and friends are unprivileged on x86
> and thus they allow userspace (and guest kernels in paravirt)
> learn things they don't need to know.
>
> I don't see how making GDT page-aligned and page-sized
> changes anything in this regard. SGDT will still work,
> and still leak GDT address.
Well, as I try to explain it in the other part of my mail, doing so enables us to
remap the GDT to a less security sensitive virtual address that does not leak the
kernel's randomized address:
> > Your observation in the changelog and your patch:
> >
> >>>> It is page-sized because of paravirt. [...]
> >
> > ... conflicts with the intention to mark (remap) the primary GDT address read-only
> > on native kernels as well.
> >
> > So what we should do instead is to use the page alignment properly and remap the
> > GDT to a read-only location, and load that one.
>
> If we'd have a small GDT (i.e. what my patch does), we still can remap the
> entire page which contains small GDT, and simply don't care that some other data
> is also visible through that RO page.
That's generally considered fragile: suppose an attacker has a limited information
leak that can read absolute addresses with system privilege but he doesn't know
the kernel's randomized base offset. With a 'partial page' mapping there could be
function pointers near the GDT, part of the page the GDT happens to be on, that
leak this information.
(Same goes for crypto keys or other critical information (like canary information,
salts, etc.) accidentally ending up nearby.)
Arguably it's a bit tenuous, but when playing remapping games it's generally
considered good to be page aligned and page sized, with zero padding.
> > This would have a couple of advantages:
> >
> > - This would give kernel address randomization more teeth on x86.
> >
> > - An additional advantage would be that rootkits overwriting the GDT would have
> > a bit more work to do.
> >
> > - A third advantage would be that for NUMA systems we could 'mirror' the GDT into
> > node-local memory and load those. This makes GDT load cache-misses a bit less
> > expensive.
>
> GDT is per-cpu. Isn't per-cpu memory already NUMA-local?
Indeed it is:
fomalhaut:~> for ((cpu=1; cpu<9; cpu++)); do taskset $cpu ./sgdt ; done
SGDT: ffff88103fa09000 / 007f
SGDT: ffff88103fa29000 / 007f
SGDT: ffff88103fa29000 / 007f
SGDT: ffff88103fa49000 / 007f
SGDT: ffff88103fa49000 / 007f
SGDT: ffff88103fa49000 / 007f
SGDT: ffff88103fa29000 / 007f
SGDT: ffff88103fa69000 / 007f
I confused it with the IDT, which is still global.
This also means that the GDT in itself does not leak kernel addresses at the
moment, except it leaks the layout of the percpu area.
So my suggestion would be to:
- make the GDT unconditionally page aligned and sized, then remap it to a
read-only address unconditionally as well, like we do it for the IDT.
- make the IDT per CPU as well, for performance reasons.
Thanks,
Ingo
next prev parent reply other threads:[~2015-09-29 9:01 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-26 18:00 [PATCH] x86: Use entire page for the per-cpu GDT only if paravirt-enabled Denys Vlasenko
2015-09-26 19:50 ` H. Peter Anvin
2015-09-26 20:38 ` Denys Vlasenko
2015-09-28 7:58 ` Ingo Molnar
2015-09-28 12:45 ` Denys Vlasenko
2015-09-29 9:01 ` Ingo Molnar [this message]
2015-09-29 17:35 ` Andy Lutomirski
2015-09-29 17:50 ` Linus Torvalds
2015-09-29 18:02 ` Andy Lutomirski
2015-09-29 20:30 ` H. Peter Anvin
2015-09-30 1:20 ` Eric W. Biederman
2015-09-30 1:31 ` H. Peter Anvin
2015-09-30 2:11 ` Eric W. Biederman
2015-09-30 2:26 ` H. Peter Anvin
2015-09-29 18:18 ` H. Peter Anvin
2015-09-29 18:22 ` Andy Lutomirski
2015-09-29 18:27 ` H. Peter Anvin
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=20150929090112.GA1400@gmail.com \
--to=mingo@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=akpm@linux-foundation.org \
--cc=boris.ostrovsky@oracle.com \
--cc=bp@alien8.de \
--cc=brgerst@gmail.com \
--cc=david.vrabel@citrix.com \
--cc=dvlasenk@redhat.com \
--cc=gleb@kernel.org \
--cc=hpa@zytor.com \
--cc=joro@8bytes.org \
--cc=keescook@chromium.org \
--cc=konrad.wilk@oracle.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=pbonzini@redhat.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--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;
as well as URLs for NNTP newsgroup(s).