summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorWill Deacon <will.deacon@arm.com>2017-05-09 18:00:04 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-04-13 19:47:54 +0200
commit5daab7259a6ec50415c1dcfb1a3ef3302f9281f6 (patch)
tree63f72d18d31f1be652e27f045a72302e615e67d3 /kernel
parent6ed24ef46757007f3f8f0dd342bbfbb16bf92bf7 (diff)
perf/callchain: Force USER_DS when invoking perf_callchain_user()
[ Upstream commit 88b0193d9418c00340e45e0a913a0813bc6c8c96 ] Perf can generate and record a user callchain in response to a synchronous request, such as a tracepoint firing. If this happens under set_fs(KERNEL_DS), then we can end up walking the user stack (and dereferencing/saving whatever we find there) without the protections usually afforded by checks such as access_ok. Rather than play whack-a-mole with each architecture's stack unwinding implementation, fix the root of the problem by ensuring that we force USER_DS when invoking perf_callchain_user from the perf core. Reported-by: Al Viro <viro@ZenIV.linux.org.uk> Signed-off-by: Will Deacon <will.deacon@arm.com> Acked-by: Peter Zijlstra <peterz@infradead.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Sasha Levin <alexander.levin@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/events/callchain.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/kernel/events/callchain.c b/kernel/events/callchain.c
index e9fdb5203de5..411226b26bca 100644
--- a/kernel/events/callchain.c
+++ b/kernel/events/callchain.c
@@ -227,12 +227,18 @@ get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
}
if (regs) {
+ mm_segment_t fs;
+
if (crosstask)
goto exit_put;
if (add_mark)
perf_callchain_store_context(&ctx, PERF_CONTEXT_USER);
+
+ fs = get_fs();
+ set_fs(USER_DS);
perf_callchain_user(&ctx, regs);
+ set_fs(fs);
}
}