public inbox for linux-riscv@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] riscv: Allow PROT_WRITE-only mmap()
@ 2022-09-08 17:01 Andrew Bresticker
  2022-09-08 17:21 ` SS JieJi
  2022-09-08 18:50 ` [PATCH v2] riscv: Make mmap() with PROT_WRITE imply PROT_READ Andrew Bresticker
  0 siblings, 2 replies; 12+ messages in thread
From: Andrew Bresticker @ 2022-09-08 17:01 UTC (permalink / raw)
  To: Palmer Dabbelt
  Cc: Paul Walmsley, Atish Patra, Celeste Liu, dram, Ruizhe Pan,
	linux-riscv, linux-kernel, Andrew Bresticker

Commit 2139619bcad7 ("riscv: mmap with PROT_WRITE but no PROT_READ is
invalid") made mmap() return EINVAL if PROT_WRITE was set wihtout
PROT_READ with the justification that a write-only PTE is considered a
reserved PTE permission bit pattern in the privileged spec. This check
is unnecessary since RISC-V defines its protection_map such that PROT_WRITE
maps to the same PTE permissions as PROT_WRITE|PROT_READ, and it is
inconsistent with other architectures that don't support write-only PTEs,
creating a potential software portability issue. Just remove the check
altogether and let PROT_WRITE imply PROT_READ as is the case on other
architectures.

Fixes: 2139619bcad7 ("riscv: mmap with PROT_WRITE but no PROT_READ is invalid")
Signed-off-by: Andrew Bresticker <abrestic@rivosinc.com>
---
 arch/riscv/kernel/sys_riscv.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/arch/riscv/kernel/sys_riscv.c b/arch/riscv/kernel/sys_riscv.c
index 571556bb9261..5d3f2fbeb33c 100644
--- a/arch/riscv/kernel/sys_riscv.c
+++ b/arch/riscv/kernel/sys_riscv.c
@@ -18,9 +18,6 @@ static long riscv_sys_mmap(unsigned long addr, unsigned long len,
 	if (unlikely(offset & (~PAGE_MASK >> page_shift_offset)))
 		return -EINVAL;
 
-	if (unlikely((prot & PROT_WRITE) && !(prot & PROT_READ)))
-		return -EINVAL;
-
 	return ksys_mmap_pgoff(addr, len, prot, flags, fd,
 			       offset >> (PAGE_SHIFT - page_shift_offset));
 }
-- 
2.25.1


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2022-09-09 18:52 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-08 17:01 [PATCH] riscv: Allow PROT_WRITE-only mmap() Andrew Bresticker
2022-09-08 17:21 ` SS JieJi
2022-09-08 17:28   ` SS JieJi
2022-09-08 18:14     ` Andrew Bresticker
2022-09-08 18:50 ` [PATCH v2] riscv: Make mmap() with PROT_WRITE imply PROT_READ Andrew Bresticker
2022-09-08 18:56   ` SS JieJi
2022-09-08 19:18     ` Andrew Bresticker
2022-09-09  3:01   ` Celeste Liu
2022-09-09 11:42     ` Coelacanthus
2022-09-09 15:16       ` Andrew Bresticker
2022-09-09 15:45         ` Celeste Liu
2022-09-09 18:52   ` Atish Patra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox