Re: [RFC][PATCH] Randomize kernel base address on boot

H. Peter Anvin
2011-05-25T16:25:15Z

On 05/25/2011 09:15 AM, Dan Rosenberg wrote:
>
> Ok, checking the e820 memory map seems like the way to go then. As a
> first attempt, I'd assume that if I find a contiguous free chunk that
> begins before (or at) 16 MB and continues beyond 16 MB, then that
> represents space where it's safe to load the kernel (up to a certain
> point before the end of that chunk), assuming the chunk has enough space
> and I do some degree of checking that I'm not decompressing on top of
> something else (I'll start to gather a list of what to watch out for).
> Is this a fair assumption?
>

There is already code that calculates exactly how much space is needed,
so that part is good -- you should have a tight bound available to you.

The important and messy part, though, is that you get the "raw" e820 map
at that point (including not even having had the e801 and 88 fallback
information merged into it.) This information has to be sanitized (to
deal with overlaps and broken-up chunks) and reserved areas merged in.
This is done in the kernel proper, and bootloaders have some equivalent
code, but you don't have it in that particular boot stage.

>
> Do you have any alternatives that allow maintaining compatibility while
> giving us finer-grained alignment? It seems it should be possible,
> since alignment was lower than 16 MB for years before this change was
> introduced...
>

Basically, you end up having to have a "real alignment" that is internal
to the kernel. We already expose a "minimum alignment" field in the
header (the legacy field is now "recommended alignment"); however, the
"minimum alignment" is really too aggressive.

Since this can be buried in the kernel itself the key is to not change
the existing header fields.

--
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel. I don't speak on their behalf.