summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCeleste Liu <coelacanthus@outlook.com>2022-05-31 15:56:52 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-08-25 11:38:19 +0200
commitd881c98d0a499ef719ba1776fccfa4ee475d3e1e (patch)
tree276cf8ab1201e4d03bfda5593cba2a402d29b36a
parent333bdb72be1307421da4bf8692f6040f15d8cbb0 (diff)
downloadlinux-d881c98d0a499ef719ba1776fccfa4ee475d3e1e.tar.gz
linux-d881c98d0a499ef719ba1776fccfa4ee475d3e1e.tar.bz2
linux-d881c98d0a499ef719ba1776fccfa4ee475d3e1e.zip
riscv: mmap with PROT_WRITE but no PROT_READ is invalid
[ Upstream commit 2139619bcad7ac44cc8f6f749089120594056613 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--arch/riscv/kernel/sys_riscv.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/arch/riscv/kernel/sys_riscv.c b/arch/riscv/kernel/sys_riscv.c
index 12f8a7fce78b..8a7880b9c433 100644
--- a/arch/riscv/kernel/sys_riscv.c
+++ b/arch/riscv/kernel/sys_riscv.c
@@ -18,9 +18,8 @@ static long riscv_sys_mmap(unsigned long addr, unsigned long len,
if (unlikely(offset & (~PAGE_MASK >> page_shift_offset)))
return -EINVAL;
- if ((prot & PROT_WRITE) && (prot & PROT_EXEC))
- if (unlikely(!(prot & PROT_READ)))
- 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));