]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
riscv: disable SUM in the exception handler
authorChristoph Hellwig <hch@lst.de>
Thu, 4 Jan 2018 18:55:55 +0000 (19:55 +0100)
committerPalmer Dabbelt <palmer@dabbelt.com>
Wed, 31 Jan 2018 03:12:38 +0000 (19:12 -0800)
The SUM bit is enabled at the beginning of the copy_{to,from}_user and
{get,put}_user routines, and cleared before they return.  But these user
copy helper can be interrupted by exceptions, in which case the SUM bit
will remain set, which leads to elevated privileges for the code running
in exception context, as that can now access userspace address space
unconditionally.  This frequently happens when the user copy routines
access freshly allocated user memory that hasn't been faulted in, and a
pagefault needs to be taken before the user copy routines can continue.

Fix this by unconditionally clearing SUM when the exception handler is
called - the restore code will automatically restore it based on the
saved value.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
arch/riscv/kernel/entry.S

index 7404ec222406290ed03c671a3b4463c61aa49c12..87fc045be51fa8078f5176de0f384c79a4a687c5 100644 (file)
@@ -78,10 +78,13 @@ _save_context:
        REG_S x31, PT_T6(sp)
 
        /*
-        * Disable FPU to detect illegal usage of
-        * floating point in kernel space
+        * Disable user-mode memory access as it should only be set in the
+        * actual user copy routines.
+        *
+        * Disable the FPU to detect illegal usage of floating point in kernel
+        * space.
         */
-       li t0, SR_FS
+       li t0, SR_SUM | SR_FS
 
        REG_L s0, TASK_TI_USER_SP(tp)
        csrrc s1, sstatus, t0