From: Borislav Petkov <bp@amd64.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Borislav Petkov <bp@amd64.org>, "H. Peter Anvin" <hpa@zytor.com>,
Ingo Molnar <mingo@elte.hu>, Thomas Gleixner <tglx@linutronix.de>,
LKML <linux-kernel@vger.kernel.org>,
"Przywara, Andre" <Andre.Przywara@amd.com>,
"Pohlack, Martin" <Martin.Pohlack@amd.com>
Subject: Re: [PATCH] x86, AMD: Correct F15h IC aliasing issue
Date: Sun, 24 Jul 2011 19:22:22 +0200 [thread overview]
Message-ID: <20110724172222.GB12621@aftab> (raw)
In-Reply-To: <CA+55aFwL9Fwd9ouX3UMOayoBsZyZzTdDSySa6nZJxbpyLifbaQ@mail.gmail.com>
Hi Linus,
On Sun, Jul 24, 2011 at 12:04:27PM -0400, Linus Torvalds wrote:
> Argh. This is a small disaster, you know that, right? Suddenly we have
> user-visible allocation changes depending on which CPU you are running
> on. I just hope that the address-space randomization has caught all
> the code that depended on specific layouts.
>
> And even with ASLR, I wouldn't be surprised if there are binaries out
> there that "know" that they get dense virtual memory when they do
> back-to-back allocations, even when they don't pass in the address
> explicitly.
That's what I'm afraid of. Thus the boot option to disable it, I'm
afraid the patch won't be of help in such situations.
> How much testing has AMD done with this change and various legacy
> Linux distros?
Currently underway. Just to make sure: this change currently addresses
only the case with 32-bit binaries running on a 64-bit kernel and not
the 32-bit kernel case.
> The 32-bit case in particular makes me nervous, that's where I'd
> expect a higher likelihood of binaries that depend on the layout.
Ok, noted.
> You guys do realize that we had to disable ASLR on many machines?
Disabling ASLR is actually ok because it also fixes the aliasing issue
in 99% of the cases by keeping the VA slice [14:12] the same across
processes.
Btw, one of the joke-fixes floating around here was to disable ASLR
completely as on Transmeta:
<arch/x86/kernel/cpu/transmeta.c:92>
#ifdef CONFIG_SYSCTL
/*
* randomize_va_space slows us down enormously;
* it probably triggers retranslation of x86->native bytecode
*/
randomize_va_space = 0;
#endif
> So at a MINIMUM, I would say that this is acceptable only when the
> process doing the allocation hasn't got ASLR disabled.
I guess I could look at randomize_va_space before enabling it.
But this won't address the case where one of the processes was created
with ASLR off and the other with ASLR on and they map the same library
at VAs differing at bits [14:12].
> On Fri, Jul 22, 2011 at 6:15 AM, Borislav Petkov <bp@amd64.org> wrote:
> > +static inline unsigned long unalias_addr(unsigned long addr, bool incr)
> > +{
> > + /* handle both 32- and 64-bit with a single conditional */
> > + if (!(unalias_va_addr & (2 - mmap_is_ia32())))
> > + return addr;
>
> Ugh. I guess it works, but the actual values you used did not have a
> comment about those particular values being magical. You should do
> that, otherwise somebody will start adding bits and moving things
> around, and breaking this "bits 2/1" logic.
Good point, will do.
> > + /* check if [14:12] are already cleared */
> > + if (!(addr & (0x7 << PAGE_SHIFT)))
> > + return addr;
> > +
> > + addr = addr & ~(0x7 << PAGE_SHIFT);
> > + if (incr)
> > + addr += (0x8 << PAGE_SHIFT);
>
> This is just really hard to look at. First you talk about "bits
> 14:12", and then you use odd values like "8 << PAGE_SHIFT".
>
> Yes, yes, I can do the math in my head, and say "8 is 1<<3, and
> PAGE_SHIFT is 12, so he's adding things up to the next bit 15".
>
> But is that really sensible?
>
> If we don't already have helpers for this, it would still be prettier
> with something like
>
> #define BIT(a) (1ul << (a))
> #define BITS(a,b) (BIT((a)+1) - BIT(b))
>
> and then that "0x7 << PAGE_SHIFT" ends up being BITS(14,12) like in
> the comment (you should really double-check that I got it right
> though).
Yeah, I like the BITS() thing - will change. I actually have a similar
macro GENMASK(o, hi) in <drivers/edac/amd64_edac.h> - I should move it
to <linux/bitops.h> and rename it to BITS().
> Or alternatively, make the comment match the code, and explain the
> 14:12 with something like "the three bits above the page mask",
> although that just sounds odd.
>
> Anyway, I seriously think that this patch is completely unacceptable
> in this form, and is quite possibly going to break real applications.
> Maybe most of the applications that had problems with ASLR only had
> trouble with anonymous memory, and the fact that you only do this for
> file mappings might mean that it's ok. But I'd be really worried.
> Changing address space layout is not a small decision.
I suspected as much - thus the boot option to disable it. We'll do our
extensive testing as good as we can and we'll keep our fingers crossed.
Big thanks for your review.
--
Regards/Gruss,
Boris.
Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
GM: Alberto Bozzo
Reg: Dornach, Landkreis Muenchen
HRB Nr. 43632 WEEE Registernr: 129 19551
next prev parent reply other threads:[~2011-07-24 17:22 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-22 13:15 [PATCH] x86, AMD: Correct F15h IC aliasing issue Borislav Petkov
2011-07-24 11:13 ` Ingo Molnar
2011-07-24 13:40 ` Borislav Petkov
2011-07-24 13:47 ` Ingo Molnar
2011-07-24 16:16 ` Andrew Morton
2011-07-26 18:33 ` Borislav Petkov
2011-07-24 16:04 ` Linus Torvalds
2011-07-24 17:22 ` Borislav Petkov [this message]
2011-07-24 17:39 ` Linus Torvalds
2011-07-24 18:12 ` Ingo Molnar
2011-07-24 18:23 ` Borislav Petkov
2011-07-24 18:30 ` Ingo Molnar
2011-07-24 19:07 ` Borislav Petkov
2011-07-24 20:44 ` Ingo Molnar
2011-07-25 20:00 ` Borislav Petkov
2011-07-25 20:06 ` Ingo Molnar
2011-07-25 21:53 ` Borislav Petkov
2011-07-26 5:58 ` Ray Lee
2011-07-26 17:28 ` Borislav Petkov
2011-07-26 18:34 ` Ingo Molnar
2011-07-26 18:39 ` Borislav Petkov
2011-07-26 18:47 ` Ingo Molnar
2011-07-26 19:33 ` Borislav Petkov
2011-07-27 17:10 ` Borislav Petkov
2011-07-27 17:16 ` H. Peter Anvin
2011-07-28 13:44 ` Borislav Petkov
2011-07-28 14:02 ` H. Peter Anvin
2011-07-28 14:13 ` Borislav Petkov
2011-07-28 14:18 ` H. Peter Anvin
2011-07-28 14:35 ` Borislav Petkov
2011-07-26 17:59 ` Avi Kivity
2011-07-26 18:13 ` Borislav Petkov
2011-07-26 18:16 ` H. Peter Anvin
2011-07-26 18:37 ` Borislav Petkov
2011-07-26 18:38 ` H. Peter Anvin
2011-07-26 19:42 ` Andre Przywara
2011-07-26 22:34 ` H. Peter Anvin
2011-07-27 4:14 ` Avi Kivity
2011-07-27 6:21 ` Borislav Petkov
2011-07-27 6:59 ` Ingo Molnar
2011-07-27 9:30 ` Avi Kivity
2011-07-27 15:37 ` Borislav Petkov
2011-07-27 15:45 ` Avi Kivity
2011-07-27 15:49 ` Borislav Petkov
2011-07-27 15:57 ` Avi Kivity
2011-07-27 16:42 ` Borislav Petkov
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=20110724172222.GB12621@aftab \
--to=bp@amd64.org \
--cc=Andre.Przywara@amd.com \
--cc=Martin.Pohlack@amd.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.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.