From: Stian Halseth <stian@itx.no>
To: Andreas Larsson <andreas@gaisler.com>,
"David S . Miller" <davem@davemloft.net>
Cc: Kees Cook <kees@kernel.org>,
Michel Lespinasse <michel@lespinasse.org>,
Jan Engelhardt <jengelh@inai.de>,
sparclinux@vger.kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, Stian Halseth <stian@itx.no>
Subject: [PATCH v2 3/3] sparc64: Randomize the load address of PIE executables
Date: Sun, 18 Oct 2026 14:27:34 +0200 [thread overview]
Message-ID: <20261018122734.2594904-4-stian@itx.no> (raw)
In-Reply-To: <20261018122734.2594904-1-stian@itx.no>
On sparc64 every PIE executable (ET_DYN with PT_INTERP) is loaded at
exactly ELF_ET_DYN_BASE, with its brk heap at a fixed offset after it.
The stack and the mmap base are randomized; the program image and brk
are not.
load_elf_binary() adds arch_mmap_rnd() to the load bias and calls
arch_randomize_brk(), but without ARCH_HAS_ELF_RANDOMIZE both are
no-ops. sparc64 already has a suitable mmap_rnd() for the mmap base.
Rename it to arch_mmap_rnd(), add arch_randomize_brk() with the ranges
x86 and the generic version use, and select ARCH_HAS_ELF_RANDOMIZE.
Closes: https://github.com/sparclinux/issues/issues/119
Tested-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Stian Halseth <stian@itx.no>
---
.../features/vm/ELF-ASLR/arch-support.txt | 2 +-
arch/sparc/Kconfig | 1 +
arch/sparc/kernel/sys_sparc_64.c | 14 ++++++++++++--
3 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/Documentation/features/vm/ELF-ASLR/arch-support.txt b/Documentation/features/vm/ELF-ASLR/arch-support.txt
index 57406c0d53531..d4a34c9fbae86 100644
--- a/Documentation/features/vm/ELF-ASLR/arch-support.txt
+++ b/Documentation/features/vm/ELF-ASLR/arch-support.txt
@@ -24,7 +24,7 @@
| riscv: | ok |
| s390: | ok |
| sh: | TODO |
- | sparc: | TODO |
+ | sparc: | ok |
| um: | TODO |
| x86: | ok |
| xtensa: | TODO |
diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
index ab77d3f2536e1..82c989b9e7831 100644
--- a/arch/sparc/Kconfig
+++ b/arch/sparc/Kconfig
@@ -71,6 +71,7 @@ config SPARC64
def_bool 64BIT
select ALTERNATE_USER_ADDRESS_SPACE
select ARCH_HAS_DELAY_TIMER
+ select ARCH_HAS_ELF_RANDOMIZE
select HAVE_FUNCTION_TRACER
select HAVE_FUNCTION_GRAPH_TRACER
select HAVE_KRETPROBES
diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
index 087595fa43081..2948d5769e768 100644
--- a/arch/sparc/kernel/sys_sparc_64.c
+++ b/arch/sparc/kernel/sys_sparc_64.c
@@ -26,6 +26,8 @@
#include <linux/ipc.h>
#include <linux/personality.h>
#include <linux/random.h>
+#include <linux/elf-randomize.h>
+#include <linux/sizes.h>
#include <linux/export.h>
#include <linux/context_tracking.h>
#include <linux/timex.h>
@@ -280,7 +282,7 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
EXPORT_SYMBOL(get_fb_unmapped_area);
/* Essentially the same as PowerPC. */
-static unsigned long mmap_rnd(void)
+unsigned long arch_mmap_rnd(void)
{
unsigned long rnd = 0UL;
@@ -294,9 +296,17 @@ static unsigned long mmap_rnd(void)
return rnd << PAGE_SHIFT;
}
+unsigned long arch_randomize_brk(struct mm_struct *mm)
+{
+ if (test_thread_flag(TIF_32BIT))
+ return randomize_page(mm->brk, SZ_32M);
+
+ return randomize_page(mm->brk, SZ_1G);
+}
+
void arch_pick_mmap_layout(struct mm_struct *mm, const struct rlimit *rlim_stack)
{
- unsigned long random_factor = mmap_rnd();
+ unsigned long random_factor = arch_mmap_rnd();
unsigned long gap;
/*
--
2.43.0
next prev parent reply other threads:[~2026-10-18 12:27 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-18 12:27 [PATCH v2 0/3] sparc64: Randomize mmap base and " Stian Halseth
2026-10-18 12:27 ` [PATCH v2 1/3] sparc64: Start bottom-up mmap searches at mm->mmap_base Stian Halseth
2026-10-18 12:27 ` [PATCH v2 2/3] sparc64: Move the 32-bit PIE base below the legacy mmap base Stian Halseth
2026-10-18 12:27 ` Stian Halseth [this message]
2026-10-18 13:09 ` [PATCH v2 0/3] sparc64: Randomize mmap base and PIE executables John Paul Adrian Glaubitz
2026-10-18 13:33 ` Stian Halseth
2026-10-18 13:38 ` Stian Halseth
2026-10-18 20:37 ` Magnus Lindholm
2026-10-18 21:08 ` Stian Halseth
2026-10-18 21:12 ` Magnus Lindholm
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=20261018122734.2594904-4-stian@itx.no \
--to=stian@itx.no \
--cc=andreas@gaisler.com \
--cc=davem@davemloft.net \
--cc=jengelh@inai.de \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=michel@lespinasse.org \
--cc=sparclinux@vger.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
all inboxes | Powered by JetHome®