mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Stephane Eranian <eranian@google.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	"mingo@elte.hu" <mingo@elte.hu>,
	"ak@linux.intel.com" <ak@linux.intel.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	David Ahern <dsahern@gmail.com>, Jiri Olsa <jolsa@redhat.com>,
	Hugh Dickins <hughd@google.com>,
	Kees Cook <keescook@chromium.org>
Subject: Re: [RFC] perf: mmap2 not covering VM_CLONE regions
Date: Wed, 2 Oct 2013 13:23:16 +0200	[thread overview]
Message-ID: <20131002112316.GP3081@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <CABPqkBS_zDkgX4NioducZ+H9VEt1jb7gQDbZ_zB6ui5Tf=UR5A@mail.gmail.com>

On Tue, Oct 01, 2013 at 01:22:58PM +0200, Stephane Eranian wrote:
> > So the problem is that we don't have a user visible address space
> > identifier; with CLONE_THREAD we have the thread group id that acts
> > like this. But for bare CLONE_VM usage there's nothing afaik.
> 
> 
> From the tool's perspective, the MMAP2 record must contain enough information
> to identify that the mapping points to the same physical pages in that
> particular
> case (multi-process + VM_CLONE). As we have it now all inode-related fields
> are zero which is useless (indicates: no info). In other words, we need to make
> up some unique number and stash it in the maj.min,ino triplet somehow.

So the only thing I can come up with is something like the below;
supposedly the sha hash mixing a boot time random seed and the mm
pointer is enough to avoid it being a data leak.

And of course there's the possibility of a collision.

---
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -39,11 +39,15 @@
 #include <linux/hw_breakpoint.h>
 #include <linux/mm_types.h>
 #include <linux/cgroup.h>
+#include <linux/random.h>
+#include <linux/cryptohash.h>
 
 #include "internal.h"
 
 #include <asm/irq_regs.h>
 
+static u64 __perf_rand_seed;
+
 struct remote_function_call {
 	struct task_struct	*p;
 	int			(*func)(void *info);
@@ -5136,6 +5140,33 @@ static void perf_event_mmap_event(struct
 		min = MINOR(dev);
 
 	} else {
+		union {
+			struct {
+				u64 ino, gen;
+				u32 min;
+			};
+			u32 digest[SHA_DIGEST_WORDS];
+		} hash;
+		union {
+			struct {
+				u64 seed;
+				u64 ptr;
+			};
+			u8 message[SHA_MESSAGE_BYTES];
+		} data;
+		u32 workspace[SHA_WORKSPACE_WORDS];
+
+		memset(&data, 0, sizeof(data));
+		data.seed = __perf_rand_seed;
+		data.ptr = (u64)vma->vm_mm;
+
+		sha_init(hash.digest);
+		sha_transform(hash.digest, data.message, workspace);
+
+		gen = hash.gen;
+		ino = hash.ino;
+		min = hash.min;
+
 		if (arch_vma_name(mmap_event->vma)) {
 			name = strncpy(tmp, arch_vma_name(mmap_event->vma),
 				       sizeof(tmp) - 1);
@@ -7895,6 +7926,8 @@ void __init perf_event_init(void)
 	/* do not patch jump label more than once per second */
 	jump_label_rate_limit(&perf_sched_events, HZ);
 
+	get_random_bytes(&__perf_rand_seed, sizeof(__perf_rand_seed));
+
 	/*
 	 * Build time assertion that we keep the data_head at the intended
 	 * location.  IOW, validation we got the __reserved[] size right.

  reply	other threads:[~2013-10-02 11:23 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-30 15:44 Stephane Eranian
2013-09-30 16:15 ` Peter Zijlstra
2013-09-30 16:48   ` Stephane Eranian
2013-09-30 16:54     ` Peter Zijlstra
2013-10-01 11:22       ` Stephane Eranian
2013-10-02 11:23         ` Peter Zijlstra [this message]
2013-10-02 11:58           ` Peter Zijlstra
2013-10-02 12:39             ` Ingo Molnar
2013-10-02 12:46               ` Peter Zijlstra
2013-10-02 12:59                 ` Stephane Eranian
2013-10-02 13:01                   ` Peter Zijlstra
2013-10-02 13:13                     ` Stephane Eranian
2013-10-02 13:37                       ` Peter Zijlstra
2013-10-02 17:14                         ` Kees Cook
2013-10-02 17:20                           ` Stephane Eranian
2013-10-02 17:29                             ` Kees Cook
2013-10-02 17:49                               ` Stephane Eranian
2013-10-02 18:10                                 ` Kees Cook
2013-10-02 19:00                                   ` Peter Zijlstra
2013-10-02 19:38                                     ` Kees Cook
2013-10-02 20:31                                       ` Peter Zijlstra
2013-10-03  8:55                                         ` Stephane Eranian
2013-10-03  9:03                                           ` Peter Zijlstra
2013-10-03  9:13                                             ` Stephane Eranian
2013-10-03 15:34                                               ` Kees Cook
2013-10-07 21:04                                             ` Stephane Eranian
2013-10-08  6:54                                               ` Peter Zijlstra
2013-10-08  7:15                                                 ` Stephane Eranian
2013-10-08  9:36                                                   ` Peter Zijlstra
2013-10-08  9:42                                                     ` Stephane Eranian
2013-10-08  9:54                                                       ` Peter Zijlstra
2013-10-03 18:32                                           ` Andi Kleen
2013-10-07 11:16                     ` Stephane Eranian
2013-10-07 11:32                       ` Peter Zijlstra
2013-10-02 15:22                 ` Ingo Molnar
2013-10-08 14:23 ` David Ahern
2013-10-08 19:41   ` Ingo Molnar
2013-10-08 19:54     ` Stephane Eranian
2013-10-08 19:57       ` David Ahern
2013-10-09  9:54         ` Ingo Molnar
2013-10-09  9:59       ` Ingo Molnar
2013-10-09 10:39         ` Peter Zijlstra

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=20131002112316.GP3081@twins.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=acme@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=dsahern@gmail.com \
    --cc=eranian@google.com \
    --cc=hughd@google.com \
    --cc=jolsa@redhat.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /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

Powered by JetHome