archive mirror
 help / color / mirror / Atom feed
From: Andrew Bresticker <>
To: Palmer Dabbelt <>
Cc: Paul Walmsley <>,
	Celeste Liu <>,
	dram <>, Ruizhe Pan <>,,,,
	Andrew Bresticker <>,, Atish Patra <>
Subject: [PATCH v4 2/2] riscv: Allow PROT_WRITE-only mmap()
Date: Thu, 15 Sep 2022 15:37:02 -0400	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

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 we let VM_WRITE imply VM_READ on RISC-V, 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

Note that this also allows PROT_WRITE|PROT_EXEC mappings which were
disallowed prior to the aforementioned commit; PROT_READ is implied in
such mappings as well.

Fixes: 2139619bcad7 ("riscv: mmap with PROT_WRITE but no PROT_READ is invalid")
Cc: <> # v4.19+
Reviewed-by: Atish Patra <>
Signed-off-by: Andrew Bresticker <>
v1 -> v2: Update access_error() to account for write-implies-read
v2 -> v3: Separate into two commits
 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));

linux-riscv mailing list

  parent reply	other threads:[~2022-09-15 19:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-15 19:37 [PATCH v4 0/2] Make mmap() with PROT_WRITE imply PROT_READ Andrew Bresticker
2022-09-15 19:37 ` [PATCH v4 1/2] riscv: Make VM_WRITE imply VM_READ Andrew Bresticker
2022-09-15 19:37 ` Andrew Bresticker [this message]
2022-10-11 17:04 ` [PATCH v4 0/2] Make mmap() with PROT_WRITE imply PROT_READ Conor Dooley
2022-10-13 21:01 ` Palmer Dabbelt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).