Summary: | copyin() repeatedly traps on some illegal user addresses on RISC-V | ||
---|---|---|---|
Product: | Base System | Reporter: | Robert Morris <rtm> |
Component: | riscv | Assignee: | Mark Johnston <markj> |
Status: | Closed FIXED | ||
Severity: | Affects Some People | CC: | jrtc27 |
Priority: | --- | ||
Version: | CURRENT | ||
Hardware: | riscv | ||
OS: | Any |
Description
Robert Morris
2022-07-25 23:05:50 UTC
This is a regression in 31218f3209ac ("riscv: Add support for enabling SV48 mode"), right? We do check VIRT_IS_VALID in page_fault_handler and will SIGSEGV the process or panic the kernel depending on which mode faulted, and copyin etc will check the address is for userspace before using it, but they check VM_MAX(_)USER_ADDRESS which is now the SV48 version even when SV39 is in use. Here's a patch which fixes the problem for me: https://reviews.freebsd.org/D35952 (In reply to Mark Johnston from comment #2) This patch eliminates the problem for me as well. A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=828ea49debe34fddf63cb648b9e57871a34158b6 commit 828ea49debe34fddf63cb648b9e57871a34158b6 Author: Mark Johnston <markj@FreeBSD.org> AuthorDate: 2022-07-28 13:38:52 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2022-07-28 18:33:39 +0000 riscv: Avoid passing invalid addresses to pmap_fault() After the addition of SV48 support, VIRT_IS_VALID() did not exclude addresses that are in the SV39 address space hole but not in the SV48 address space hole. This can result in mishandling of accesses to that range when in SV39 mode. Fix the problem by modifying VIRT_IS_VALID() to use the runtime address space bounds. Then, if the address is invalid, and pcb_onfault is set, give vm_fault_trap() a chance to veto the access instead of panicking. PR: 265439 Reviewed by: jhb Reported and tested by: Robert Morris <rtm@lcs.mit.edu> Fixes: 31218f3209ac ("riscv: Add support for enabling SV48 mode") MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D35952 sys/riscv/include/pmap.h | 5 +++++ sys/riscv/include/vmparam.h | 4 ---- sys/riscv/riscv/pmap.c | 2 ++ sys/riscv/riscv/trap.c | 7 ++----- 4 files changed, 9 insertions(+), 9 deletions(-) A commit in branch stable/13 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=2f1cdb1e4883a962ff305f7422495122516983df commit 2f1cdb1e4883a962ff305f7422495122516983df Author: Mark Johnston <markj@FreeBSD.org> AuthorDate: 2022-07-28 13:38:52 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2022-08-04 13:57:15 +0000 riscv: Avoid passing invalid addresses to pmap_fault() After the addition of SV48 support, VIRT_IS_VALID() did not exclude addresses that are in the SV39 address space hole but not in the SV48 address space hole. This can result in mishandling of accesses to that range when in SV39 mode. Fix the problem by modifying VIRT_IS_VALID() to use the runtime address space bounds. Then, if the address is invalid, and pcb_onfault is set, give vm_fault_trap() a chance to veto the access instead of panicking. PR: 265439 Reviewed by: jhb Reported and tested by: Robert Morris <rtm@lcs.mit.edu> Fixes: 31218f3209ac ("riscv: Add support for enabling SV48 mode") Sponsored by: The FreeBSD Foundation (cherry picked from commit 828ea49debe34fddf63cb648b9e57871a34158b6) sys/riscv/include/pmap.h | 5 +++++ sys/riscv/include/vmparam.h | 4 ---- sys/riscv/riscv/pmap.c | 2 ++ sys/riscv/riscv/trap.c | 7 ++----- 4 files changed, 9 insertions(+), 9 deletions(-) Thank you for the report. |