Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

riscv/mm: manufacture shadow stack ptes

This patch implements the creation of a shadow stack pte on
riscv. Creating shadow stack PTE on riscv means clearing RWX and then
setting W=1.

Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Reviewed-by: Zong Li <zong.li@sifive.com>
Signed-off-by: Deepak Gupta <debug@rivosinc.com>
Tested-by: Andreas Korb <andreas.korb@aisec.fraunhofer.de> # QEMU, custom CVA6
Tested-by: Valentin Haudiquet <valentin.haudiquet@canonical.com>
Link: https://patch.msgid.link/20251112-v5_user_cfi_series-v23-7-b55691eacf4f@rivosinc.com
[pjw@kernel.org: cleaned up patch description]
Signed-off-by: Paul Walmsley <pjw@kernel.org>

authored by

Deepak Gupta and committed by
Paul Walmsley
f56ffb8a 6c7559f2

+10
+10
arch/riscv/include/asm/pgtable.h
··· 456 456 return __pte(pte_val(pte) | _PAGE_WRITE); 457 457 } 458 458 459 + static inline pte_t pte_mkwrite_shstk(pte_t pte) 460 + { 461 + return __pte((pte_val(pte) & ~(_PAGE_LEAF)) | _PAGE_WRITE); 462 + } 463 + 459 464 /* static inline pte_t pte_mkexec(pte_t pte) */ 460 465 461 466 static inline pte_t pte_mkdirty(pte_t pte) ··· 842 837 static inline pmd_t pmd_mkwrite_novma(pmd_t pmd) 843 838 { 844 839 return pte_pmd(pte_mkwrite_novma(pmd_pte(pmd))); 840 + } 841 + 842 + static inline pmd_t pmd_mkwrite_shstk(pmd_t pte) 843 + { 844 + return __pmd((pmd_val(pte) & ~(_PAGE_LEAF)) | _PAGE_WRITE); 845 845 } 846 846 847 847 static inline pmd_t pmd_wrprotect(pmd_t pmd)