* [PATCH 0/2] sparc64: Randomize mmap base and PIE executables
@ 2026-10-17 10:04 Stian Halseth
2026-10-17 10:04 ` [PATCH 1/2] sparc64: Start bottom-up mmap searches at mm->mmap_base Stian Halseth
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Stian Halseth @ 2026-10-17 10:04 UTC (permalink / raw)
To: Andreas Larsson, David S . Miller
Cc: Kees Cook, Michel Lespinasse, sparclinux, linux-mm, linux-kernel,
Stian Halseth
On sparc64 a 64-bit process gets little address space randomization:
the stack moves, but shared libraries, anonymous mappings, PIE
executables and the brk heap land at the same address on every run.
Patch 1 makes arch_get_unmapped_area() start at the randomized
mm->mmap_base again, which it has ignored since v3.8. Patch 2 selects
ARCH_HAS_ELF_RANDOMIZE so that PIE executables and brk are randomized
as on other architectures.
Found while adding PIE support to the sparc64 Go port:
https://github.com/sparclinux/issues/issues/119
Tested on a T4-1 and a T7-1 (sun4v) and a V240 (sun4u), with 64-bit and
32-bit userland. With the series the program image, brk, shared
libraries and mmap base move between runs, and with
randomize_va_space=0 or setarch -R the layout is the same as before.
The exec and mm selftests, glibc's elf and nptl tests, the Python test
suite and a kernel build give the same results with and without the
series.
Stian Halseth (2):
sparc64: Start bottom-up mmap searches at mm->mmap_base
sparc64: Randomize the load address of PIE executables
.../features/vm/ELF-ASLR/arch-support.txt | 2 +-
arch/sparc/Kconfig | 1 +
arch/sparc/kernel/sys_sparc_64.c | 18 ++++++++++++++----
3 files changed, 16 insertions(+), 5 deletions(-)
base-commit: 24a19b953e2a3d0ea5a8c4951a0ab8f32720c907
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] sparc64: Start bottom-up mmap searches at mm->mmap_base
2026-10-17 10:04 [PATCH 0/2] sparc64: Randomize mmap base and PIE executables Stian Halseth
@ 2026-10-17 10:04 ` Stian Halseth
2026-10-17 10:04 ` [PATCH 2/2] sparc64: Randomize the load address of PIE executables Stian Halseth
2026-10-17 14:40 ` [PATCH 0/2] sparc64: Randomize mmap base and " Jan Engelhardt
2 siblings, 0 replies; 4+ messages in thread
From: Stian Halseth @ 2026-10-17 10:04 UTC (permalink / raw)
To: Andreas Larsson, David S . Miller
Cc: Kees Cook, Michel Lespinasse, sparclinux, linux-mm, linux-kernel,
Stian Halseth, stable
arch_pick_mmap_layout() randomizes mm->mmap_base for the bottom-up
layout, which every 64-bit task uses, but arch_get_unmapped_area()
starts its search at TASK_UNMAPPED_BASE and never looks at it. Shared
libraries and anonymous mappings of 64-bit tasks therefore land at the
same address on every run; only the stack is randomized.
Before the conversion to vm_unmapped_area() the search started at
mm->free_area_cache, which binfmt_elf set to mm->mmap_base. Use
mm->mmap_base as the low limit again, as generic_get_unmapped_area()
does.
Fixes: bb64f55019c7 ("mm: use vm_unmapped_area() on sparc64 architecture")
Link: https://github.com/sparclinux/issues/issues/119
Cc: stable@vger.kernel.org
Signed-off-by: Stian Halseth <stian@itx.no>
---
arch/sparc/kernel/sys_sparc_64.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
index ecefcffcf7b10..087595fa43081 100644
--- a/arch/sparc/kernel/sys_sparc_64.c
+++ b/arch/sparc/kernel/sys_sparc_64.c
@@ -142,7 +142,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
}
info.length = len;
- info.low_limit = TASK_UNMAPPED_BASE;
+ info.low_limit = mm->mmap_base;
info.high_limit = min(task_size, VA_EXCLUDE_START);
info.align_mask = get_align_mask(filp, flags);
if (!file_hugepage)
@@ -151,7 +151,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
VM_BUG_ON(addr != -ENOMEM);
- info.low_limit = VA_EXCLUDE_END;
+ info.low_limit = max(mm->mmap_base, VA_EXCLUDE_END);
info.high_limit = task_size;
addr = vm_unmapped_area(&info);
}
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] sparc64: Randomize the load address of PIE executables
2026-10-17 10:04 [PATCH 0/2] sparc64: Randomize mmap base and PIE executables Stian Halseth
2026-10-17 10:04 ` [PATCH 1/2] sparc64: Start bottom-up mmap searches at mm->mmap_base Stian Halseth
@ 2026-10-17 10:04 ` Stian Halseth
2026-10-17 14:40 ` [PATCH 0/2] sparc64: Randomize mmap base and " Jan Engelhardt
2 siblings, 0 replies; 4+ messages in thread
From: Stian Halseth @ 2026-10-17 10:04 UTC (permalink / raw)
To: Andreas Larsson, David S . Miller
Cc: Kees Cook, Michel Lespinasse, sparclinux, linux-mm, linux-kernel,
Stian Halseth
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
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] sparc64: Randomize mmap base and PIE executables
2026-10-17 10:04 [PATCH 0/2] sparc64: Randomize mmap base and PIE executables Stian Halseth
2026-10-17 10:04 ` [PATCH 1/2] sparc64: Start bottom-up mmap searches at mm->mmap_base Stian Halseth
2026-10-17 10:04 ` [PATCH 2/2] sparc64: Randomize the load address of PIE executables Stian Halseth
@ 2026-10-17 14:40 ` Jan Engelhardt
2 siblings, 0 replies; 4+ messages in thread
From: Jan Engelhardt @ 2026-10-17 14:40 UTC (permalink / raw)
To: Stian Halseth
Cc: Andreas Larsson, David S . Miller, Kees Cook, Michel Lespinasse,
sparclinux, linux-mm, linux-kernel
On Saturday 2026-10-17 12:04, Stian Halseth wrote:
>On sparc64 a 64-bit process gets little address space randomization:
>the stack moves, but shared libraries, anonymous mappings, PIE
>executables and the brk heap land at the same address on every run.
>Tested on a T4-1 and a T7-1 (sun4v) and a V240 (sun4u), with 64-bit and
I too gave this a spin, on T5240 with a Linux 7.2.11 base and
Debian's LP64 userland.
Tested-by: Jan Engelhardt <jengelh@inai.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-10-17 14:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-17 10:04 [PATCH 0/2] sparc64: Randomize mmap base and PIE executables Stian Halseth
2026-10-17 10:04 ` [PATCH 1/2] sparc64: Start bottom-up mmap searches at mm->mmap_base Stian Halseth
2026-10-17 10:04 ` [PATCH 2/2] sparc64: Randomize the load address of PIE executables Stian Halseth
2026-10-17 14:40 ` [PATCH 0/2] sparc64: Randomize mmap base and " Jan Engelhardt
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®