From: "Borys Popławski" <poplawski.borys@gmail.com>
To: luto@kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: VDSO is randomized even when ASLR is disabled
Date: Tue, 1 Feb 2022 18:14:19 +0100 [thread overview]
Message-ID: <9b82908f-eed1-b6b7-62aa-ecbba7bf048b@gmail.com> (raw)
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
next reply other threads:[~2022-02-01 17:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-01 17:14 Borys Popławski [this message]
2022-03-09 12:42 ` VDSO is randomized even when ASLR is disabled Borys Popławski
2022-03-16 15:58 ` Dave Hansen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9b82908f-eed1-b6b7-62aa-ecbba7bf048b@gmail.com \
--to=poplawski.borys@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox