Skip to contentSkip to conversation

riscv: mm: implement pgprot_nx

PATCH Applied Jisheng Zhang 5 participants 6 messages Nov 21, 2023 – Apr 4, 2024 RISC-V

v1 of 2 Applied 1/1 Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 riscv: mm: implement pgprot_nx

commit cca98e9f8b5e ("mm: enforce that vmap can't map pages executable") enforces the W^X protection by not allowing remapping existing pages as executable. Add riscv bits so that riscv can benefit the same protection.

---
 arch/riscv/include/asm/pgtable.h | 6 ++++++
 1 file changed, 6 insertions(+)
arch/riscv/include/asm/pgtable.h +6 -0
index 294044429e8e..4fc6ee5226fb 100644
@@ -608,6 +608,12 @@ static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
 	return ptep_test_and_clear_young(vma, address, ptep);
 }
 
+#define pgprot_nx pgprot_nx
+static inline pgprot_t pgprot_nx(pgprot_t _prot)
+{
+	return __pgprot(pgprot_val(_prot) & ~_PAGE_EXEC);
+}
+
 #define pgprot_noncached pgprot_noncached
 static inline pgprot_t pgprot_noncached(pgprot_t _prot)
 {
Signature · 1 line
2.42.0
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 9 lines · Jisheng Zhang

commit cca98e9f8b5e ("mm: enforce that vmap can't map pages executable") enforces the W^X protection by not allowing remapping existing pages as executable. Add riscv bits so that riscv can benefit the same protection.

---
 arch/riscv/include/asm/pgtable.h | 6 ++++++
 1 file changed, 6 insertions(+)
#3 lore raw
In reply to Jisheng Zhang
Quoted 4 lines · Jisheng Zhang

commit cca98e9f8b5e ("mm: enforce that vmap can't map pages executable") enforces the W^X protection by not allowing remapping existing pages as executable. Add riscv bits so that riscv can benefit the same protection.

And this simple patch to enforce W^X protection is also missed ;)

Thanks in advance

Quoted 31 lines
---
 arch/riscv/include/asm/pgtable.h | 6 ++++++
 1 file changed, 6 insertions(+)
arch/riscv/include/asm/pgtable.h +6 -0
index 294044429e8e..4fc6ee5226fb 100644
@@ -608,6 +608,12 @@ static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
 	return ptep_test_and_clear_young(vma, address, ptep);
 }
 
+#define pgprot_nx pgprot_nx
+static inline pgprot_t pgprot_nx(pgprot_t _prot)
+{
+	return __pgprot(pgprot_val(_prot) & ~_PAGE_EXEC);
+}
+
 #define pgprot_noncached pgprot_noncached
 static inline pgprot_t pgprot_noncached(pgprot_t _prot)
 {
Signature · 7 lines
2.42.0


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
reviewer Reviewed-by on v1 1/1
#4 lore raw
In reply to Jisheng Zhang
Quoted 17 lines · Jisheng Zhang

commit cca98e9f8b5e ("mm: enforce that vmap can't map pages executable") enforces the W^X protection by not allowing remapping existing pages as executable. Add riscv bits so that riscv can benefit the same protection.

---
  arch/riscv/include/asm/pgtable.h | 6 ++++++
  1 file changed, 6 insertions(+)
arch/riscv/include/asm/pgtable.h +0 -0
index 294044429e8e..4fc6ee5226fb 100644
@@ -608,6 +608,12 @@ static inline int ptep_clear_flush_young(struct vm_area_struct *vma,
  	return ptep_test_and_clear_young(vma, address, ptep);
  }

arch/riscv/include/asm/pgtable.h static inline int ptep_clear_flush_young(struct vm_area_struct *vma, · line 619

Quoted 10 lines
arch/riscv/include/asm/pgtable.h +6 -0
 
+#define pgprot_nx pgprot_nx
+static inline pgprot_t pgprot_nx(pgprot_t _prot)
+{
+	return __pgprot(pgprot_val(_prot) & ~_PAGE_EXEC);
+}
+
  #define pgprot_noncached pgprot_noncached
  static inline pgprot_t pgprot_noncached(pgprot_t _prot)
  {

This one looks good too:

Thanks,

Alex

#5 lore raw
In reply to Jisheng Zhang
This patch was applied to riscv/linux.git (fixes) by Palmer Dabbelt <[email protected]>:

Hello:

This patch was applied to riscv/linux.git (fixes)
by Palmer Dabbelt <[email protected]>:

Quoted 8 lines · On Wed, 22 Nov 2023 00:06:37 +0800 you wrote:

commit cca98e9f8b5e ("mm: enforce that vmap can't map pages executable") enforces the W^X protection by not allowing remapping existing pages as executable. Add riscv bits so that riscv can benefit the same protection.

[...]

Here is the summary with links:
- riscv: mm: implement pgprot_nx

    https://git.kernel.org/riscv/c/0ffe1ae7026d

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html