RISC-V: Don't allow write+exec only page mapping request in mmap
authorYash Shah <yash.shah@sifive.com>
Tue, 16 Jun 2020 14:03:06 +0000 (19:33 +0530)
committerSasha Levin <sashal@kernel.org>
Tue, 30 Jun 2020 19:36:19 +0000 (15:36 -0400)
commit1c1549e363a1386c9a66f394dfda2cbeefbe3dfc
tree9ba3e198b57168612da3b3ddce0306e937d428be
parentf6f7d573f8a18174c0c8c90d7e778f12846cd97d
RISC-V: Don't allow write+exec only page mapping request in mmap

[ Upstream commit e0d17c842c0f824fd4df9f4688709fc6907201e1 ]

As per the table 4.4 of version "20190608-Priv-MSU-Ratified" of the
RISC-V instruction set manual[0], the PTE permission bit combination of
"write+exec only" is reserved for future use. Hence, don't allow such
mapping request in mmap call.

An issue is been reported by David Abdurachmanov, that while running
stress-ng with "sysbadaddr" argument, RCU stalls are observed on RISC-V
specific kernel.

This issue arises when the stress-sysbadaddr request for pages with
"write+exec only" permission bits and then passes the address obtain
from this mmap call to various system call. For the riscv kernel, the
mmap call should fail for this particular combination of permission bits
since it's not valid.

[0]: http://dabbelt.com/~palmer/keep/riscv-isa-manual/riscv-privileged-20190608-1.pdf

Signed-off-by: Yash Shah <yash.shah@sifive.com>
Reported-by: David Abdurachmanov <david.abdurachmanov@gmail.com>
[Palmer: Refer to the latest ISA specification at the only link I could
find, and update the terminology.]
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/riscv/kernel/sys_riscv.c