Re: [PATCH 1/2] exec: randomize the argument block's offset within its page

From: Rik van Riel

Date: Tue Dec 01 2026 - 20:43:18 EST


On Fri, 2026-10-23 at 03:54 +0200, Brian Witte wrote:
> bprm->p starts one word below STACK_TOP_MAX, and setup_arg_pages()
> moves the stack only by whole pages, so the argv, envp and execfn
> strings sit at the same offset within their page on every exec. Three
> execs on x86_64 put argv[0] at 0x7ffeee30af9f, 0x7ffdf3709f9f and
> 0x7ffc871e0f9f.
>
> Lower bprm->p by a random amount under a page before the strings are
> copied: about 12 bits of entropy with 4K pages and 16 with 64K.
> bprm->argmin is derived from bprm->p, so the argument size limit is
> unchanged, but up to a page of RLIMIT_STACK is used.
>
> ADDR_NO_RANDOMIZE disables the offset; PF_RANDOMIZE cannot be used,
> since load_elf_binary() sets it after the strings are copied.
> PER_CLEAR_ON_SETID also clears the flag for set-id execs only after
> the
> copy, and moving the strings then would mean copying them all. So
> bprm_fill_uid()'s set-id checks are repeated early, without its
>
I still had to do a little git archeology to
figure out exactly why that test is that way
in bprm_fill_uid(), but a little digging made
it all clear!

>
> Suggested-by: Daniel Micay <danielmicay@xxxxxxxxx>
> Link: https://github.com/KSPP/linux/issues/283
> Signed-off-by: Brian Witte <brianwitte@xxxxxxxxxxxxx>

Reviewed-by: Rik van Riel <riel@xxxxxxxxxxx>

--
All Rights Reversed.