Skip to content

Commit 6569fc1

Browse files
woodrow-shenpalmer-dabbelt
authored andcommitted
riscv: mm: Ensure prot of VM_WRITE and VM_EXEC must be readable
Commit 8aeb7b1 ("RISC-V: Make mmap() with PROT_WRITE imply PROT_READ") allows riscv to use mmap with PROT_WRITE only, and meanwhile mmap with w+x is also permitted. However, when userspace tries to access this page with PROT_WRITE|PROT_EXEC, which causes infinite loop at load page fault as well as it triggers soft lockup. According to riscv privileged spec, "Writable pages must also be marked readable". The fix to drop the `PAGE_COPY_READ_EXEC` and then `PAGE_COPY_EXEC` would be just used instead. This aligns the other arches (i.e arm64) for protection_map. Fixes: 8aeb7b1 ("RISC-V: Make mmap() with PROT_WRITE imply PROT_READ") Signed-off-by: Hsieh-Tseng Shen <[email protected]> Reviewed-by: Alexandre Ghiti <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 6966d79 commit 6569fc1

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

arch/riscv/include/asm/pgtable.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,7 @@ extern struct pt_alloc_ops pt_ops __initdata;
165165
_PAGE_EXEC | _PAGE_WRITE)
166166

167167
#define PAGE_COPY PAGE_READ
168-
#define PAGE_COPY_EXEC PAGE_EXEC
169-
#define PAGE_COPY_READ_EXEC PAGE_READ_EXEC
168+
#define PAGE_COPY_EXEC PAGE_READ_EXEC
170169
#define PAGE_SHARED PAGE_WRITE
171170
#define PAGE_SHARED_EXEC PAGE_WRITE_EXEC
172171

arch/riscv/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ static const pgprot_t protection_map[16] = {
293293
[VM_EXEC] = PAGE_EXEC,
294294
[VM_EXEC | VM_READ] = PAGE_READ_EXEC,
295295
[VM_EXEC | VM_WRITE] = PAGE_COPY_EXEC,
296-
[VM_EXEC | VM_WRITE | VM_READ] = PAGE_COPY_READ_EXEC,
296+
[VM_EXEC | VM_WRITE | VM_READ] = PAGE_COPY_EXEC,
297297
[VM_SHARED] = PAGE_NONE,
298298
[VM_SHARED | VM_READ] = PAGE_READ,
299299
[VM_SHARED | VM_WRITE] = PAGE_SHARED,

0 commit comments

Comments
 (0)