Re: [PATCH v5] mm: Optional full ASLR for mmap(), mremap(), vdso and stack

Andy Lutomirski
2020-12-03T17:43:39Z

> On Dec 3, 2020, at 9:29 AM, Florian Weimer <fweimer@redhat.com> wrote:
>
> ﻿* Andy Lutomirski:
>
>> If you want a 4GB allocation to succeed, you can only divide the
>> address space into 32k fragments. Or, a little more precisely, if you
>> want a randomly selected 4GB region to be empty, any other allocation
>> has a 1/32k chance of being in the way. (Rough numbers — I’m ignoring
>> effects of the beginning and end of the address space, and I’m
>> ignoring the size of a potential conflicting allocation.).
>
> I think the probability distribution is way more advantageous than that
> because it is unlikely that 32K allocations are all exactly spaced 4 GB
> apart. (And with 32K allocations, you are close to the VMA limit anyway.)

I’m assuming the naive algorithm of choosing an address and trying it. Actually looking for a big enough gap would be more reliable.

I suspect that something much more clever could be done in which the heap is divided up into a few independently randomized sections and heap pages are randomized within the sections might do much better. There should certainly be a lot of room for something between what we have now and a fully randomized scheme.

It might also be worth looking at what other OSes do.