stacktrace: Force USER_DS for stack_trace_save_user()
authorPeter Zijlstra <peterz@infradead.org>
Thu, 18 Jul 2019 08:47:47 +0000 (10:47 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Thu, 18 Jul 2019 14:47:24 +0000 (16:47 +0200)
When walking userspace stacks, USER_DS needs to be set, otherwise
access_ok() will not function as expected.

Reported-by: Vegard Nossum <vegard.nossum@oracle.com>
Reported-by: Eiichi Tsukata <devel@etsukata.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Vegard Nossum <vegard.nossum@oracle.com>
Reviewed-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Link: https://lkml.kernel.org/r/20190718085754.GM3402@hirez.programming.kicks-ass.net
kernel/stacktrace.c

index e6a02b274b737e9d46f6c6816488fef40c72fdb5..f5440abb753291df445a1ce17559fd476d810a15 100644 (file)
@@ -226,12 +226,17 @@ unsigned int stack_trace_save_user(unsigned long *store, unsigned int size)
                .store  = store,
                .size   = size,
        };
+       mm_segment_t fs;
 
        /* Trace user stack if not a kernel thread */
        if (current->flags & PF_KTHREAD)
                return 0;
 
+       fs = get_fs();
+       set_fs(USER_DS);
        arch_stack_walk_user(consume_entry, &c, task_pt_regs(current));
+       set_fs(fs);
+
        return c.len;
 }
 #endif