riscv: lib: uaccess: fix CSR_STATUS SR_SUM bit
PATCH 1/1 riscv: lib: uaccess: fix CSR_STATUS SR_SUM bit
Since commit 5d8544e2d007 ("RISC-V: Generic library routines and assembly") and commit ebcbd75e3962 ("riscv: Fix the bug in memory access fixup code"), if __clear_user and __copy_user return from an fixup branch, CSR_STATUS SR_SUM bit will be set, it is a vulnerability, so that S-mode memory accesses to pages that are accessible by U-mode will success. Disable S-mode access to U-mode memory should clear SR_SUM bit.
--- arch/riscv/lib/uaccess.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/riscv/lib/uaccess.S +2 -2
@@ -173,11 +173,11 @@ ENTRY(__asm_copy_from_user) ret /* Exception fixup code */ 10: /* Disable access to user memory */ - csrs CSR_STATUS, t6 + csrc CSR_STATUS, t6 mv a0, t5 ret ENDPROC(__asm_copy_to_user) ENDPROC(__asm_copy_from_user) EXPORT_SYMBOL(__asm_copy_to_user)
@@ -225,10 +225,10 @@ ENTRY(__clear_user) j 3b /* Exception fixup code */ 11: /* Disable access to user memory */ - csrs CSR_STATUS, t6 + csrc CSR_STATUS, t6 mv a0, a1 ret ENDPROC(__clear_user) EXPORT_SYMBOL(__clear_user)
Signature · 1 line
2.35.1
Quoted 35 lines
Since commit
5d8544e2d007("RISC-V: Generic library routines and assembly") and commitebcbd75e3962("riscv: Fix the bug in memory access fixup code"), if__clear_userand__copy_userreturn from an fixup branch,CSR_STATUSSR_SUMbit will be set, it is a vulnerability, so that S-mode memory accesses to pages that are accessible by U-mode will success. Disable S-mode access to U-mode memory should clearSR_SUMbit.Fixes 5d8544e2d007 ("RISC-V: Generic library routines and assembly")Fixes ebcbd75e3962 ("riscv: Fix the bug in memory access fixup code")Signed-off-by Chen Lifu <[email protected]>--- arch/riscv/lib/uaccess.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/riscv/lib/uaccess.S +1
-1@@ -173,11 +173,11 @@ ENTRY(__asm_copy_from_user) ret /* Exception fixup code */ 10: /* Disable access to user memory */ - csrs CSR_STATUS, t6 + csrc CSR_STATUS, t6 mv a0, t5 ret ENDPROC(__asm_copy_to_user) ENDPROC(__asm_copy_from_user) EXPORT_SYMBOL(__asm_copy_to_user)@@ -225,10 +225,10 @@ ENTRY(__clear_user) j 3b
arch/riscv/lib/uaccess.S ENTRY(__clear_user) · line 234
Quoted 10 lines
arch/riscv/lib/uaccess.S +1
-1/* Exception fixup code */ 11: /* Disable access to user memory */ - csrs CSR_STATUS, t6 + csrc CSR_STATUS, t6 mv a0, a1 ret ENDPROC(__clear_user) EXPORT_SYMBOL(__clear_user)
friendly ping ...
Quoted 37 lines
Quoted 37 lines
Since commit
5d8544e2d007("RISC-V: Generic library routines and assembly") and commitebcbd75e3962("riscv: Fix the bug in memory access fixup code"), if__clear_userand__copy_userreturn from an fixup branch,CSR_STATUSSR_SUMbit will be set, it is a vulnerability, so that S-mode memory accesses to pages that are accessible by U-mode will success. Disable S-mode access to U-mode memory should clearSR_SUMbit.Fixes 5d8544e2d007 ("RISC-V: Generic library routines and assembly")Fixes ebcbd75e3962 ("riscv: Fix the bug in memory access fixup code")Signed-off-by Chen Lifu <[email protected]>---
arch/riscv/lib/uaccess.S| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)arch/riscv/lib/uaccess.S +0
-0@@ -173,11 +173,11 @@ ENTRY(__asm_copy_from_user)ret
/* Exception fixup code */
10:
/* Disable access to user memory */
- csrsCSR_STATUS, t6
+ csrcCSR_STATUS, t6
mv a0, t5
ret
ENDPROC(__asm_copy_to_user)
ENDPROC(__asm_copy_from_user)
EXPORT_SYMBOL(__asm_copy_to_user)arch/riscv/lib/uaccess.S +0
-0@@ -225,10 +225,10 @@ ENTRY(__clear_user)j 3b
/* Exception fixup code */
11:
/* Disable access to user memory */
- csrsCSR_STATUS, t6
Quoted 9 lines
Quoted 6 lines
+ csrc
CSR_STATUS, t6
mv a0, a1
ret
ENDPROC(__clear_user)
EXPORT_SYMBOL(__clear_user)friendly ping ...
friendly ping ...
Quoted 5 lines
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
.
Quoted 47 lines · chenlifu
Quoted 37 lines
Quoted 37 lines
Since commit
5d8544e2d007("RISC-V: Generic library routines and assembly") and commitebcbd75e3962("riscv: Fix the bug in memory access fixup code"), if__clear_userand__copy_userreturn from an fixup branch,CSR_STATUSSR_SUMbit will be set, it is a vulnerability, so that S-mode memory accesses to pages that are accessible by U-mode will success. Disable S-mode access to U-mode memory should clearSR_SUMbit.Fixes 5d8544e2d007 ("RISC-V: Generic library routines and assembly")Fixes ebcbd75e3962 ("riscv: Fix the bug in memory access fixup code")Signed-off-by Chen Lifu <[email protected]>---
arch/riscv/lib/uaccess.S| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)arch/riscv/lib/uaccess.S +0
-0@@ -173,11 +173,11 @@ ENTRY(__asm_copy_from_user)ret
/* Exception fixup code */
10:
/* Disable access to user memory */
- csrsCSR_STATUS, t6
+ csrcCSR_STATUS, t6
mv a0, t5
ret
ENDPROC(__asm_copy_to_user)
ENDPROC(__asm_copy_from_user)
EXPORT_SYMBOL(__asm_copy_to_user)arch/riscv/lib/uaccess.S +0
-0@@ -225,10 +225,10 @@ ENTRY(__clear_user)j 3b
/* Exception fixup code */
11:
/* Disable access to user memory */
- csrsCSR_STATUS, t6Quoted 9 lines
Quoted 6 lines
+ csrc
CSR_STATUS, t6
mv a0, a1
ret
ENDPROC(__clear_user)
EXPORT_SYMBOL(__clear_user)friendly ping ...
Quoted 8 lines
friendly ping ...
Quoted 5 lines
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
..
friendly ping ...
Quoted 11 lines · Chen Lifu
Since commit
5d8544e2d007("RISC-V: Generic library routines and assembly") and commitebcbd75e3962("riscv: Fix the bug in memory access fixup code"), if__clear_userand__copy_userreturn from an fixup branch,CSR_STATUSSR_SUMbit will be set, it is a vulnerability, so that S-mode memory accesses to pages that are accessible by U-mode will success. Disable S-mode access to U-mode memory should clearSR_SUMbit.Fixes 5d8544e2d007 ("RISC-V: Generic library routines and assembly")Fixes ebcbd75e3962 ("riscv: Fix the bug in memory access fixup code")Signed-off-by Chen Lifu <[email protected]>
I've not run tested this, but it does look correct
Quoted 33 lines
--- arch/riscv/lib/uaccess.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/riscv/lib/uaccess.S +2
-2@@ -173,11 +173,11 @@ ENTRY(__asm_copy_from_user) ret /* Exception fixup code */ 10: /* Disable access to user memory */ - csrs CSR_STATUS, t6 + csrc CSR_STATUS, t6 mv a0, t5 ret ENDPROC(__asm_copy_to_user) ENDPROC(__asm_copy_from_user) EXPORT_SYMBOL(__asm_copy_to_user)@@ -225,10 +225,10 @@ ENTRY(__clear_user) j 3b /* Exception fixup code */ 11: /* Disable access to user memory */ - csrs CSR_STATUS, t6 + csrc CSR_STATUS, t6 mv a0, a1 ret ENDPROC(__clear_user) EXPORT_SYMBOL(__clear_user)
Signature · 9 lines
Ben Dooks http://www.codethink.co.uk/ Senior Engineer Codethink - Providing Genius https://www.codethink.co.uk/privacy.html _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Palmer Dabbelt
maintainerQuoted 34 lines · On Tue, 14 Jun 2022 18:47:14 PDT (-0700), [email protected] wrote:
Since commit
5d8544e2d007("RISC-V: Generic library routines and assembly") and commitebcbd75e3962("riscv: Fix the bug in memory access fixup code"), if__clear_userand__copy_userreturn from an fixup branch,CSR_STATUSSR_SUMbit will be set, it is a vulnerability, so that S-mode memory accesses to pages that are accessible by U-mode will success. Disable S-mode access to U-mode memory should clearSR_SUMbit.Fixes 5d8544e2d007 ("RISC-V: Generic library routines and assembly")Fixes ebcbd75e3962 ("riscv: Fix the bug in memory access fixup code")Signed-off-by Chen Lifu <[email protected]>--- arch/riscv/lib/uaccess.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/riscv/lib/uaccess.S +1
-1@@ -173,11 +173,11 @@ ENTRY(__asm_copy_from_user) ret /* Exception fixup code */ 10: /* Disable access to user memory */ - csrs CSR_STATUS, t6 + csrc CSR_STATUS, t6 mv a0, t5 ret ENDPROC(__asm_copy_to_user) ENDPROC(__asm_copy_from_user) EXPORT_SYMBOL(__asm_copy_to_user)@@ -225,10 +225,10 @@ ENTRY(__clear_user) j 3b
arch/riscv/lib/uaccess.S ENTRY(__clear_user) · line 234
Quoted 10 lines
arch/riscv/lib/uaccess.S +1
-1/* Exception fixup code */ 11: /* Disable access to user memory */ - csrs CSR_STATUS, t6 + csrc CSR_STATUS, t6 mv a0, a1 ret ENDPROC(__clear_user) EXPORT_SYMBOL(__clear_user)
Thanks, this is on for-next (still for 5.20).