Subject: Re: [PATCH net] net: filter: x86: fix JIT address randomization

From: "H. Peter Anvin" <[email-masked]>
Date: Tue, 13 May 2014 14:28:55 -0700

On 05/13/2014 01:34 PM, Alexei Starovoitov wrote:
>>
>> The argument of not having code ending on (or being very close of) page
>> boundary seems orthogonal to this bug fix.
> 
> Gotta pick some number... page/2 seems good enough to have
> large range for prandom() to choose and better performance.
> Another alternative is to do min(…, PAGE_SIZE - sizeof(*header)),
> but that is harder to understand.
> 

The latter is correct by construction, and thus doesn't end up with the
question "what is going on here" or has hidden failure conditions.

> Also just realized that I miscalculated the breaking point:
> "If prandom_u32() % hole selects a number >= 4096, then kernel will crash"
> it should read: "… >= 4092 ..."
> since sizeof(*header) needs to be accounted for.

No, it should read PAGE_SIZE - sizeof(*header) if anything.

	-hpa