lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200229125131.536409697dfa78d4db4e0dfc@kernel.org>
Date:   Sat, 29 Feb 2020 12:51:31 +0900
From:   Masami Hiramatsu <mhiramat@...nel.org>
To:     Masami Hiramatsu <mhiramat@...nel.org>
Cc:     Adrian Hunter <adrian.hunter@...el.com>,
        Peter Zijlstra <peterz@...radead.org>,
        Ingo Molnar <mingo@...hat.com>,
        Steven Rostedt <rostedt@...dmis.org>,
        Borislav Petkov <bp@...en8.de>,
        "H . Peter Anvin" <hpa@...or.com>, x86@...nel.org,
        Mark Rutland <mark.rutland@....com>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Mathieu Poirier <mathieu.poirier@...aro.org>,
        Leo Yan <leo.yan@...aro.org>,
        Arnaldo Carvalho de Melo <acme@...nel.org>,
        Jiri Olsa <jolsa@...hat.com>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH V3 04/13] kprobes: Add perf ksymbol events for kprobe
 insn pages

On Sat, 29 Feb 2020 00:11:14 +0900
Masami Hiramatsu <mhiramat@...nel.org> wrote:

> On Fri, 28 Feb 2020 15:51:16 +0200
> Adrian Hunter <adrian.hunter@...el.com> wrote:
> 
> > Symbols are needed for tools to describe instruction addresses. Pages
> > allocated for kprobe's purposes need symbols to be created for them.
> > Add such symbols to be visible via perf ksymbol events.
> > 
> > Signed-off-by: Adrian Hunter <adrian.hunter@...el.com>
> > ---
> >  include/uapi/linux/perf_event.h |  5 +++++
> >  kernel/kprobes.c                | 12 ++++++++++++
> >  2 files changed, 17 insertions(+)
> > 
> > diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
> > index bae9e9d2d897..9b38ac04c110 100644
> > --- a/include/uapi/linux/perf_event.h
> > +++ b/include/uapi/linux/perf_event.h
> > @@ -1031,6 +1031,11 @@ enum perf_event_type {
> >  enum perf_record_ksymbol_type {
> >  	PERF_RECORD_KSYMBOL_TYPE_UNKNOWN	= 0,
> >  	PERF_RECORD_KSYMBOL_TYPE_BPF		= 1,
> > +	/*
> > +	 * Out of line code such as kprobe-replaced instructions or optimized
> > +	 * kprobes.
> > +	 */
> > +	PERF_RECORD_KSYMBOL_TYPE_OOL		= 2,
> >  	PERF_RECORD_KSYMBOL_TYPE_MAX		/* non-ABI */
> >  };
> >  
> > diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> > index 229d1b596690..f880eb2189c0 100644
> > --- a/kernel/kprobes.c
> > +++ b/kernel/kprobes.c
> > @@ -35,6 +35,7 @@
> >  #include <linux/ftrace.h>
> >  #include <linux/cpu.h>
> >  #include <linux/jump_label.h>
> > +#include <linux/perf_event.h>
> >  
> >  #include <asm/sections.h>
> >  #include <asm/cacheflush.h>
> > @@ -184,6 +185,10 @@ kprobe_opcode_t *__get_insn_slot(struct kprobe_insn_cache *c)
> >  	kip->cache = c;
> >  	list_add_rcu(&kip->list, &c->pages);
> >  	slot = kip->insns;
> > +
> > +	/* Record the perf ksymbol register event after adding the page */
> > +	perf_event_ksymbol(PERF_RECORD_KSYMBOL_TYPE_OOL, (u64)kip->insns,
> > +			   PAGE_SIZE, false, c->sym);
> >  out:
> >  	mutex_unlock(&c->mutex);
> >  	return slot;
> > @@ -202,6 +207,13 @@ static int collect_one_slot(struct kprobe_insn_page *kip, int idx)
> >  		 * next time somebody inserts a probe.
> >  		 */
> >  		if (!list_is_singular(&kip->list)) {
> > +			/*
> > +			 * Record perf ksymbol unregister event before removing
> > +			 * the page.
> > +			 */
> > +			perf_event_ksymbol(PERF_RECORD_KSYMBOL_TYPE_OOL,
> > +					   (u64)kip->insns, PAGE_SIZE, true,
> > +					   kip->cache->sym);
> >  			list_del_rcu(&kip->list);
> >  			synchronize_rcu();
> 
> If you think this event should happen after unused the page,
> here is the best position to do that.

Oops, I've mixed up with another synchronization. Ignore it.
This kip should already be safe because all slots are clean here.

Acked-by: Masami Hiramatsu <mhiramat@...nel.org>

Thank you,


-- 
Masami Hiramatsu <mhiramat@...nel.org>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ