Skip to contentSkip to conversation

LoongArch: Increase default mmap randomization bits

PATCH In review Bingwu Zhang 3 participants 11 messages Mar 28 – Apr 13 LoongArch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 LoongArch: Increase default mmap randomization bits

From: Bingwu Zhang <[email protected]>

Increase default mmap randomization bits from 12 to 18 on 64-bit platforms for better strength.

The original default, 12, means that ASLR offset has only (1 << 12) = 4096 possibilities. On average, it can be brute-forced in 2048 attempts. If a service is configured to restart automatically or can be started easily (e.g. execve a suid program), then trying for 4k times can be done in one day even when each attempt takes 20s.
Increasing it to 18 makes brute-force much more difficult and leaves more time for operators to find out attacks.

On 64-bit platforms, virtual address space is cheap, so the randomization bits can be increased safely without disturbing userland much and security comes first instead of availability.

Fixes fa96b57c1490 ("LoongArch: Add build infrastructure")
---
 arch/loongarch/Kconfig | 2 ++
 1 file changed, 2 insertions(+)
arch/loongarch/Kconfig +2 -0
index 92068ff38685..b47c4e4ecbb7 100644
@@ -740,9 +740,11 @@ config MMU
 	default y
 
 config ARCH_MMAP_RND_BITS_MIN
+	default 18 if 64BIT
 	default 12
 
 config ARCH_MMAP_RND_BITS_MAX
+	default 32 if 64BIT
 	default 18
 
 config ARCH_SUPPORTS_UPROBES

base-commit: be762d8b6dd7efacb61937d20f8475db8f207655

Signature · 1 line
2.52.0
maintainer
#1 lore raw

Hi, Bingwu,

Quoted 14 lines · Bingwu Zhang

From: Bingwu Zhang <[email protected]>

Increase default mmap randomization bits from 12 to 18 on 64-bit platforms for better strength.

The original default, 12, means that ASLR offset has only (1 << 12) = 4096 possibilities. On average, it can be brute-forced in 2048 attempts. If a service is configured to restart automatically or can be started easily (e.g. execve a suid program), then trying for 4k times can be done in one day even when each attempt takes 20s.
Increasing it to 18 makes brute-force much more difficult and leaves more time for operators to find out attacks.

Quoted 3 lines

On 64-bit platforms, virtual address space is cheap, so the randomization bits can be increased safely without disturbing userland much and security comes first instead of availability.

Don't change ARCH_MMAP_RND_BITS_MIN because it may compact performance, and you cannot blindly increase ARCH_MMAP_RND_BITS_MAX because it should no more than "VA_BITS - PAGE_SHIFT - 3" (see arch/riscv/Kconfig and arch/csky/Kconfig). For LoongArch, VA_BITS can be 39 (half of VA40), PAGE_SHIFT can be 16 (64KB page), so ARCH_MMAP_RND_BITS_MAX can only increase up to 20 (39 - 16 - 3 =20).

These are done in:
https://github.com/chenhuacai/linux/commit/ff35475dcfbd4c6e9c275aaef3c92da710894058

Huacai

Quoted 28 lines
Fixes fa96b57c1490 ("LoongArch: Add build infrastructure")
---
 arch/loongarch/Kconfig | 2 ++
 1 file changed, 2 insertions(+)
arch/loongarch/Kconfig +2 -0
index 92068ff38685..b47c4e4ecbb7 100644
@@ -740,9 +740,11 @@ config MMU
        default y
 
 config ARCH_MMAP_RND_BITS_MIN
+       default 18 if 64BIT
        default 12
 
 config ARCH_MMAP_RND_BITS_MAX
+       default 32 if 64BIT
        default 18
 
 config ARCH_SUPPORTS_UPROBES

base-commit: be762d8b6dd7efacb61937d20f8475db8f207655 --
2.52.0

#2 lore raw
Quoted 20 lines · China Standard Time Huacai Chen

Hi, Bingwu,

Quoted 13 lines · Bingwu Zhang

From: Bingwu Zhang <[email protected]>

Increase default mmap randomization bits from 12 to 18 on 64-bit platforms for better strength.

The original default, 12, means that ASLR offset has only (1 << 12) = 4096 possibilities. On average, it can be brute-forced in 2048 attempts. If a service is configured to restart automatically or can be started easily (e.g. execve a suid program), then trying for 4k times can be done in one day even when each attempt takes 20s.
Increasing it to 18 makes brute-force much more difficult and leaves more time for operators to find out attacks.

Quoted 3 lines

On 64-bit platforms, virtual address space is cheap, so the randomization bits can be increased safely without disturbing userland much and security comes first instead of availability.

Quoted 6 lines

Don't change ARCH_MMAP_RND_BITS_MIN because it may compact performance, and you cannot blindly increase ARCH_MMAP_RND_BITS_MAX because it should no more than "VA_BITS - PAGE_SHIFT - 3" (see arch/riscv/Kconfig and arch/csky/Kconfig). For LoongArch, VA_BITS can be 39 (half of VA40), PAGE_SHIFT can be 16 (64KB page), so ARCH_MMAP_RND_BITS_MAX can only increase up to 20 (39 - 16 - 3 =20).

Sorry for the late reply.

It was my mistake that I didn't notice the upper bound of MAX. Thank you for pointing out!

However, I didn't get where increasing MIN could compact performance. Theoretically, the only difference is that the gap between heaps and stacks are larger, from [128, 128+64]M to [128, 128+4096]M. This shouldn't affect performance much. MIPS once used MIN=16, RISC-V 64 and PowerPC and ARM 64 are using 18, and x86-64 is using 28, but I hadn't heard anyone complaining about the performance.

I ran some benchmarks last weekend using the LLVM build benchmark of AOSC OS
https://github.com/AOSC-Dev/buildbot-benchmark/blob/master/buildbot-benchmark.bash
and here are the results

Processor Rand bits Time/secs
Average Variance Range
3C6000/S 18 612.927 614.394 614.513 613.343 614.76
613.9874 0.515637840000006 1.83299999999997
3C6000/S 12 614.322 613.93 614.825 613.859
615.875 614.5622 0.548874160000007 2.01599999999996
3A5000 18 3547.165 3548.764 3552.192 3545.697
3547.567 3548.277 4.79228759999993 6.49499999999989
3A5000 12 3549.029 3551.894 3549.191 3567.869
3587.409 3561.0784 222.052853440003 38.3800000000001

I didn't see any statistically meaningful performance defect.

Quoted 32 lines

These are done in:
https://github.com/chenhuacai/linux/commit/ff35475dcfbd4c6e9c275aaef3c92da71
0894058

Huacai

Quoted 25 lines
Fixes fa96b57c1490 ("LoongArch: Add build infrastructure")

---

 arch/loongarch/Kconfig | 2 ++
 1 file changed, 2 insertions(+)
arch/loongarch/Kconfig +2 -0
index 92068ff38685..b47c4e4ecbb7 100644
@@ -740,9 +740,11 @@ config MMU
 
        default y
 
 config ARCH_MMAP_RND_BITS_MIN
 
+       default 18 if 64BIT
 
        default 12
 
 config ARCH_MMAP_RND_BITS_MAX
 
+       default 32 if 64BIT
Quoted 7 lines
Quoted 7 lines

default 18

config ARCH_SUPPORTS_UPROBES

base-commit: be762d8b6dd7efacb61937d20f8475db8f207655 --
2.52.0

Best regards,

Signature · 1 line
Bingwu Zhang @ Sun, 12 Apr 2026 03:28:14 +0000
maintainer
#3 lore raw
Quoted 56 lines · Bingwu Zhang
Quoted 20 lines · China Standard Time Huacai Chen

Hi, Bingwu,

Quoted 13 lines · Bingwu Zhang

From: Bingwu Zhang <[email protected]>

Increase default mmap randomization bits from 12 to 18 on 64-bit platforms for better strength.

The original default, 12, means that ASLR offset has only (1 << 12) = 4096 possibilities. On average, it can be brute-forced in 2048 attempts. If a service is configured to restart automatically or can be started easily (e.g. execve a suid program), then trying for 4k times can be done in one day even when each attempt takes 20s.
Increasing it to 18 makes brute-force much more difficult and leaves more time for operators to find out attacks.

Quoted 3 lines

On 64-bit platforms, virtual address space is cheap, so the randomization bits can be increased safely without disturbing userland much and security comes first instead of availability.

Quoted 6 lines

Don't change ARCH_MMAP_RND_BITS_MIN because it may compact performance, and you cannot blindly increase ARCH_MMAP_RND_BITS_MAX because it should no more than "VA_BITS - PAGE_SHIFT - 3" (see arch/riscv/Kconfig and arch/csky/Kconfig). For LoongArch, VA_BITS can be 39 (half of VA40), PAGE_SHIFT can be 16 (64KB page), so ARCH_MMAP_RND_BITS_MAX can only increase up to 20 (39 - 16 - 3 =20).

Sorry for the late reply.

It was my mistake that I didn't notice the upper bound of MAX. Thank you for pointing out!

However, I didn't get where increasing MIN could compact performance. Theoretically, the only difference is that the gap between heaps and stacks are larger, from [128, 128+64]M to [128, 128+4096]M. This shouldn't affect performance much. MIPS once used MIN=16, RISC-V 64 and PowerPC and ARM 64 are using 18, and x86-64 is using 28, but I hadn't heard anyone complaining about the performance.

I ran some benchmarks last weekend using the LLVM build benchmark of AOSC OS
https://github.com/AOSC-Dev/buildbot-benchmark/blob/master/buildbot-benchmark.bash
and here are the results

Processor Rand bits Time/secs
Average Variance Range

3C6000/S        18      612.927 614.394 614.513 613.343 614.76
613.9874        0.515637840000006       1.83299999999997
3C6000/S        12      614.322 613.93  614.825 613.859
615.875 614.5622        0.548874160000007       2.01599999999996
3A5000  18      3547.165        3548.764        3552.192        3545.697
3547.567        3548.277        4.79228759999993        6.49499999999989
3A5000  12      3549.029        3551.894        3549.191        3567.869
3587.409        3561.0784       222.052853440003        38.3800000000001
Quoted 1 line

I didn't see any statistically meaningful performance defect.

OK, then we can increase ARCH_MMAP_RND_BITS_MIN, but the range 18~20 seems too small and then useless, can we consider using 15~20?

Huacai

Quoted 45 lines
Quoted 33 lines

These are done in:
https://github.com/chenhuacai/linux/commit/ff35475dcfbd4c6e9c275aaef3c92da71
0894058

Huacai

Quoted 25 lines
Fixes fa96b57c1490 ("LoongArch: Add build infrastructure")

---

 arch/loongarch/Kconfig | 2 ++
 1 file changed, 2 insertions(+)
arch/loongarch/Kconfig +2 -0
index 92068ff38685..b47c4e4ecbb7 100644
@@ -740,9 +740,11 @@ config MMU
 
        default y
 
 config ARCH_MMAP_RND_BITS_MIN
 
+       default 18 if 64BIT
 
        default 12
 
 config ARCH_MMAP_RND_BITS_MAX
 
+       default 32 if 64BIT
Quoted 7 lines
Quoted 7 lines

default 18

config ARCH_SUPPORTS_UPROBES

base-commit: be762d8b6dd7efacb61937d20f8475db8f207655 --
2.52.0

Best regards,

--
Bingwu Zhang @ Sun, 12 Apr 2026 03:28:14 +0000

#4 lore raw
Quoted 57 lines · Huacai Chen
Quoted 56 lines · Bingwu Zhang
Quoted 20 lines · China Standard Time Huacai Chen

Hi, Bingwu,

Quoted 13 lines · Bingwu Zhang

From: Bingwu Zhang <[email protected]>

Increase default mmap randomization bits from 12 to 18 on 64-bit platforms for better strength.

The original default, 12, means that ASLR offset has only (1 << 12) = 4096 possibilities. On average, it can be brute-forced in 2048 attempts. If a service is configured to restart automatically or can be started easily (e.g. execve a suid program), then trying for 4k times can be done in one day even when each attempt takes 20s.
Increasing it to 18 makes brute-force much more difficult and leaves more time for operators to find out attacks.

Quoted 3 lines

On 64-bit platforms, virtual address space is cheap, so the randomization bits can be increased safely without disturbing userland much and security comes first instead of availability.

Quoted 6 lines

Don't change ARCH_MMAP_RND_BITS_MIN because it may compact performance, and you cannot blindly increase ARCH_MMAP_RND_BITS_MAX because it should no more than "VA_BITS - PAGE_SHIFT - 3" (see arch/riscv/Kconfig and arch/csky/Kconfig). For LoongArch, VA_BITS can be 39 (half of VA40), PAGE_SHIFT can be 16 (64KB page), so ARCH_MMAP_RND_BITS_MAX can only increase up to 20 (39 - 16 - 3 =20).

Sorry for the late reply.

It was my mistake that I didn't notice the upper bound of MAX. Thank you for pointing out!

However, I didn't get where increasing MIN could compact performance. Theoretically, the only difference is that the gap between heaps and stacks are larger, from [128, 128+64]M to [128, 128+4096]M. This shouldn't affect performance much. MIPS once used MIN=16, RISC-V 64 and PowerPC and ARM 64 are using 18, and x86-64 is using 28, but I hadn't heard anyone complaining about the performance.

I ran some benchmarks last weekend using the LLVM build benchmark of AOSC OS
https://github.com/AOSC-Dev/buildbot-benchmark/blob/master/buildbot-benchmark.bash
and here are the results

Processor       Rand bits       Time/secs
Average Variance        Range
3C6000/S        18      612.927 614.394 614.513 613.343 614.76 613.9874        0.515637840000006       1.83299999999997 3C6000/S        12      614.322 613.93  614.825 613.859 615.875 614.5622        0.548874160000007       2.01599999999996 3A5000  18      3547.165        3548.764        3552.192        3545.697 3547.567        3548.277        4.79228759999993        6.49499999999989 3A5000  12      3549.029        3551.894        3549.191        3567.869 3587.409        3561.0784       222.052853440003        38.3800000000001

Quoted 3 lines
Quoted 1 line

I didn't see any statistically meaningful performance defect.

OK, then we can increase ARCH_MMAP_RND_BITS_MIN, but the range 18~20 seems too small and then useless, can we consider using 15~20?

IMO ARCH_MMAP_RND_BITS_MIN should be just the minimal that the architecture can support, not related to security. If you want to recommend a value for increasing security you'd set ARCH_MMAP_RND_BITS_DEFAULT a larger value instead.

Signature · 1 line
Xi Ruoyao <[email protected]>
maintainer
#5 lore raw
Quoted 59 lines · Xi Ruoyao
Quoted 57 lines · Huacai Chen
Quoted 56 lines · Bingwu Zhang
Quoted 20 lines · China Standard Time Huacai Chen

Hi, Bingwu,

Quoted 13 lines · Bingwu Zhang

From: Bingwu Zhang <[email protected]>

Increase default mmap randomization bits from 12 to 18 on 64-bit platforms for better strength.

The original default, 12, means that ASLR offset has only (1 << 12) = 4096 possibilities. On average, it can be brute-forced in 2048 attempts. If a service is configured to restart automatically or can be started easily (e.g. execve a suid program), then trying for 4k times can be done in one day even when each attempt takes 20s.
Increasing it to 18 makes brute-force much more difficult and leaves more time for operators to find out attacks.

Quoted 3 lines

On 64-bit platforms, virtual address space is cheap, so the randomization bits can be increased safely without disturbing userland much and security comes first instead of availability.

Quoted 6 lines

Don't change ARCH_MMAP_RND_BITS_MIN because it may compact performance, and you cannot blindly increase ARCH_MMAP_RND_BITS_MAX because it should no more than "VA_BITS - PAGE_SHIFT - 3" (see arch/riscv/Kconfig and arch/csky/Kconfig). For LoongArch, VA_BITS can be 39 (half of VA40), PAGE_SHIFT can be 16 (64KB page), so ARCH_MMAP_RND_BITS_MAX can only increase up to 20 (39 - 16 - 3 =20).

Sorry for the late reply.

It was my mistake that I didn't notice the upper bound of MAX. Thank you for pointing out!

However, I didn't get where increasing MIN could compact performance. Theoretically, the only difference is that the gap between heaps and stacks are larger, from [128, 128+64]M to [128, 128+4096]M. This shouldn't affect performance much. MIPS once used MIN=16, RISC-V 64 and PowerPC and ARM 64 are using 18, and x86-64 is using 28, but I hadn't heard anyone complaining about the performance.

I ran some benchmarks last weekend using the LLVM build benchmark of AOSC OS
https://github.com/AOSC-Dev/buildbot-benchmark/blob/master/buildbot-benchmark.bash
and here are the results

Processor Rand bits Time/secs
Average Variance Range

3C6000/S        18      612.927 614.394 614.513 613.343 614.76
613.9874        0.515637840000006       1.83299999999997
3C6000/S        12      614.322 613.93  614.825 613.859
615.875 614.5622        0.548874160000007       2.01599999999996
3A5000  18      3547.165        3548.764        3552.192        3545.697
3547.567        3548.277        4.79228759999993        6.49499999999989
3A5000  12      3549.029        3551.894        3549.191        3567.869
3587.409        3561.0784       222.052853440003        38.3800000000001
Quoted 8 lines
Quoted 3 lines
Quoted 1 line

I didn't see any statistically meaningful performance defect.

OK, then we can increase ARCH_MMAP_RND_BITS_MIN, but the range 18~20 seems too small and then useless, can we consider using 15~20?

IMO ARCH_MMAP_RND_BITS_MIN should be just the minimal that the architecture can support, not related to security. If you want to recommend a value for increasing security you'd set ARCH_MMAP_RND_BITS_DEFAULT a larger value instead.

If so, just keep 12.

Huacai

Quoted 3 lines

--
Xi Ruoyao <[email protected]>

#6 lore raw
In reply to Xi Ruoyao
Quoted 81 lines · Xi Ruoyao
Quoted 80 lines · Huacai Chen
Quoted 79 lines · Bingwu Zhang
Quoted 28 lines · China Standard Time Huacai Chen

Hi, Bingwu,

Quoted 19 lines · Bingwu Zhang

From: Bingwu Zhang <[email protected]>

Increase default mmap randomization bits from 12 to 18 on 64- bit
platforms for better strength.

The original default, 12, means that ASLR offset has only (1 << 12) =
4096 possibilities. On average, it can be brute-forced in 2048 attempts.
If a service is configured to restart automatically or can be started
easily (e.g. execve a suid program), then trying for 4k times can be
done in one day even when each attempt takes 20s. Increasing it to 18 makes brute-force much more difficult and leaves
more time for operators to find out attacks.

Quoted 4 lines

On 64-bit platforms, virtual address space is cheap, so the randomization bits can be increased safely without disturbing userland
much and security comes first instead of availability.

Quoted 9 lines

Don't change ARCH_MMAP_RND_BITS_MIN because it may compact performance, and you cannot blindly increase ARCH_MMAP_RND_BITS_MAX
because it should no more than "VA_BITS - PAGE_SHIFT - 3" (see arch/riscv/Kconfig and arch/csky/Kconfig). For LoongArch, VA_BITS can
be 39 (half of VA40), PAGE_SHIFT can be 16 (64KB page), so ARCH_MMAP_RND_BITS_MAX can only increase up to 20 (39 - 16 - 3 =20).

Sorry for the late reply.

It was my mistake that I didn't notice the upper bound of MAX. Thank you for
pointing out!

However, I didn't get where increasing MIN could compact performance.
Theoretically, the only difference is that the gap between heaps and stacks
are larger, from [128, 128+64]M to [128, 128+4096]M. This shouldn't affect
performance much. MIPS once used MIN=16, RISC-V 64 and PowerPC and ARM 64 are
using 18, and x86-64 is using 28, but I hadn't heard anyone complaining about
the performance.

I ran some benchmarks last weekend using the LLVM build benchmark of AOSC OS
https://github.com/AOSC-Dev/buildbot-benchmark/blob/master/buildbot-benchmark.bash
and here are the results

Processor       Rand bits       Time/secs
Average Variance        Range
3C6000/S        18      612.927 614.394 614.513 613.343 614.76 613.9874        0.515637840000006       1.83299999999997 3C6000/S        12      614.322 613.93  614.825 613.859 615.875 614.5622        0.548874160000007       2.01599999999996 3A5000  18      3547.165        3548.764        3552.192 3545.697
3547.567        3548.277        4.79228759999993 6.49499999999989
3A5000  12      3549.029        3551.894        3549.191 3567.869
3587.409        3561.0784       222.052853440003 38.3800000000001

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

I didn't see any statistically meaningful performance defect.

OK, then we can increase ARCH_MMAP_RND_BITS_MIN, but the range 18~20 seems too small and then useless, can we consider using 15~20?

IMO ARCH_MMAP_RND_BITS_MIN should be just the minimal that the architecture can support, not related to security.  If you want to recommend a value for increasing security you'd set ARCH_MMAP_RND_BITS_DEFAULT a larger value instead.

I.e. for example if someone is building a distro running on an embedded system where avoiding addr space fragmentation is more important than security we shouldn't be stopping him to decrease ARCH_MMAP_RND_BITS unless he reaches the architecture minimum. Instead we should increase ARCH_MMAP_RND_BITS_DEFAULT so the "typical" systems get a larger ARCH_MMAP_RND_BITS.

Signature · 1 line
Xi Ruoyao <[email protected]>
maintainer
#7 lore raw
Quoted 92 lines · Xi Ruoyao
Quoted 81 lines · Xi Ruoyao
Quoted 80 lines · Huacai Chen
Quoted 79 lines · Bingwu Zhang
Quoted 28 lines · China Standard Time Huacai Chen

Hi, Bingwu,

Quoted 19 lines · Bingwu Zhang

From: Bingwu Zhang <[email protected]>

Increase default mmap randomization bits from 12 to 18 on 64- bit
platforms for better strength.

The original default, 12, means that ASLR offset has only (1 << 12) =
4096 possibilities. On average, it can be brute-forced in 2048 attempts.
If a service is configured to restart automatically or can be started
easily (e.g. execve a suid program), then trying for 4k times can be
done in one day even when each attempt takes 20s. Increasing it to 18 makes brute-force much more difficult and leaves
more time for operators to find out attacks.

Quoted 4 lines

On 64-bit platforms, virtual address space is cheap, so the randomization bits can be increased safely without disturbing userland
much and security comes first instead of availability.

Quoted 9 lines

Don't change ARCH_MMAP_RND_BITS_MIN because it may compact performance, and you cannot blindly increase ARCH_MMAP_RND_BITS_MAX
because it should no more than "VA_BITS - PAGE_SHIFT - 3" (see arch/riscv/Kconfig and arch/csky/Kconfig). For LoongArch, VA_BITS can
be 39 (half of VA40), PAGE_SHIFT can be 16 (64KB page), so ARCH_MMAP_RND_BITS_MAX can only increase up to 20 (39 - 16 - 3 =20).

Sorry for the late reply.

It was my mistake that I didn't notice the upper bound of MAX. Thank you for
pointing out!

However, I didn't get where increasing MIN could compact performance.
Theoretically, the only difference is that the gap between heaps and stacks
are larger, from [128, 128+64]M to [128, 128+4096]M. This shouldn't affect
performance much. MIPS once used MIN=16, RISC-V 64 and PowerPC and ARM 64 are
using 18, and x86-64 is using 28, but I hadn't heard anyone complaining about
the performance.

I ran some benchmarks last weekend using the LLVM build benchmark of AOSC OS
https://github.com/AOSC-Dev/buildbot-benchmark/blob/master/buildbot-benchmark.bash
and here are the results

Processor Rand bits Time/secs
Average Variance Range

3C6000/S        18      612.927 614.394 614.513 613.343 614.76
613.9874        0.515637840000006       1.83299999999997
3C6000/S        12      614.322 613.93  614.825 613.859

615.875 614.5622 0.548874160000007 2.01599999999996
3A5000 18 3547.165 3548.764 3552.192
3545.697
3547.567 3548.277 4.79228759999993
6.49499999999989
3A5000 12 3549.029 3551.894 3549.191
3567.869
3587.409 3561.0784 222.052853440003
38.3800000000001

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

I didn't see any statistically meaningful performance defect.

OK, then we can increase ARCH_MMAP_RND_BITS_MIN, but the range 18~20 seems too small and then useless, can we consider using 15~20?

IMO ARCH_MMAP_RND_BITS_MIN should be just the minimal that the architecture can support, not related to security. If you want to recommend a value for increasing security you'd set ARCH_MMAP_RND_BITS_DEFAULT a larger value instead.

Quoted 6 lines

I.e. for example if someone is building a distro running on an embedded system where avoiding addr space fragmentation is more important than security we shouldn't be stopping him to decrease ARCH_MMAP_RND_BITS unless he reaches the architecture minimum. Instead we should increase ARCH_MMAP_RND_BITS_DEFAULT so the "typical" systems get a larger ARCH_MMAP_RND_BITS.

Hmm, ARCH_MMAP_RND_BITS is visible and configurable, so just keep ARCH_MMAP_RND_BITS_MIN as 12.

Huacai

Quoted 3 lines

--
Xi Ruoyao <[email protected]>

author
#8 lore raw
In reply to Xi Ruoyao
Quoted 82 lines · Xi Ruoyao

On Sun, 2026-04-12 at 20:32 +0800, Xi Ruoyao wrote:
&gt; On Sun, 2026-04-12 at 20:24 +0800, Huacai Chen wrote:
&gt; &gt; On Sun, Apr 12, 2026 at 11:49 AM Bingwu Zhang &lt;[email protected]&gt; wrote:
&gt; &gt; &gt;
&gt; &gt; &gt; On Sunday, March 29, 2026 11:48:02 AM China Standard Time Huacai &gt; &gt; &gt; Chen wrote:
&gt; &gt; &gt; &gt; Hi, Bingwu,
&gt; &gt; &gt; &gt;
&gt; &gt; &gt; &gt; On Sun, Mar 29, 2026 at 6:59 AM Bingwu Zhang &lt;[email protected]&gt; &gt; &gt; &gt; &gt; wrote:
&gt; &gt; &gt; &gt; &gt; From: Bingwu Zhang &lt;[email protected]&gt;
&gt; &gt; &gt; &gt; &gt;
&gt; &gt; &gt; &gt; &gt; Increase default mmap randomization bits from 12 to 18 on 64- &gt; &gt; &gt; &gt; &gt; bit
&gt; &gt; &gt; &gt; &gt; platforms for better strength.
&gt; &gt; &gt; &gt; &gt;
&gt; &gt; &gt; &gt; &gt; The original default, 12, means that ASLR offset has only (1 &gt; &gt; &gt; &gt; &gt; &lt;&lt; 12) =
&gt; &gt; &gt; &gt; &gt; 4096 possibilities. On average, it can be brute-forced in 2048 &gt; &gt; &gt; &gt; &gt; attempts.
&gt; &gt; &gt; &gt; &gt; If a service is configured to restart automatically or can be &gt; &gt; &gt; &gt; &gt; started
&gt; &gt; &gt; &gt; &gt; easily (e.g. execve a suid program), then trying for 4k times &gt; &gt; &gt; &gt; &gt; can be
&gt; &gt; &gt; &gt; &gt; done in one day even when each attempt takes 20s.
&gt; &gt; &gt; &gt; &gt; Increasing it to 18 makes brute-force much more difficult and &gt; &gt; &gt; &gt; &gt; leaves
&gt; &gt; &gt; &gt; &gt; more time for operators to find out attacks.
&gt; &gt; &gt; &gt; &gt;
&gt; &gt; &gt; &gt; &gt; On 64-bit platforms, virtual address space is cheap, so the &gt; &gt; &gt; &gt; &gt; randomization bits can be increased safely without disturbing &gt; &gt; &gt; &gt; &gt; userland
&gt; &gt; &gt; &gt; &gt; much and security comes first instead of availability. &gt; &gt; &gt; &gt;
&gt; &gt; &gt; &gt; Don&#x27;t change ARCH_MMAP_RND_BITS_MIN because it may compact &gt; &gt; &gt; &gt; performance, and you cannot blindly increase
&gt; &gt; &gt; &gt; ARCH_MMAP_RND_BITS_MAX
&gt; &gt; &gt; &gt; because it should no more than &quot;VA_BITS - PAGE_SHIFT - 3&quot; (see &gt; &gt; &gt; &gt; arch/riscv/Kconfig and arch/csky/Kconfig). For LoongArch, &gt; &gt; &gt; &gt; VA_BITS can
&gt; &gt; &gt; &gt; be 39 (half of VA40), PAGE_SHIFT can be 16 (64KB page), so &gt; &gt; &gt; &gt; ARCH_MMAP_RND_BITS_MAX can only increase up to 20 (39 - 16 - 3 &gt; &gt; &gt; &gt; =20).
&gt; &gt; &gt;
&gt; &gt; &gt; Sorry for the late reply.
&gt; &gt; &gt;
&gt; &gt; &gt; It was my mistake that I didn&#x27;t notice the upper bound of MAX. &gt; &gt; &gt; Thank you for
&gt; &gt; &gt; pointing out!
&gt; &gt; &gt;
&gt; &gt; &gt; However, I didn&#x27;t get where increasing MIN could compact
&gt; &gt; &gt; performance.
&gt; &gt; &gt; Theoretically, the only difference is that the gap between heaps &gt; &gt; &gt; and stacks
&gt; &gt; &gt; are larger, from [128, 128+64]M to [128, 128+4096]M. This
&gt; &gt; &gt; shouldn&#x27;t affect
&gt; &gt; &gt; performance much. MIPS once used MIN=16, RISC-V 64 and PowerPC and &gt; &gt; &gt; ARM 64 are
&gt; &gt; &gt; using 18, and x86-64 is using 28, but I hadn&#x27;t heard anyone &gt; &gt; &gt; complaining about
&gt; &gt; &gt; the performance.
&gt; &gt; &gt;
&gt; &gt; &gt; I ran some benchmarks last weekend using the LLVM build benchmark &gt; &gt; &gt; of AOSC OS
&gt; &gt; &gt; https://github.com/AOSC-Dev/buildbot-benchmark/blob/master/buildbot-benchmark.bash
&gt; &gt; &gt; and here are the results
&gt; &gt; &gt;
&gt; &gt; &gt; Processor       Rand bits       Time/secs
&gt; &gt; &gt; Average Variance        Range
&gt; &gt; &gt; 3C6000/S        18      612.927 614.394 614.513 613.343 614.76 &gt; &gt; &gt; 613.9874        0.515637840000006       1.83299999999997
&gt; &gt; &gt; 3C6000/S        12      614.322 613.93  614.825 613.859
&gt; &gt; &gt; 615.875 614.5622        0.548874160000007       2.01599999999996 &gt; &gt; &gt; 3A5000  18      3547.165        3548.764        3552.192
&gt; &gt; &gt; 3545.697
&gt; &gt; &gt; 3547.567        3548.277        4.79228759999993
&gt; &gt; &gt; 6.49499999999989
&gt; &gt; &gt; 3A5000  12      3549.029        3551.894        3549.191
&gt; &gt; &gt; 3567.869
&gt; &gt; &gt; 3587.409        3561.0784       222.052853440003
&gt; &gt; &gt; 38.3800000000001
&gt; &gt; &gt;

Quoted 8 lines

&gt; &gt; &gt; I didn&#x27;t see any statistically meaningful performance defect. &gt; &gt; OK, then we can increase ARCH_MMAP_RND_BITS_MIN, but the range 18~20 &gt; &gt; seems too small and then useless, can we consider using 15~20? &gt;
&gt; IMO ARCH_MMAP_RND_BITS_MIN should be just the minimal that the &gt; architecture can support, not related to security.  If you want to &gt; recommend a value for increasing security you&#x27;d set
&gt; ARCH_MMAP_RND_BITS_DEFAULT a larger value instead.

okay, I agree to abandon this patch. But,
Isn't the minimum supported value 0 (i.e. mmap ASLR disabled)? There is always a fixed 128M gap between heaps and stack tops so 0 should work.

Quoted 7 lines

I.e. for example if someone is building a distro running on an embedded system where avoiding addr space fragmentation is more important than security we shouldn&#x27;t be stopping him to decrease ARCH_MMAP_RND_BITS unless he reaches the architecture minimum. Instead we should increase ARCH_MMAP_RND_BITS_DEFAULT so the &quot;typical&quot; systems get a larger ARCH_MMAP_RND_BITS.

Is address space fragmentation that important on embedded systems? Isn't it obvious that you will never have 300G RAM on embedded systems?

Quoted 3 lines
Signature · 2 lines
-- 
Xi Ruoyao &lt;[email protected]&gt;

Bingwu Zhang

author
#9 lore raw
In reply to Xi Ruoyao
Quoted 82 lines · Xi Ruoyao

On Sun, 2026-04-12 at 20:32 +0800, Xi Ruoyao wrote:
&gt; On Sun, 2026-04-12 at 20:24 +0800, Huacai Chen wrote:
&gt; &gt; On Sun, Apr 12, 2026 at 11:49 AM Bingwu Zhang &lt;[email protected]&gt; wrote:
&gt; &gt; &gt;
&gt; &gt; &gt; On Sunday, March 29, 2026 11:48:02 AM China Standard Time Huacai &gt; &gt; &gt; Chen wrote:
&gt; &gt; &gt; &gt; Hi, Bingwu,
&gt; &gt; &gt; &gt;
&gt; &gt; &gt; &gt; On Sun, Mar 29, 2026 at 6:59 AM Bingwu Zhang &lt;[email protected]&gt; &gt; &gt; &gt; &gt; wrote:
&gt; &gt; &gt; &gt; &gt; From: Bingwu Zhang &lt;[email protected]&gt;
&gt; &gt; &gt; &gt; &gt;
&gt; &gt; &gt; &gt; &gt; Increase default mmap randomization bits from 12 to 18 on 64- &gt; &gt; &gt; &gt; &gt; bit
&gt; &gt; &gt; &gt; &gt; platforms for better strength.
&gt; &gt; &gt; &gt; &gt;
&gt; &gt; &gt; &gt; &gt; The original default, 12, means that ASLR offset has only (1 &gt; &gt; &gt; &gt; &gt; &lt;&lt; 12) =
&gt; &gt; &gt; &gt; &gt; 4096 possibilities. On average, it can be brute-forced in 2048 &gt; &gt; &gt; &gt; &gt; attempts.
&gt; &gt; &gt; &gt; &gt; If a service is configured to restart automatically or can be &gt; &gt; &gt; &gt; &gt; started
&gt; &gt; &gt; &gt; &gt; easily (e.g. execve a suid program), then trying for 4k times &gt; &gt; &gt; &gt; &gt; can be
&gt; &gt; &gt; &gt; &gt; done in one day even when each attempt takes 20s.
&gt; &gt; &gt; &gt; &gt; Increasing it to 18 makes brute-force much more difficult and &gt; &gt; &gt; &gt; &gt; leaves
&gt; &gt; &gt; &gt; &gt; more time for operators to find out attacks.
&gt; &gt; &gt; &gt; &gt;
&gt; &gt; &gt; &gt; &gt; On 64-bit platforms, virtual address space is cheap, so the &gt; &gt; &gt; &gt; &gt; randomization bits can be increased safely without disturbing &gt; &gt; &gt; &gt; &gt; userland
&gt; &gt; &gt; &gt; &gt; much and security comes first instead of availability. &gt; &gt; &gt; &gt;
&gt; &gt; &gt; &gt; Don&#x27;t change ARCH_MMAP_RND_BITS_MIN because it may compact &gt; &gt; &gt; &gt; performance, and you cannot blindly increase
&gt; &gt; &gt; &gt; ARCH_MMAP_RND_BITS_MAX
&gt; &gt; &gt; &gt; because it should no more than &quot;VA_BITS - PAGE_SHIFT - 3&quot; (see &gt; &gt; &gt; &gt; arch/riscv/Kconfig and arch/csky/Kconfig). For LoongArch, &gt; &gt; &gt; &gt; VA_BITS can
&gt; &gt; &gt; &gt; be 39 (half of VA40), PAGE_SHIFT can be 16 (64KB page), so &gt; &gt; &gt; &gt; ARCH_MMAP_RND_BITS_MAX can only increase up to 20 (39 - 16 - 3 &gt; &gt; &gt; &gt; =20).
&gt; &gt; &gt;
&gt; &gt; &gt; Sorry for the late reply.
&gt; &gt; &gt;
&gt; &gt; &gt; It was my mistake that I didn&#x27;t notice the upper bound of MAX. &gt; &gt; &gt; Thank you for
&gt; &gt; &gt; pointing out!
&gt; &gt; &gt;
&gt; &gt; &gt; However, I didn&#x27;t get where increasing MIN could compact
&gt; &gt; &gt; performance.
&gt; &gt; &gt; Theoretically, the only difference is that the gap between heaps &gt; &gt; &gt; and stacks
&gt; &gt; &gt; are larger, from [128, 128+64]M to [128, 128+4096]M. This
&gt; &gt; &gt; shouldn&#x27;t affect
&gt; &gt; &gt; performance much. MIPS once used MIN=16, RISC-V 64 and PowerPC and &gt; &gt; &gt; ARM 64 are
&gt; &gt; &gt; using 18, and x86-64 is using 28, but I hadn&#x27;t heard anyone &gt; &gt; &gt; complaining about
&gt; &gt; &gt; the performance.
&gt; &gt; &gt;
&gt; &gt; &gt; I ran some benchmarks last weekend using the LLVM build benchmark &gt; &gt; &gt; of AOSC OS
&gt; &gt; &gt; https://github.com/AOSC-Dev/buildbot-benchmark/blob/master/buildbot-benchmark.bash
&gt; &gt; &gt; and here are the results
&gt; &gt; &gt;
&gt; &gt; &gt; Processor       Rand bits       Time/secs
&gt; &gt; &gt; Average Variance        Range
&gt; &gt; &gt; 3C6000/S        18      612.927 614.394 614.513 613.343 614.76 &gt; &gt; &gt; 613.9874        0.515637840000006       1.83299999999997
&gt; &gt; &gt; 3C6000/S        12      614.322 613.93  614.825 613.859
&gt; &gt; &gt; 615.875 614.5622        0.548874160000007       2.01599999999996 &gt; &gt; &gt; 3A5000  18      3547.165        3548.764        3552.192
&gt; &gt; &gt; 3545.697
&gt; &gt; &gt; 3547.567        3548.277        4.79228759999993
&gt; &gt; &gt; 6.49499999999989
&gt; &gt; &gt; 3A5000  12      3549.029        3551.894        3549.191
&gt; &gt; &gt; 3567.869
&gt; &gt; &gt; 3587.409        3561.0784       222.052853440003
&gt; &gt; &gt; 38.3800000000001
&gt; &gt; &gt;

Quoted 8 lines

&gt; &gt; &gt; I didn&#x27;t see any statistically meaningful performance defect. &gt; &gt; OK, then we can increase ARCH_MMAP_RND_BITS_MIN, but the range 18~20 &gt; &gt; seems too small and then useless, can we consider using 15~20? &gt;
&gt; IMO ARCH_MMAP_RND_BITS_MIN should be just the minimal that the &gt; architecture can support, not related to security.  If you want to &gt; recommend a value for increasing security you&#x27;d set
&gt; ARCH_MMAP_RND_BITS_DEFAULT a larger value instead.

okay, I agree to abandon this patch. But,
Isn't the minimum supported value 0 (i.e. mmap ASLR disabled)? There is always a fixed 128M gap between heaps and stack tops so 0 should work.

Quoted 7 lines

I.e. for example if someone is building a distro running on an embedded system where avoiding addr space fragmentation is more important than security we shouldn&#x27;t be stopping him to decrease ARCH_MMAP_RND_BITS unless he reaches the architecture minimum. Instead we should increase ARCH_MMAP_RND_BITS_DEFAULT so the &quot;typical&quot; systems get a larger ARCH_MMAP_RND_BITS.

Is address space fragmentation that important on embedded systems? Isn't it obvious that you will never have 300G RAM on embedded systems?

Quoted 3 lines
Signature · 2 lines
-- 
Xi Ruoyao &lt;[email protected]&gt;

Bingwu Zhang

maintainer
#10 lore raw
Quoted 93 lines · xtex
Quoted 82 lines · Xi Ruoyao

On Sun, 2026-04-12 at 20:32 +0800, Xi Ruoyao wrote:
&gt; On Sun, 2026-04-12 at 20:24 +0800, Huacai Chen wrote:
&gt; &gt; On Sun, Apr 12, 2026 at 11:49 AM Bingwu Zhang &lt;[email protected]&gt; wrote:
&gt; &gt; &gt;
&gt; &gt; &gt; On Sunday, March 29, 2026 11:48:02 AM China Standard Time Huacai &gt; &gt; &gt; Chen wrote:
&gt; &gt; &gt; &gt; Hi, Bingwu,
&gt; &gt; &gt; &gt;
&gt; &gt; &gt; &gt; On Sun, Mar 29, 2026 at 6:59 AM Bingwu Zhang &lt;[email protected]&gt; &gt; &gt; &gt; &gt; wrote:
&gt; &gt; &gt; &gt; &gt; From: Bingwu Zhang &lt;[email protected]&gt;
&gt; &gt; &gt; &gt; &gt;
&gt; &gt; &gt; &gt; &gt; Increase default mmap randomization bits from 12 to 18 on 64- &gt; &gt; &gt; &gt; &gt; bit
&gt; &gt; &gt; &gt; &gt; platforms for better strength.
&gt; &gt; &gt; &gt; &gt;
&gt; &gt; &gt; &gt; &gt; The original default, 12, means that ASLR offset has only (1 &gt; &gt; &gt; &gt; &gt; &lt;&lt; 12) =
&gt; &gt; &gt; &gt; &gt; 4096 possibilities. On average, it can be brute-forced in 2048 &gt; &gt; &gt; &gt; &gt; attempts.
&gt; &gt; &gt; &gt; &gt; If a service is configured to restart automatically or can be &gt; &gt; &gt; &gt; &gt; started
&gt; &gt; &gt; &gt; &gt; easily (e.g. execve a suid program), then trying for 4k times &gt; &gt; &gt; &gt; &gt; can be
&gt; &gt; &gt; &gt; &gt; done in one day even when each attempt takes 20s.
&gt; &gt; &gt; &gt; &gt; Increasing it to 18 makes brute-force much more difficult and &gt; &gt; &gt; &gt; &gt; leaves
&gt; &gt; &gt; &gt; &gt; more time for operators to find out attacks.
&gt; &gt; &gt; &gt; &gt;
&gt; &gt; &gt; &gt; &gt; On 64-bit platforms, virtual address space is cheap, so the &gt; &gt; &gt; &gt; &gt; randomization bits can be increased safely without disturbing &gt; &gt; &gt; &gt; &gt; userland
&gt; &gt; &gt; &gt; &gt; much and security comes first instead of availability. &gt; &gt; &gt; &gt;
&gt; &gt; &gt; &gt; Don&#x27;t change ARCH_MMAP_RND_BITS_MIN because it may compact &gt; &gt; &gt; &gt; performance, and you cannot blindly increase
&gt; &gt; &gt; &gt; ARCH_MMAP_RND_BITS_MAX
&gt; &gt; &gt; &gt; because it should no more than &quot;VA_BITS - PAGE_SHIFT - 3&quot; (see &gt; &gt; &gt; &gt; arch/riscv/Kconfig and arch/csky/Kconfig). For LoongArch, &gt; &gt; &gt; &gt; VA_BITS can
&gt; &gt; &gt; &gt; be 39 (half of VA40), PAGE_SHIFT can be 16 (64KB page), so &gt; &gt; &gt; &gt; ARCH_MMAP_RND_BITS_MAX can only increase up to 20 (39 - 16 - 3 &gt; &gt; &gt; &gt; =20).
&gt; &gt; &gt;
&gt; &gt; &gt; Sorry for the late reply.
&gt; &gt; &gt;
&gt; &gt; &gt; It was my mistake that I didn&#x27;t notice the upper bound of MAX. &gt; &gt; &gt; Thank you for
&gt; &gt; &gt; pointing out!
&gt; &gt; &gt;
&gt; &gt; &gt; However, I didn&#x27;t get where increasing MIN could compact
&gt; &gt; &gt; performance.
&gt; &gt; &gt; Theoretically, the only difference is that the gap between heaps &gt; &gt; &gt; and stacks
&gt; &gt; &gt; are larger, from [128, 128+64]M to [128, 128+4096]M. This
&gt; &gt; &gt; shouldn&#x27;t affect
&gt; &gt; &gt; performance much. MIPS once used MIN=16, RISC-V 64 and PowerPC and &gt; &gt; &gt; ARM 64 are
&gt; &gt; &gt; using 18, and x86-64 is using 28, but I hadn&#x27;t heard anyone &gt; &gt; &gt; complaining about
&gt; &gt; &gt; the performance.
&gt; &gt; &gt;
&gt; &gt; &gt; I ran some benchmarks last weekend using the LLVM build benchmark &gt; &gt; &gt; of AOSC OS
&gt; &gt; &gt; https://github.com/AOSC-Dev/buildbot-benchmark/blob/master/buildbot-benchmark.bash
&gt; &gt; &gt; and here are the results
&gt; &gt; &gt;
&gt; &gt; &gt; Processor Rand bits Time/secs
&gt; &gt; &gt; Average Variance Range

&gt; &gt; &gt; 3C6000/S        18      612.927 614.394 614.513 613.343 614.76
&gt; &gt; &gt; 613.9874        0.515637840000006       1.83299999999997
&gt; &gt; &gt; 3C6000/S        12      614.322 613.93  614.825 613.859

&gt; &gt; &gt; 615.875 614.5622 0.548874160000007 2.01599999999996
&gt; &gt; &gt; 3A5000 18 3547.165 3548.764 3552.192
&gt; &gt; &gt; 3545.697
&gt; &gt; &gt; 3547.567 3548.277 4.79228759999993
&gt; &gt; &gt; 6.49499999999989
&gt; &gt; &gt; 3A5000 12 3549.029 3551.894 3549.191
&gt; &gt; &gt; 3567.869
&gt; &gt; &gt; 3587.409 3561.0784 222.052853440003
&gt; &gt; &gt; 38.3800000000001
&gt; &gt; &gt;

Quoted 8 lines

&gt; &gt; &gt; I didn&#x27;t see any statistically meaningful performance defect. &gt; &gt; OK, then we can increase ARCH_MMAP_RND_BITS_MIN, but the range 18~20 &gt; &gt; seems too small and then useless, can we consider using 15~20? &gt;
&gt; IMO ARCH_MMAP_RND_BITS_MIN should be just the minimal that the &gt; architecture can support, not related to security. If you want to &gt; recommend a value for increasing security you&#x27;d set
&gt; ARCH_MMAP_RND_BITS_DEFAULT a larger value instead.

Quoted 2 lines

okay, I agree to abandon this patch. But,
Isn't the minimum supported value 0 (i.e. mmap ASLR disabled)? There is always a fixed 128M gap between heaps and stack tops so 0 should work.

Maybe it should be 0, but keeping the old value is better because I think there are some historic reasons.

Huacai

Quoted 17 lines
Quoted 8 lines

I.e. for example if someone is building a distro running on an embedded system where avoiding addr space fragmentation is more important than security we shouldn&#x27;t be stopping him to decrease ARCH_MMAP_RND_BITS unless he reaches the architecture minimum. Instead we should increase ARCH_MMAP_RND_BITS_DEFAULT so the &quot;typical&quot; systems get a larger ARCH_MMAP_RND_BITS.

Is address space fragmentation that important on embedded systems? Isn't it obvious that you will never have 300G RAM on embedded systems?

Quoted 3 lines

--
Xi Ruoyao &lt;[email protected]&gt;

Bingwu Zhang