From: Audra Mitchell <audra@redhat.com>
To: linux-mm@kvack.org
Cc: audra@redhat.com, raquini@redhat.com, aris@redhat.com,
akpm@linux-foundation.org, willy@infradead.org,
william.kucharski@oracle.com, linux-kernel@vger.kernel.org
Subject: [PATCH] mm: Stop PMD alignment for PIE shared objects
Date: Thu, 19 Dec 2024 16:15:52 -0500 [thread overview]
Message-ID: <20241219211552.1450226-1-audra@redhat.com> (raw)
After commit 1854bc6e2420 ("mm/readahead: Align file mappings for non-DAX")
any request through thp_get_unmapped_area would align to a PMD_SIZE,
causing shared objects to have less randomization than previously (9 less
bits for 2MB PMDs). As these lower 9 bits are the most impactful for
ASLR, this change could be argued to have an impact on security.
Running the pie-so program [1] multiple times we can see the randomization
loss as the lower address bits get aligned to a 2MB size on x86 (pie-so):
# ./all-gather && ./all-bits
---------[SNIP]---------
aslr heap 19 bits
aslr exec 00 bits
aslr mmap 29 bits
aslr so 00 bits
aslr stack 31 bits
aslr pie-exec 30 bits
aslr pie-heap 30 bits
aslr pie-so 20 bits
aslr pie-mmap 29 bits
aslr pie-stack 30 bits
Fix this issue by checking that the request is aligned to the PMD_SIZE,
otherwise fall back to mm_get_unmapped_area_vmflags().
[1] https://github.com/stevegrubb/distro-elf-inspector
Fixes: 1854bc6e2420 ("mm/readahead: Align file mappings for non-DAX")
Signed-off-by: Audra Mitchell <audra@redhat.com>
---
mm/huge_memory.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index ee335d96fc39..696caf6cbf4a 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -1101,6 +1101,9 @@ static unsigned long __thp_get_unmapped_area(struct file *filp,
if (len_pad < len || (off + len_pad) < off)
return 0;
+ if (!IS_ALIGNED(len, PMD_SIZE))
+ return 0;
+
ret = mm_get_unmapped_area_vmflags(current->mm, filp, addr, len_pad,
off >> PAGE_SHIFT, flags, vm_flags);
--
2.45.0
next reply other threads:[~2024-12-19 21:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-19 21:15 Audra Mitchell [this message]
2024-12-19 21:30 ` Matthew Wilcox
2024-12-19 21:59 ` Audra Mitchell
2024-12-20 18:20 ` Rafael Aquini
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=20241219211552.1450226-1-audra@redhat.com \
--to=audra@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=aris@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=raquini@redhat.com \
--cc=william.kucharski@oracle.com \
--cc=willy@infradead.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
all inboxes | Powered by JetHome®