Skip to content

Commit

Permalink
riscv: lib: uaccess: fix CSR_STATUS SR_SUM bit
Browse files Browse the repository at this point in the history
Since commit 5d8544e ("RISC-V: Generic library routines and assembly")
and commit ebcbd75 ("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.

Fixes: 5d8544e ("RISC-V: Generic library routines and assembly")
Fixes: ebcbd75 ("riscv: Fix the bug in memory access fixup code")
Signed-off-by: Chen Lifu <chenlifu@huawei.com>
Reviewed-by: Ben Dooks <ben.dooks@codethink.co.uk>
Link: https://lore.kernel.org/r/20220615014714.1650349-1-chenlifu@huawei.com
Cc: stable@vger.kernel.org
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
  • Loading branch information
Chen Lifu authored and Palmer Dabbelt committed Aug 10, 2022
1 parent 4d1044f commit c08b484
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions arch/riscv/lib/uaccess.S
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ ENTRY(__asm_copy_from_user)
/* 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)
Expand Down Expand Up @@ -227,7 +227,7 @@ ENTRY(__clear_user)
/* Exception fixup code */
11:
/* Disable access to user memory */
csrs CSR_STATUS, t6
csrc CSR_STATUS, t6
mv a0, a1
ret
ENDPROC(__clear_user)
Expand Down

0 comments on commit c08b484

Please sign in to comment.