Skip to content

Commit 02e1844

Browse files
yabincIngo Molnar
authored andcommitted
perf/core: Force USER_DS when recording user stack data
Perf can record user stack data in response to a synchronous request, such as a tracepoint firing. If this happens under set_fs(KERNEL_DS), then we end up reading user stack data using __copy_from_user_inatomic() under set_fs(KERNEL_DS). I think this conflicts with the intention of using set_fs(KERNEL_DS). And it is explicitly forbidden by hardware on ARM64 when both CONFIG_ARM64_UAO and CONFIG_ARM64_PAN are used. So fix this by forcing USER_DS when recording user stack data. Signed-off-by: Yabin Cui <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Cc: <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Fixes: 88b0193 ("perf/callchain: Force USER_DS when invoking perf_callchain_user()") Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 0912125 commit 02e1844

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

kernel/events/core.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5943,6 +5943,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
59435943
unsigned long sp;
59445944
unsigned int rem;
59455945
u64 dyn_size;
5946+
mm_segment_t fs;
59465947

59475948
/*
59485949
* We dump:
@@ -5960,7 +5961,10 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
59605961

59615962
/* Data. */
59625963
sp = perf_user_stack_pointer(regs);
5964+
fs = get_fs();
5965+
set_fs(USER_DS);
59635966
rem = __output_copy_user(handle, (void *) sp, dump_size);
5967+
set_fs(fs);
59645968
dyn_size = dump_size - rem;
59655969

59665970
perf_output_skip(handle, rem);

0 commit comments

Comments
 (0)