mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arun Sharma <asharma@fb.com>
To: linux-kernel@vger.kernel.org
Cc: Arun Sharma <asharma@fb.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@elte.hu>
Subject: [PATCH 2/3] perf, x86: Don't leak kernel data via callchains
Date: Fri, 20 Apr 2012 12:35:26 -0700	[thread overview]
Message-ID: <1334950527-5050-3-git-send-email-asharma@fb.com> (raw)
In-Reply-To: <1334950527-5050-1-git-send-email-asharma@fb.com>

The NMI could fire when the kernel has done set_fs(KERNEL_DS).
Since we're interested in user space stack pointers only,
check against USER_DS explicitly.

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/kernel/cpu/perf_event.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
index 9f98636..ccd8c07 100644
--- a/arch/x86/kernel/cpu/perf_event.c
+++ b/arch/x86/kernel/cpu/perf_event.c
@@ -1803,6 +1803,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
 {
 	struct stack_frame frame;
 	const void __user *fp;
+	mm_segment_t oldfs = get_fs();
 
 	if (perf_guest_cbs && perf_guest_cbs->is_in_guest()) {
 		/* TODO: We don't support guest os callchain now */
@@ -1816,8 +1817,9 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
 	if (!current->mm)
 		return;
 
+	set_fs(USER_DS);
 	if (perf_callchain_user32(regs, entry))
-		return;
+		goto out;
 
 	while (entry->nr < PERF_MAX_STACK_DEPTH) {
 		unsigned long bytes;
@@ -1831,6 +1833,10 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
 		perf_callchain_store(entry, frame.return_address);
 		fp = frame.next_frame;
 	}
+
+out:
+	set_fs(oldfs);
+	return;
 }
 
 unsigned long perf_instruction_pointer(struct pt_regs *regs)
-- 
1.7.8.4


  parent reply	other threads:[~2012-04-20 19:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-20 19:35 [PATCH 0/3] perf: Support multiple stacks (v2) Arun Sharma
2012-04-20 19:35 ` [PATCH 1/3] perf, x86: Allow multiple stacks Arun Sharma
2012-04-20 19:35 ` Arun Sharma [this message]
2012-04-20 19:57   ` [PATCH 2/3] perf, x86: Don't leak kernel data via callchains Linus Torvalds
2012-04-20 19:35 ` [PATCH 3/3] perf: Limit callchains to 127 Arun Sharma

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1334950527-5050-3-git-send-email-asharma@fb.com \
    --to=asharma@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®