All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] perf: Support multiple stacks (v3)
@ 2012-04-20 22:41 Arun Sharma
  2012-04-20 22:41 ` [PATCH 1/4] perf, x86: Allow multiple stacks Arun Sharma
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Arun Sharma @ 2012-04-20 22:41 UTC (permalink / raw)
  To: linux-kernel; +Cc: Arun Sharma

If userspace has two or more stacks and we happen to take a sample when
the stack pointer is pointing to a higher stack, we get truncated
callchains. This patch series tries to address that.

Changelog:

v3: add explicit checks to copy_from_user_nmi
v3: add explicit checks in perf_callchain_user*

v2: do this for compat32 as well
v2: improve safety checks and reduce max callchain size


Arun Sharma (4):
  perf, x86: Allow multiple stacks
  perf: Limit callchains to 127
  perf, x86: Check if user fp is valid
  x86: Check user address explicitly in copy_from_user_nmi()

 arch/x86/include/asm/uaccess.h   |   13 +++++++------
 arch/x86/kernel/cpu/perf_event.c |   11 +++++++++--
 arch/x86/lib/usercopy.c          |    3 +++
 include/linux/perf_event.h       |    2 +-
 4 files changed, 20 insertions(+), 9 deletions(-)

-- 
1.7.8.4


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/4] perf, x86: Allow multiple stacks
  2012-04-20 22:41 [PATCH 0/4] perf: Support multiple stacks (v3) Arun Sharma
@ 2012-04-20 22:41 ` Arun Sharma
  2012-05-07 23:46     ` Arun Sharma
  2012-06-06 16:02   ` [tip:perf/core] perf/x86: " tip-bot for Arun Sharma
  2012-04-20 22:41 ` [PATCH 2/4] perf: Limit callchains to 127 Arun Sharma
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 12+ messages in thread
From: Arun Sharma @ 2012-04-20 22:41 UTC (permalink / raw)
  To: linux-kernel
  Cc: Arun Sharma, Ingo Molnar, Arnaldo Carvalho de Melo,
	Frederic Weisbecker, Mike Galbraith, Paul Mackerras,
	Peter Zijlstra, Stephane Eranian, Namhyung Kim, Tom Zanussi,
	linux-perf-users

Without this patch, applications with two different stack
regions (eg: native stack vs JIT stack) get truncated
callchains even when RBP chaining is present. GDB shows proper
stack traces and the frame pointer chaining is intact.

This patch disables the (fp < RSP) check, hoping that other checks
in the code save the day for us. In our limited testing, this
didn't seem to break anything.

In the long term, we could potentially have userspace advise
the kernel on the range of valid stack addresses, so we don't
spend a lot of time unwinding from bogus addresses.

Signed-off-by: Arun Sharma <asharma@fb.com>
Cc: Ingo Molnar <mingo@elte.hu>
CC: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-perf-users@vger.kernel.org
---
 arch/x86/kernel/cpu/perf_event.c |    6 ------
 1 files changed, 0 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index bb8e034..9f98636 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -1785,9 +1785,6 @@ perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry *entry)
 		if (bytes != sizeof(frame))
 			break;
 
-		if (fp < compat_ptr(regs->sp))
-			break;
-
 		perf_callchain_store(entry, frame.return_address);
 		fp = compat_ptr(frame.next_frame);
 	}
@@ -1831,9 +1828,6 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
 		if (bytes != sizeof(frame))
 			break;
 
-		if ((unsigned long)fp < regs->sp)
-			break;
-
 		perf_callchain_store(entry, frame.return_address);
 		fp = frame.next_frame;
 	}
-- 
1.7.8.4


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/4] perf: Limit callchains to 127
  2012-04-20 22:41 [PATCH 0/4] perf: Support multiple stacks (v3) Arun Sharma
  2012-04-20 22:41 ` [PATCH 1/4] perf, x86: Allow multiple stacks Arun Sharma
@ 2012-04-20 22:41 ` Arun Sharma
  2012-06-06 16:03   ` [tip:perf/core] " tip-bot for Arun Sharma
  2012-04-20 22:41 ` [PATCH 3/4] perf, x86: Check if user fp is valid Arun Sharma
  2012-04-20 22:41 ` [PATCH 4/4] x86: Check user address explicitly in copy_from_user_nmi() Arun Sharma
  3 siblings, 1 reply; 12+ messages in thread
From: Arun Sharma @ 2012-04-20 22:41 UTC (permalink / raw)
  To: linux-kernel; +Cc: Arun Sharma, Linus Torvalds, Peter Zijlstra, Ingo Molnar

Stack depth of 255 seems excessive, given that copy_from_user_nmi()
could be slow.

Signed-off-by: Arun Sharma <asharma@fb.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: linux-kernel@vger.kernel.org
---
 include/linux/perf_event.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index ddbb6a9..d1e71c1 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -609,7 +609,7 @@ struct perf_guest_info_callbacks {
 #include <linux/sysfs.h>
 #include <asm/local.h>
 
-#define PERF_MAX_STACK_DEPTH		255
+#define PERF_MAX_STACK_DEPTH		127
 
 struct perf_callchain_entry {
 	__u64				nr;
-- 
1.7.8.4


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/4] perf, x86: Check if user fp is valid
  2012-04-20 22:41 [PATCH 0/4] perf: Support multiple stacks (v3) Arun Sharma
  2012-04-20 22:41 ` [PATCH 1/4] perf, x86: Allow multiple stacks Arun Sharma
  2012-04-20 22:41 ` [PATCH 2/4] perf: Limit callchains to 127 Arun Sharma
@ 2012-04-20 22:41 ` Arun Sharma
  2012-06-06 16:03   ` [tip:perf/core] perf/x86: " tip-bot for Arun Sharma
  2012-04-20 22:41 ` [PATCH 4/4] x86: Check user address explicitly in copy_from_user_nmi() Arun Sharma
  3 siblings, 1 reply; 12+ messages in thread
From: Arun Sharma @ 2012-04-20 22:41 UTC (permalink / raw)
  To: linux-kernel; +Cc: Arun Sharma, Linus Torvalds, Peter Zijlstra, Ingo Molnar

Signed-off-by: Arun Sharma <asharma@fb.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: linux-kernel@vger.kernel.org
---
 arch/x86/include/asm/uaccess.h   |   13 +++++++------
 arch/x86/kernel/cpu/perf_event.c |   12 ++++++++++++
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
index e054459..997d59b 100644
--- a/arch/x86/include/asm/uaccess.h
+++ b/arch/x86/include/asm/uaccess.h
@@ -32,9 +32,9 @@
 
 #define segment_eq(a, b)	((a).seg == (b).seg)
 
-#define __addr_ok(addr)					\
-	((unsigned long __force)(addr) <		\
-	 (current_thread_info()->addr_limit.seg))
+#define __cur_addr_limit	(current_thread_info()->addr_limit.seg)
+#define __addr_ok(addr) 	\
+	((unsigned long __force)(addr) < __cur_addr_limit)
 
 /*
  * Test whether a block of memory is a valid user space address.
@@ -46,14 +46,14 @@
  * This needs 33-bit (65-bit for x86_64) arithmetic. We have a carry...
  */
 
-#define __range_not_ok(addr, size)					\
+#define __range_not_ok(addr, size, limit)				\
 ({									\
 	unsigned long flag, roksum;					\
 	__chk_user_ptr(addr);						\
 	asm("add %3,%1 ; sbb %0,%0 ; cmp %1,%4 ; sbb $0,%0"		\
 	    : "=&r" (flag), "=r" (roksum)				\
 	    : "1" (addr), "g" ((long)(size)),				\
-	      "rm" (current_thread_info()->addr_limit.seg));		\
+	      "rm" (limit));						\
 	flag;								\
 })
 
@@ -76,7 +76,8 @@
  * checks that the pointer is in the user space range - after calling
  * this function, memory access functions may still return -EFAULT.
  */
-#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
+#define access_ok(type, addr, size) \
+	(likely(__range_not_ok(addr, size, __cur_addr_limit) == 0))
 
 /*
  * The exception table consists of pairs of addresses: the first is the
diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index 9f98636..3e4be2c 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -1761,6 +1761,12 @@ perf_callchain_kernel(struct perf_callchain_entry *entry, struct pt_regs *regs)
 	dump_trace(NULL, regs, NULL, 0, &backtrace_ops, entry);
 }
 
+static inline int
+valid_user_frame(const void __user *fp, unsigned long size)
+{
+	return (__range_not_ok(fp, size, TASK_SIZE) == 0);
+}
+
 #ifdef CONFIG_COMPAT
 
 #include <asm/compat.h>
@@ -1785,6 +1791,9 @@ perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry *entry)
 		if (bytes != sizeof(frame))
 			break;
 
+		if (!valid_user_frame(fp, sizeof(frame)))
+			break;
+
 		perf_callchain_store(entry, frame.return_address);
 		fp = compat_ptr(frame.next_frame);
 	}
@@ -1828,6 +1837,9 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
 		if (bytes != sizeof(frame))
 			break;
 
+		if (!valid_user_frame(fp, sizeof(frame)))
+			break;
+
 		perf_callchain_store(entry, frame.return_address);
 		fp = frame.next_frame;
 	}
-- 
1.7.8.4


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 4/4] x86: Check user address explicitly in copy_from_user_nmi()
  2012-04-20 22:41 [PATCH 0/4] perf: Support multiple stacks (v3) Arun Sharma
                   ` (2 preceding siblings ...)
  2012-04-20 22:41 ` [PATCH 3/4] perf, x86: Check if user fp is valid Arun Sharma
@ 2012-04-20 22:41 ` Arun Sharma
  2012-06-05 16:55   ` Peter Zijlstra
  2012-06-06 16:04   ` [tip:perf/core] perf/x86: " tip-bot for Arun Sharma
  3 siblings, 2 replies; 12+ messages in thread
From: Arun Sharma @ 2012-04-20 22:41 UTC (permalink / raw)
  To: linux-kernel; +Cc: Arun Sharma, Linus Torvalds, Peter Zijlstra, Ingo Molnar

Signed-off-by: Arun Sharma <asharma@fb.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: linux-kernel@vger.kernel.org
---
 arch/x86/lib/usercopy.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/arch/x86/lib/usercopy.c b/arch/x86/lib/usercopy.c
index d6ae30b..2da7914 100644
--- a/arch/x86/lib/usercopy.c
+++ b/arch/x86/lib/usercopy.c
@@ -21,6 +21,9 @@ copy_from_user_nmi(void *to, const void __user *from, unsigned long n)
 	void *map;
 	int ret;
 
+	if (__range_not_ok(from, n, TASK_SIZE) == 0)
+		return len;
+
 	do {
 		ret = __get_user_pages_fast(addr, 1, 0, &page);
 		if (!ret)
-- 
1.7.8.4


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/4] perf, x86: Allow multiple stacks
  2012-04-20 22:41 ` [PATCH 1/4] perf, x86: Allow multiple stacks Arun Sharma
@ 2012-05-07 23:46     ` Arun Sharma
  2012-06-06 16:02   ` [tip:perf/core] perf/x86: " tip-bot for Arun Sharma
  1 sibling, 0 replies; 12+ messages in thread
From: Arun Sharma @ 2012-05-07 23:46 UTC (permalink / raw)
  To: linux-kernel
  Cc: Ingo Molnar, Arnaldo Carvalho de Melo, Frederic Weisbecker,
	Mike Galbraith, Paul Mackerras, Peter Zijlstra, Stephane Eranian,
	Namhyung Kim, Tom Zanussi, linux-perf-users

On 4/20/12 3:41 PM, Arun Sharma wrote:
> Without this patch, applications with two different stack
> regions (eg: native stack vs JIT stack) get truncated
> callchains even when RBP chaining is present. GDB shows proper
> stack traces and the frame pointer chaining is intact.
>
> This patch disables the (fp<  RSP) check, hoping that other checks
> in the code save the day for us. In our limited testing, this
> didn't seem to break anything.
>
> In the long term, we could potentially have userspace advise
> the kernel on the range of valid stack addresses, so we don't
> spend a lot of time unwinding from bogus addresses.

Ingo/Peter: Did you get a chance to look at this patch series (Support 
multiple stacks v3)?

  -Arun

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/4] perf, x86: Allow multiple stacks
@ 2012-05-07 23:46     ` Arun Sharma
  0 siblings, 0 replies; 12+ messages in thread
From: Arun Sharma @ 2012-05-07 23:46 UTC (permalink / raw)
  To: linux-kernel
  Cc: Ingo Molnar, Arnaldo Carvalho de Melo, Frederic Weisbecker,
	Mike Galbraith, Paul Mackerras, Peter Zijlstra, Stephane Eranian,
	Namhyung Kim, Tom Zanussi, linux-perf-users

On 4/20/12 3:41 PM, Arun Sharma wrote:
> Without this patch, applications with two different stack
> regions (eg: native stack vs JIT stack) get truncated
> callchains even when RBP chaining is present. GDB shows proper
> stack traces and the frame pointer chaining is intact.
>
> This patch disables the (fp<  RSP) check, hoping that other checks
> in the code save the day for us. In our limited testing, this
> didn't seem to break anything.
>
> In the long term, we could potentially have userspace advise
> the kernel on the range of valid stack addresses, so we don't
> spend a lot of time unwinding from bogus addresses.

Ingo/Peter: Did you get a chance to look at this patch series (Support 
multiple stacks v3)?

  -Arun

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 4/4] x86: Check user address explicitly in copy_from_user_nmi()
  2012-04-20 22:41 ` [PATCH 4/4] x86: Check user address explicitly in copy_from_user_nmi() Arun Sharma
@ 2012-06-05 16:55   ` Peter Zijlstra
  2012-06-06 16:04   ` [tip:perf/core] perf/x86: " tip-bot for Arun Sharma
  1 sibling, 0 replies; 12+ messages in thread
From: Peter Zijlstra @ 2012-06-05 16:55 UTC (permalink / raw)
  To: Arun Sharma; +Cc: linux-kernel, Linus Torvalds, Ingo Molnar

On Fri, 2012-04-20 at 15:41 -0700, Arun Sharma wrote:
> Signed-off-by: Arun Sharma <asharma@fb.com>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Ingo Molnar <mingo@elte.hu>
> Cc: linux-kernel@vger.kernel.org
> ---
>  arch/x86/lib/usercopy.c |    3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/x86/lib/usercopy.c b/arch/x86/lib/usercopy.c
> index d6ae30b..2da7914 100644
> --- a/arch/x86/lib/usercopy.c
> +++ b/arch/x86/lib/usercopy.c
> @@ -21,6 +21,9 @@ copy_from_user_nmi(void *to, const void __user *from, unsigned long n)
>  	void *map;
>  	int ret;
>  
> +	if (__range_not_ok(from, n, TASK_SIZE) == 0)
> +		return len;
> +
>  	do {
>  		ret = __get_user_pages_fast(addr, 1, 0, &page);
>  		if (!ret)

Needed the below to make it compile.. folded that.

---
--- a/arch/x86/lib/usercopy.c
+++ b/arch/x86/lib/usercopy.c
@@ -8,6 +8,7 @@
 #include <linux/module.h>
 
 #include <asm/word-at-a-time.h>
+#include <linux/sched.h>
 
 /*
  * best effort, GUP based copy_from_user() that is NMI-safe


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [tip:perf/core] perf/x86: Allow multiple stacks
  2012-04-20 22:41 ` [PATCH 1/4] perf, x86: Allow multiple stacks Arun Sharma
  2012-05-07 23:46     ` Arun Sharma
@ 2012-06-06 16:02   ` tip-bot for Arun Sharma
  1 sibling, 0 replies; 12+ messages in thread
From: tip-bot for Arun Sharma @ 2012-06-06 16:02 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, eranian, paulus, acme, hpa, mingo, tzanussi,
	a.p.zijlstra, efault, namhyung.kim, fweisbec, tglx, asharma

Commit-ID:  302fa4b58ac754a6da13f4f5546f710fecc3b945
Gitweb:     http://git.kernel.org/tip/302fa4b58ac754a6da13f4f5546f710fecc3b945
Author:     Arun Sharma <asharma@fb.com>
AuthorDate: Fri, 20 Apr 2012 15:41:33 -0700
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 6 Jun 2012 17:07:58 +0200

perf/x86: Allow multiple stacks

Without this patch, applications with two different stack
regions (eg: native stack vs JIT stack) get truncated
callchains even when RBP chaining is present. GDB shows proper
stack traces and the frame pointer chaining is intact.

This patch disables the (fp < RSP) check, hoping that other checks
in the code save the day for us. In our limited testing, this
didn't seem to break anything.

In the long term, we could potentially have userspace advise
the kernel on the range of valid stack addresses, so we don't
spend a lot of time unwinding from bogus addresses.

Signed-off-by: Arun Sharma <asharma@fb.com>
CC: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-perf-users@vger.kernel.org
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1334961696-19580-2-git-send-email-asharma@fb.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/cpu/perf_event.c |    6 ------
 1 files changed, 0 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index cb60838..e78bc25 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -1781,9 +1781,6 @@ perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry *entry)
 		if (bytes != sizeof(frame))
 			break;
 
-		if (fp < compat_ptr(regs->sp))
-			break;
-
 		perf_callchain_store(entry, frame.return_address);
 		fp = compat_ptr(frame.next_frame);
 	}
@@ -1827,9 +1824,6 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
 		if (bytes != sizeof(frame))
 			break;
 
-		if ((unsigned long)fp < regs->sp)
-			break;
-
 		perf_callchain_store(entry, frame.return_address);
 		fp = frame.next_frame;
 	}

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [tip:perf/core] perf: Limit callchains to 127
  2012-04-20 22:41 ` [PATCH 2/4] perf: Limit callchains to 127 Arun Sharma
@ 2012-06-06 16:03   ` tip-bot for Arun Sharma
  0 siblings, 0 replies; 12+ messages in thread
From: tip-bot for Arun Sharma @ 2012-06-06 16:03 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, a.p.zijlstra, torvalds, tglx, asharma

Commit-ID:  0b0d9cf6ec7bab91977da2d71c09157f110f7c2e
Gitweb:     http://git.kernel.org/tip/0b0d9cf6ec7bab91977da2d71c09157f110f7c2e
Author:     Arun Sharma <asharma@fb.com>
AuthorDate: Fri, 20 Apr 2012 15:41:34 -0700
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 6 Jun 2012 17:08:00 +0200

perf: Limit callchains to 127

Stack depth of 255 seems excessive, given that copy_from_user_nmi()
could be slow.

Signed-off-by: Arun Sharma <asharma@fb.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1334961696-19580-3-git-send-email-asharma@fb.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 include/linux/perf_event.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 1817d40..45db49f 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -555,7 +555,7 @@ enum perf_event_type {
 	PERF_RECORD_MAX,			/* non-ABI */
 };
 
-#define PERF_MAX_STACK_DEPTH		255
+#define PERF_MAX_STACK_DEPTH		127
 
 enum perf_callchain_context {
 	PERF_CONTEXT_HV			= (__u64)-32,

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [tip:perf/core] perf/x86: Check if user fp is valid
  2012-04-20 22:41 ` [PATCH 3/4] perf, x86: Check if user fp is valid Arun Sharma
@ 2012-06-06 16:03   ` tip-bot for Arun Sharma
  0 siblings, 0 replies; 12+ messages in thread
From: tip-bot for Arun Sharma @ 2012-06-06 16:03 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, a.p.zijlstra, torvalds, tglx, asharma

Commit-ID:  bc6ca7b342d5ae15c3ba3081fd40271b8039fb25
Gitweb:     http://git.kernel.org/tip/bc6ca7b342d5ae15c3ba3081fd40271b8039fb25
Author:     Arun Sharma <asharma@fb.com>
AuthorDate: Fri, 20 Apr 2012 15:41:35 -0700
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 6 Jun 2012 17:08:01 +0200

perf/x86: Check if user fp is valid

Signed-off-by: Arun Sharma <asharma@fb.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1334961696-19580-4-git-send-email-asharma@fb.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/uaccess.h   |   12 ++++++------
 arch/x86/kernel/cpu/perf_event.c |   12 ++++++++++++
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
index 04cd688..e1f3a17 100644
--- a/arch/x86/include/asm/uaccess.h
+++ b/arch/x86/include/asm/uaccess.h
@@ -33,9 +33,8 @@
 #define segment_eq(a, b)	((a).seg == (b).seg)
 
 #define user_addr_max() (current_thread_info()->addr_limit.seg)
-#define __addr_ok(addr)					\
-	((unsigned long __force)(addr) <		\
-	 (current_thread_info()->addr_limit.seg))
+#define __addr_ok(addr) 	\
+	((unsigned long __force)(addr) < user_addr_max())
 
 /*
  * Test whether a block of memory is a valid user space address.
@@ -47,14 +46,14 @@
  * This needs 33-bit (65-bit for x86_64) arithmetic. We have a carry...
  */
 
-#define __range_not_ok(addr, size)					\
+#define __range_not_ok(addr, size, limit)				\
 ({									\
 	unsigned long flag, roksum;					\
 	__chk_user_ptr(addr);						\
 	asm("add %3,%1 ; sbb %0,%0 ; cmp %1,%4 ; sbb $0,%0"		\
 	    : "=&r" (flag), "=r" (roksum)				\
 	    : "1" (addr), "g" ((long)(size)),				\
-	      "rm" (current_thread_info()->addr_limit.seg));		\
+	      "rm" (limit));						\
 	flag;								\
 })
 
@@ -77,7 +76,8 @@
  * checks that the pointer is in the user space range - after calling
  * this function, memory access functions may still return -EFAULT.
  */
-#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
+#define access_ok(type, addr, size) \
+	(likely(__range_not_ok(addr, size, user_addr_max()) == 0))
 
 /*
  * The exception table consists of pairs of addresses relative to the
diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index e78bc25..c4706cf 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -1757,6 +1757,12 @@ perf_callchain_kernel(struct perf_callchain_entry *entry, struct pt_regs *regs)
 	dump_trace(NULL, regs, NULL, 0, &backtrace_ops, entry);
 }
 
+static inline int
+valid_user_frame(const void __user *fp, unsigned long size)
+{
+	return (__range_not_ok(fp, size, TASK_SIZE) == 0);
+}
+
 #ifdef CONFIG_COMPAT
 
 #include <asm/compat.h>
@@ -1781,6 +1787,9 @@ perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry *entry)
 		if (bytes != sizeof(frame))
 			break;
 
+		if (!valid_user_frame(fp, sizeof(frame)))
+			break;
+
 		perf_callchain_store(entry, frame.return_address);
 		fp = compat_ptr(frame.next_frame);
 	}
@@ -1824,6 +1833,9 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
 		if (bytes != sizeof(frame))
 			break;
 
+		if (!valid_user_frame(fp, sizeof(frame)))
+			break;
+
 		perf_callchain_store(entry, frame.return_address);
 		fp = frame.next_frame;
 	}

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [tip:perf/core] perf/x86: Check user address explicitly in copy_from_user_nmi()
  2012-04-20 22:41 ` [PATCH 4/4] x86: Check user address explicitly in copy_from_user_nmi() Arun Sharma
  2012-06-05 16:55   ` Peter Zijlstra
@ 2012-06-06 16:04   ` tip-bot for Arun Sharma
  1 sibling, 0 replies; 12+ messages in thread
From: tip-bot for Arun Sharma @ 2012-06-06 16:04 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, a.p.zijlstra, torvalds, tglx, asharma

Commit-ID:  db0dc75d6403b6663c0eab4c6ccb672eb9b2ed72
Gitweb:     http://git.kernel.org/tip/db0dc75d6403b6663c0eab4c6ccb672eb9b2ed72
Author:     Arun Sharma <asharma@fb.com>
AuthorDate: Fri, 20 Apr 2012 15:41:36 -0700
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 6 Jun 2012 17:08:04 +0200

perf/x86: Check user address explicitly in copy_from_user_nmi()

Signed-off-by: Arun Sharma <asharma@fb.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1334961696-19580-5-git-send-email-asharma@fb.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/lib/usercopy.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/arch/x86/lib/usercopy.c b/arch/x86/lib/usercopy.c
index f61ee67..677b1ed 100644
--- a/arch/x86/lib/usercopy.c
+++ b/arch/x86/lib/usercopy.c
@@ -8,6 +8,7 @@
 #include <linux/module.h>
 
 #include <asm/word-at-a-time.h>
+#include <linux/sched.h>
 
 /*
  * best effort, GUP based copy_from_user() that is NMI-safe
@@ -21,6 +22,9 @@ copy_from_user_nmi(void *to, const void __user *from, unsigned long n)
 	void *map;
 	int ret;
 
+	if (__range_not_ok(from, n, TASK_SIZE) == 0)
+		return len;
+
 	do {
 		ret = __get_user_pages_fast(addr, 1, 0, &page);
 		if (!ret)

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2012-06-06 16:05 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-20 22:41 [PATCH 0/4] perf: Support multiple stacks (v3) Arun Sharma
2012-04-20 22:41 ` [PATCH 1/4] perf, x86: Allow multiple stacks Arun Sharma
2012-05-07 23:46   ` Arun Sharma
2012-05-07 23:46     ` Arun Sharma
2012-06-06 16:02   ` [tip:perf/core] perf/x86: " tip-bot for Arun Sharma
2012-04-20 22:41 ` [PATCH 2/4] perf: Limit callchains to 127 Arun Sharma
2012-06-06 16:03   ` [tip:perf/core] " tip-bot for Arun Sharma
2012-04-20 22:41 ` [PATCH 3/4] perf, x86: Check if user fp is valid Arun Sharma
2012-06-06 16:03   ` [tip:perf/core] perf/x86: " tip-bot for Arun Sharma
2012-04-20 22:41 ` [PATCH 4/4] x86: Check user address explicitly in copy_from_user_nmi() Arun Sharma
2012-06-05 16:55   ` Peter Zijlstra
2012-06-06 16:04   ` [tip:perf/core] perf/x86: " tip-bot for Arun Sharma

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.