diff mbox series

[v4,12/30] riscv mm: manufacture shadow stack pte

Message ID 20240912231650.3740732-13-debug@rivosinc.com (mailing list archive)
State Superseded
Headers show
Series riscv control-flow integrity for usermode | expand

Checks

Context Check Description
conchuod/vmtest-fixes-PR fail merge-conflict
conchuod/vmtest-for-next-PR fail PR summary
conchuod/patch-12-test-1 success .github/scripts/patches/tests/build_rv32_defconfig.sh took 130.48s
conchuod/patch-12-test-2 success .github/scripts/patches/tests/build_rv64_clang_allmodconfig.sh took 2603.89s
conchuod/patch-12-test-3 success .github/scripts/patches/tests/build_rv64_gcc_allmodconfig.sh took 3068.78s
conchuod/patch-12-test-4 success .github/scripts/patches/tests/build_rv64_nommu_k210_defconfig.sh took 19.87s
conchuod/patch-12-test-5 success .github/scripts/patches/tests/build_rv64_nommu_virt_defconfig.sh took 21.87s
conchuod/patch-12-test-6 success .github/scripts/patches/tests/checkpatch.sh took 0.46s
conchuod/patch-12-test-7 success .github/scripts/patches/tests/dtb_warn_rv64.sh took 41.46s
conchuod/patch-12-test-8 success .github/scripts/patches/tests/header_inline.sh took 0.01s
conchuod/patch-12-test-9 success .github/scripts/patches/tests/kdoc.sh took 0.52s
conchuod/patch-12-test-10 success .github/scripts/patches/tests/module_param.sh took 0.01s
conchuod/patch-12-test-11 success .github/scripts/patches/tests/verify_fixes.sh took 0.00s
conchuod/patch-12-test-12 success .github/scripts/patches/tests/verify_signedoff.sh took 0.05s

Commit Message

Deepak Gupta Sept. 12, 2024, 11:16 p.m. UTC
This patch implements creating shadow stack pte (on riscv). Creating
shadow stack PTE on riscv means that clearing RWX and then setting W=1.

Signed-off-by: Deepak Gupta <debug@rivosinc.com>
Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
---
 arch/riscv/include/asm/pgtable.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff mbox series

Patch

diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h
index af4337774fe5..0b6c66fb853a 100644
--- a/arch/riscv/include/asm/pgtable.h
+++ b/arch/riscv/include/asm/pgtable.h
@@ -425,6 +425,11 @@  static inline pte_t pte_mkwrite_novma(pte_t pte)
 	return __pte(pte_val(pte) | _PAGE_WRITE);
 }
 
+static inline pte_t pte_mkwrite_shstk(pte_t pte)
+{
+	return __pte((pte_val(pte) & ~(_PAGE_LEAF)) | _PAGE_WRITE);
+}
+
 /* static inline pte_t pte_mkexec(pte_t pte) */
 
 static inline pte_t pte_mkdirty(pte_t pte)
@@ -732,6 +737,11 @@  static inline pmd_t pmd_mkwrite_novma(pmd_t pmd)
 	return pte_pmd(pte_mkwrite_novma(pmd_pte(pmd)));
 }
 
+static inline pmd_t pmd_mkwrite_shstk(pmd_t pte)
+{
+	return __pmd((pmd_val(pte) & ~(_PAGE_LEAF)) | _PAGE_WRITE);
+}
+
 static inline pmd_t pmd_wrprotect(pmd_t pmd)
 {
 	return pte_pmd(pte_wrprotect(pmd_pte(pmd)));