linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* VDSO is randomized even when ASLR is disabled
@ 2022-02-01 17:14 Borys Popławski
  2022-03-09 12:42 ` Borys Popławski
  0 siblings, 1 reply; 3+ messages in thread
From: Borys Popławski @ 2022-02-01 17:14 UTC (permalink / raw)
  To: luto; +Cc: linux-kernel

Hello,
I've stumbled upon an issue of VDSO address being randomized on x86_64 when ASLR is disabled. This happens only on systems with 5-level paging enabled. Details below.

Relevant code: "vdso_addr" in arch/x86/entry/vdso/vma.c
VDSO base address is picked at random starting from the stack bottom address so that it stays in the same PMD as the stack. This randomization is made regardless of PF_RANDOMIZE flag.
With ASLR off, stack is mapped at the highest possible address in 4-level paging, which is 0x7ffffffff000 - this leaves no space for VDSO after the stack, which effectively disables the above randomization. With 5-level paging the stack address stays the same, but "TASK_SIZE_MAX" is much greater, allowing for the above randomization.

This behavior is present in all versions (since VDSO was introduced on x64). I think the fix could be as simple as:

diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c
index 235a5794296a..0bc83e4ca512 100644
--- a/arch/x86/entry/vdso/vma.c
+++ b/arch/x86/entry/vdso/vma.c
@@ -326,7 +326,7 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
                end = TASK_SIZE_MAX;
        end -= len;
 
-       if (end > start) {
+       if (end > start && (current->flags & PF_RANDOMIZE)) {
                offset = get_random_int() % (((end - start) >> PAGE_SHIFT) + 1);
                addr = start + (offset << PAGE_SHIFT);
        } else {

but I've not tested it yet, figured I'll post here first.

Best regards,
Borys

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: VDSO is randomized even when ASLR is disabled
  2022-02-01 17:14 VDSO is randomized even when ASLR is disabled Borys Popławski
@ 2022-03-09 12:42 ` Borys Popławski
  2022-03-16 15:58   ` Dave Hansen
  0 siblings, 1 reply; 3+ messages in thread
From: Borys Popławski @ 2022-03-09 12:42 UTC (permalink / raw)
  To: luto; +Cc: linux-kernel

Hello,
I would like to get some feedback on this issue. Would such fix be accepted? Should I send a patch?

Best regards,
Borys

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: VDSO is randomized even when ASLR is disabled
  2022-03-09 12:42 ` Borys Popławski
@ 2022-03-16 15:58   ` Dave Hansen
  0 siblings, 0 replies; 3+ messages in thread
From: Dave Hansen @ 2022-03-16 15:58 UTC (permalink / raw)
  To: Borys Popławski, luto; +Cc: linux-kernel

On 3/9/22 04:42, Borys Popławski wrote:
> I would like to get some feedback on this issue. Would such fix be
> accepted? Should I send a patch?

The best way to get feedback is to submit a real patch following all the
rules in our documentation.  Cc'ing all the maintainers of the code and
testing your fix would be two great places to start.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-03-16 16:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-01 17:14 VDSO is randomized even when ASLR is disabled Borys Popławski
2022-03-09 12:42 ` Borys Popławski
2022-03-16 15:58   ` Dave Hansen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).