Skip to content

Commit 2139619

Browse files
CoelacanthusHexpalmer-dabbelt
authored andcommitted
riscv: mmap with PROT_WRITE but no PROT_READ is invalid
As mentioned in Table 4.5 in RISC-V spec Volume 2 Section 4.3, write but not read is "Reserved for future use.". For now, they are not valid. In the current code, -wx is marked as invalid, but -w- is not marked as invalid. This patch refines that judgment. Reported-by: xctan <xc-tan@outlook.com> Co-developed-by: dram <dramforever@live.com> Signed-off-by: dram <dramforever@live.com> Co-developed-by: Ruizhe Pan <c141028@gmail.com> Signed-off-by: Ruizhe Pan <c141028@gmail.com> Signed-off-by: Celeste Liu <coelacanthus@outlook.com> Link: https://lore.kernel.org/r/PH7PR14MB559464DBDD310E755F5B21E8CEDC9@PH7PR14MB5594.namprd14.prod.outlook.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 8916c90 commit 2139619

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

arch/riscv/kernel/sys_riscv.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ static long riscv_sys_mmap(unsigned long addr, unsigned long len,
1818
if (unlikely(offset & (~PAGE_MASK >> page_shift_offset)))
1919
return -EINVAL;
2020

21-
if ((prot & PROT_WRITE) && (prot & PROT_EXEC))
22-
if (unlikely(!(prot & PROT_READ)))
23-
return -EINVAL;
21+
if (unlikely((prot & PROT_WRITE) && !(prot & PROT_READ)))
22+
return -EINVAL;
2423

2524
return ksys_mmap_pgoff(addr, len, prot, flags, fd,
2625
offset >> (PAGE_SHIFT - page_shift_offset));

0 commit comments

Comments
 (0)