* [PATCH] perf: Force USER_DS when recording user stack data.
@ 2018-08-23 22:59 Yabin Cui
2018-08-24 8:56 ` Peter Zijlstra
2018-09-10 12:39 ` [tip:perf/urgent] perf/core: " tip-bot for Yabin Cui
0 siblings, 2 replies; 3+ messages in thread
From: Yabin Cui @ 2018-08-23 22:59 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Alexander Shishkin, Jiri Olsa, Namhyung Kim
Cc: linux-kernel, Yabin Cui
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 <yabinc@google.com>
---
kernel/events/core.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 2a62b96600ad..9bc047421e75 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -5948,6 +5948,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
unsigned long sp;
unsigned int rem;
u64 dyn_size;
+ mm_segment_t fs;
/*
* We dump:
@@ -5965,7 +5966,10 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
/* Data. */
sp = perf_user_stack_pointer(regs);
+ fs = get_fs();
+ set_fs(USER_DS);
rem = __output_copy_user(handle, (void *) sp, dump_size);
+ set_fs(fs);
dyn_size = dump_size - rem;
perf_output_skip(handle, rem);
--
2.19.0.rc0.228.g281dcd1b4d0-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] perf: Force USER_DS when recording user stack data.
2018-08-23 22:59 [PATCH] perf: Force USER_DS when recording user stack data Yabin Cui
@ 2018-08-24 8:56 ` Peter Zijlstra
2018-09-10 12:39 ` [tip:perf/urgent] perf/core: " tip-bot for Yabin Cui
1 sibling, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2018-08-24 8:56 UTC (permalink / raw)
To: Yabin Cui
Cc: Ingo Molnar, Arnaldo Carvalho de Melo, Alexander Shishkin,
Jiri Olsa, Namhyung Kim, linux-kernel
On Thu, Aug 23, 2018 at 03:59:35PM -0700, Yabin Cui wrote:
> 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 <yabinc@google.com>
Ingo, I think this wants a stable tag too; seems to be a corrolary of:
88b0193d9418 ("perf/callchain: Force USER_DS when invoking perf_callchain_user()")
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> ---
> kernel/events/core.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 2a62b96600ad..9bc047421e75 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -5948,6 +5948,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
> unsigned long sp;
> unsigned int rem;
> u64 dyn_size;
> + mm_segment_t fs;
>
> /*
> * We dump:
> @@ -5965,7 +5966,10 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
>
> /* Data. */
> sp = perf_user_stack_pointer(regs);
> + fs = get_fs();
> + set_fs(USER_DS);
> rem = __output_copy_user(handle, (void *) sp, dump_size);
> + set_fs(fs);
> dyn_size = dump_size - rem;
>
> perf_output_skip(handle, rem);
> --
> 2.19.0.rc0.228.g281dcd1b4d0-goog
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [tip:perf/urgent] perf/core: Force USER_DS when recording user stack data
2018-08-23 22:59 [PATCH] perf: Force USER_DS when recording user stack data Yabin Cui
2018-08-24 8:56 ` Peter Zijlstra
@ 2018-09-10 12:39 ` tip-bot for Yabin Cui
1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Yabin Cui @ 2018-09-10 12:39 UTC (permalink / raw)
To: linux-tip-commits
Cc: torvalds, hpa, stable, yabinc, peterz, linux-kernel, namhyung,
tglx, jolsa, alexander.shishkin, mingo, acme
Commit-ID: 02e184476eff848273826c1d6617bb37e5bcc7ad
Gitweb: https://git.kernel.org/tip/02e184476eff848273826c1d6617bb37e5bcc7ad
Author: Yabin Cui <yabinc@google.com>
AuthorDate: Thu, 23 Aug 2018 15:59:35 -0700
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Mon, 10 Sep 2018 14:01:46 +0200
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 <yabinc@google.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: <stable@vger.kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Fixes: 88b0193d9418 ("perf/callchain: Force USER_DS when invoking perf_callchain_user()")
Link: http://lkml.kernel.org/r/20180823225935.27035-1-yabinc@google.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
kernel/events/core.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index abaed4f8bb7f..c80549bf82c6 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -5943,6 +5943,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
unsigned long sp;
unsigned int rem;
u64 dyn_size;
+ mm_segment_t fs;
/*
* We dump:
@@ -5960,7 +5961,10 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
/* Data. */
sp = perf_user_stack_pointer(regs);
+ fs = get_fs();
+ set_fs(USER_DS);
rem = __output_copy_user(handle, (void *) sp, dump_size);
+ set_fs(fs);
dyn_size = dump_size - rem;
perf_output_skip(handle, rem);
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-09-10 12:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-23 22:59 [PATCH] perf: Force USER_DS when recording user stack data Yabin Cui
2018-08-24 8:56 ` Peter Zijlstra
2018-09-10 12:39 ` [tip:perf/urgent] perf/core: " tip-bot for Yabin Cui
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).