git: 698af78e7809 - stable/13 - dtrace_asm.S: properly enter/exit user access

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Wed, 15 Feb 2023 16:43:05 UTC
The branch stable/13 has been updated by mhorne:

URL: https://cgit.FreeBSD.org/src/commit/?id=698af78e78093aed0b84f1e5d396e127ae13f52c

commit 698af78e78093aed0b84f1e5d396e127ae13f52c
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2023-02-06 18:04:21 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2023-02-15 16:41:39 +0000

    dtrace_asm.S: properly enter/exit user access
    
    In order to read or write userspace memory without generating an access
    fault, we must first enable the SUM bit in the sstatus CSR.
    
    Reviewed by:    markj
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D38298
    
    (cherry picked from commit 0e563bde48b1af6bd472e940f04a8d76315749ab)
---
 sys/cddl/dev/dtrace/riscv/dtrace_asm.S | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/sys/cddl/dev/dtrace/riscv/dtrace_asm.S b/sys/cddl/dev/dtrace/riscv/dtrace_asm.S
index eeaf64061675..98c22a2aedfd 100644
--- a/sys/cddl/dev/dtrace/riscv/dtrace_asm.S
+++ b/sys/cddl/dev/dtrace/riscv/dtrace_asm.S
@@ -74,7 +74,9 @@ uint8_t
 dtrace_fuword8_nocheck(void *addr)
 */
 ENTRY(dtrace_fuword8_nocheck)
+	ENTER_USER_ACCESS(t0)
 	lb	a0, 0(a0)
+	EXIT_USER_ACCESS(t0)
 	RET
 END(dtrace_fuword8_nocheck)
 
@@ -83,7 +85,9 @@ uint16_t
 dtrace_fuword16_nocheck(void *addr)
 */
 ENTRY(dtrace_fuword16_nocheck)
+	ENTER_USER_ACCESS(t0)
 	lh	a0, 0(a0)
+	EXIT_USER_ACCESS(t0)
 	RET
 END(dtrace_fuword16_nocheck)
 
@@ -92,7 +96,9 @@ uint32_t
 dtrace_fuword32_nocheck(void *addr)
 */
 ENTRY(dtrace_fuword32_nocheck)
+	ENTER_USER_ACCESS(t0)
 	lw	a0, 0(a0)
+	EXIT_USER_ACCESS(t0)
 	RET
 END(dtrace_fuword32_nocheck)
 
@@ -101,7 +107,9 @@ uint64_t
 dtrace_fuword64_nocheck(void *addr)
 */
 ENTRY(dtrace_fuword64_nocheck)
+	ENTER_USER_ACCESS(t0)
 	ld	a0, 0(a0)
+	EXIT_USER_ACCESS(t0)
 	RET
 END(dtrace_fuword64_nocheck)
 
@@ -111,6 +119,7 @@ dtrace_copy(uintptr_t uaddr, uintptr_t kaddr, size_t size)
 */
 ENTRY(dtrace_copy)
 	beqz	a2, 2f		/* If len == 0 then skip loop */
+	ENTER_USER_ACCESS(t0)
 1:
 	lb	a4, 0(a0)	/* Load from uaddr */
 	addi	a0, a0, 1
@@ -118,6 +127,7 @@ ENTRY(dtrace_copy)
 	addi	a1, a1, 1
 	addi	a2, a2, -1	/* len-- */
 	bnez	a2, 1b
+	EXIT_USER_ACCESS(t0)
 2:
 	RET
 END(dtrace_copy)
@@ -129,7 +139,9 @@ dtrace_copystr(uintptr_t uaddr, uintptr_t kaddr, size_t size,
 XXX: Check for flags?
 */
 ENTRY(dtrace_copystr)
-	beqz	a2, 2f		/* If len == 0 then skip loop */
+	beqz	a2, 3f		/* If len == 0 then skip loop */
+	ENTER_USER_ACCESS(t0)
+1:
 	lb	a4, 0(a0)	/* Load from uaddr */
 	addi	a0, a0, 1
 	sb	a4, 0(a1)	/* Store in kaddr */
@@ -138,6 +150,8 @@ ENTRY(dtrace_copystr)
 	addi	a2, a2, -1	/* len-- */
 	bnez	a2, 1b
 2:
+	EXIT_USER_ACCESS(t0)
+3:
 	RET
 END(dtrace_copystr)