Skip to contentSkip to conversation

riscv: Improve stack randomisation on RV64

PATCH In review Kefeng Wang 2 participants 3 messages Aug 12, 2021 – Sep 11, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 riscv: Improve stack randomisation on RV64

54c95a11cc1b ("riscv: make mmap allocation top-down by default") support ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT, which will select ARCH_HAS_ELF_RANDOMIZE from commit e7142bf5d231 ("arm64, mm: make randomization selected by generic topdown mmap layout"), so riscv has support ELF ASLR feature, update the documentation.

And enlarge STACK_RND_MASK from 8M to 1G to increase stack randomisation on RV64 like x86/arm64 does.

Cc Alexandre Ghiti <[email protected]>
---
 Documentation/features/vm/ELF-ASLR/arch-support.txt | 2 +-
 arch/riscv/include/asm/elf.h                        | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)
Documentation/features/vm/ELF-ASLR/arch-support.txt +1 -1
index 99cb6d7f5005..2949c99fbb2f 100644
@@ -22,7 +22,7 @@
     |    openrisc: | TODO |
     |      parisc: |  ok  |
     |     powerpc: |  ok  |
-    |       riscv: | TODO |
+    |       riscv: |  ok  |
     |        s390: |  ok  |
     |          sh: | TODO |
     |       sparc: | TODO |
arch/riscv/include/asm/elf.h +3 -0
index f4b490cd0e5d..f53c40026c7a 100644
@@ -42,6 +42,9 @@
  */
 #define ELF_ET_DYN_BASE		((TASK_SIZE / 3) * 2)
 
+#ifdef CONFIG_64BIT
+#define STACK_RND_MASK		(0x3ffff >> (PAGE_SHIFT - 12))
+#endif
 /*
  * This yields a mask that user programs can use to figure out what
  * instruction set this CPU supports.  This could be done in user space,
Signature · 7 lines
2.26.2


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#1 lore raw

+cc Jonathan

Quoted 34 lines · Kefeng Wang

54c95a11cc1b ("riscv: make mmap allocation top-down by default") support ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT, which will select ARCH_HAS_ELF_RANDOMIZE from commit e7142bf5d231 ("arm64, mm: make randomization selected by generic topdown mmap layout"), so riscv has support ELF ASLR feature, update the documentation.

And enlarge STACK_RND_MASK from 8M to 1G to increase stack randomisation on RV64 like x86/arm64 does.

Cc Alexandre Ghiti <[email protected]>
---
  Documentation/features/vm/ELF-ASLR/arch-support.txt | 2 +-
  arch/riscv/include/asm/elf.h                        | 3 +++
  2 files changed, 4 insertions(+), 1 deletion(-)
Documentation/features/vm/ELF-ASLR/arch-support.txt +1 -1
index 99cb6d7f5005..2949c99fbb2f 100644
@@ -22,7 +22,7 @@
      |    openrisc: | TODO |
      |      parisc: |  ok  |
      |     powerpc: |  ok  |
-    |       riscv: | TODO |
+    |       riscv: |  ok  |
      |        s390: |  ok  |
      |          sh: | TODO |
      |       sparc: | TODO |
arch/riscv/include/asm/elf.h +0 -0
index f4b490cd0e5d..f53c40026c7a 100644

arch/riscv/include/asm/elf.h line 50

Quoted 9 lines
arch/riscv/include/asm/elf.h +3 -0
@@ -42,6 +42,9 @@
   */
  #define ELF_ET_DYN_BASE		((TASK_SIZE / 3) * 2)
 
+#ifdef CONFIG_64BIT
+#define STACK_RND_MASK		(0x3ffff >> (PAGE_SHIFT - 12))
+#endif
  /*
   * This yields a mask that user programs can use to figure out what
   * instruction set this CPU supports.  This could be done in user space,

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

maintainer
#2 lore raw
In reply to Kefeng Wang
Quoted 34 lines · On Thu, 12 Aug 2021 04:47:02 PDT (-0700), [email protected] wrote:

54c95a11cc1b ("riscv: make mmap allocation top-down by default") support ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT, which will select ARCH_HAS_ELF_RANDOMIZE from commit e7142bf5d231 ("arm64, mm: make randomization selected by generic topdown mmap layout"), so riscv has support ELF ASLR feature, update the documentation.

And enlarge STACK_RND_MASK from 8M to 1G to increase stack randomisation on RV64 like x86/arm64 does.

Cc Alexandre Ghiti <[email protected]>
---
 Documentation/features/vm/ELF-ASLR/arch-support.txt | 2 +-
 arch/riscv/include/asm/elf.h                        | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)
Documentation/features/vm/ELF-ASLR/arch-support.txt +1 -1
index 99cb6d7f5005..2949c99fbb2f 100644
@@ -22,7 +22,7 @@
     |    openrisc: | TODO |
     |      parisc: |  ok  |
     |     powerpc: |  ok  |
-    |       riscv: | TODO |
+    |       riscv: |  ok  |
     |        s390: |  ok  |
     |          sh: | TODO |
     |       sparc: | TODO |
arch/riscv/include/asm/elf.h +0 -0
index f4b490cd0e5d..f53c40026c7a 100644

arch/riscv/include/asm/elf.h line 50

Quoted 9 lines
arch/riscv/include/asm/elf.h +3 -0
@@ -42,6 +42,9 @@
  */
 #define ELF_ET_DYN_BASE		((TASK_SIZE / 3) * 2)
 
+#ifdef CONFIG_64BIT
+#define STACK_RND_MASK		(0x3ffff >> (PAGE_SHIFT - 12))
+#endif
 /*
  * This yields a mask that user programs can use to figure out what
  * instruction set this CPU supports.  This could be done in user space,

Thanks. I cleaned up the commit text a bit, this is on for-next.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv