]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
nds32: use get_kernel_nofault in dump_mem
authorChristoph Hellwig <hch@lst.de>
Mon, 20 Jul 2020 11:44:48 +0000 (13:44 +0200)
committerGreentime Hu <green.hu@gmail.com>
Thu, 25 Feb 2021 06:31:49 +0000 (14:31 +0800)
Use the proper get_kernel_nofault helper to access an unsafe kernel
pointer without faulting instead of playing with set_fs and get_user.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Nick Hu <nickhu@andestech.com>
Acked-by: Greentime Hu <green.hu@gmail.com>
Signed-off-by: Greentime Hu <green.hu@gmail.com>
arch/nds32/kernel/traps.c

index b66f889bc6df9bf7d089ee18e2014bb5ae3577c5..ee0d9ae192a5041a8a6494b93f9373f5876737fe 100644 (file)
@@ -25,17 +25,8 @@ extern void show_pte(struct mm_struct *mm, unsigned long addr);
 void dump_mem(const char *lvl, unsigned long bottom, unsigned long top)
 {
        unsigned long first;
-       mm_segment_t fs;
        int i;
 
-       /*
-        * We need to switch to kernel mode so that we can use __get_user
-        * to safely read from kernel space.  Note that we now dump the
-        * code first, just in case the backtrace kills us.
-        */
-       fs = get_fs();
-       set_fs(KERNEL_DS);
-
        pr_emerg("%s(0x%08lx to 0x%08lx)\n", lvl, bottom, top);
 
        for (first = bottom & ~31; first < top; first += 32) {
@@ -48,7 +39,9 @@ void dump_mem(const char *lvl, unsigned long bottom, unsigned long top)
                for (p = first, i = 0; i < 8 && p < top; i++, p += 4) {
                        if (p >= bottom && p < top) {
                                unsigned long val;
-                               if (__get_user(val, (unsigned long *)p) == 0)
+
+                               if (get_kernel_nofault(val,
+                                               (unsigned long *)p) == 0)
                                        sprintf(str + i * 9, " %08lx", val);
                                else
                                        sprintf(str + i * 9, " ????????");
@@ -56,8 +49,6 @@ void dump_mem(const char *lvl, unsigned long bottom, unsigned long top)
                }
                pr_emerg("%s%04lx:%s\n", lvl, first & 0xffff, str);
        }
-
-       set_fs(fs);
 }
 
 EXPORT_SYMBOL(dump_mem);