All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Prashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>
Cc: Oleg Nesterov <oleg@redhat.com>, Ingo Molnar <mingo@redhat.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: uprobes/perf: KASAN: use-after-free in uprobe_perf_close
Date: Mon, 9 Apr 2018 09:38:27 +0200	[thread overview]
Message-ID: <20180409073827.GS4082@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <35f890f7-1194-4509-a1e4-d63d1c7d22ab@lab.ntt.co.jp>

On Tue, Mar 06, 2018 at 06:49:10PM +0900, Prashant Bhole wrote:
> Sorry for late reply. I tried these changes. It didn't fix the problem. With

He, sorry for completely forgetting about this one :/

> these changes, the use-after-free access of task_struct occurs at
> _free_event() for the last remaining event.
> 
> In your changes, I tried keeping get/put_task_struct() in
> perf_alloc_context()/put_ctx() intact and The problem did not occur. Changes
> are mentioned below.

Yes, I think you're right in that this is the cleanest solution; it adds
reference counting to the exact pointer we're using.

> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index c98cce4ceebd..65889d2b5ae2 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -4109,6 +4109,8 @@ static void _free_event(struct perf_event *event)
> 
>  	if (event->ctx)
>  		put_ctx(event->ctx);
> +	if (event->hw.target)
> +		put_task_struct(event->hw.target);
> 
>  	exclusive_event_destroy(event);
>  	module_put(event->pmu->module);
> @@ -9593,6 +9595,7 @@ perf_event_alloc(struct perf_event_attr *attr, int
> cpu,
>  		 * and we cannot use the ctx information because we need the
>  		 * pmu before we get a ctx.
>  		 */
> +		get_task_struct(task);
>  		event->hw.target = task;
>  	}
> 
> @@ -9708,6 +9711,8 @@ perf_event_alloc(struct perf_event_attr *attr, int
> cpu,
>  		perf_detach_cgroup(event);
>  	if (event->ns)
>  		put_pid_ns(event->ns);
> +	if (task)

Should this not too be 'event->hw.target', for consistency and clarity?

> +		put_task_struct(task);
>  	kfree(event);
> 
>  	return ERR_PTR(err);

  reply	other threads:[~2018-04-09  7:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-22  5:08 uprobes/perf: KASAN: use-after-free in uprobe_perf_close Prashant Bhole
2018-02-22 16:37 ` Oleg Nesterov
2018-02-22 17:04   ` Peter Zijlstra
2018-02-22 17:09     ` Peter Zijlstra
2018-02-22 17:40       ` Oleg Nesterov
2018-03-06  9:49         ` Prashant Bhole
2018-04-09  7:38           ` Peter Zijlstra [this message]
2018-04-09 10:00             ` Prashant Bhole
2018-04-09 10:40             ` Oleg Nesterov
2018-04-09 11:40               ` Peter Zijlstra
2018-02-22 17:49     ` Oleg Nesterov

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=20180409073827.GS4082@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=bhole_prashant_q7@lab.ntt.co.jp \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=oleg@redhat.com \
    --cc=rostedt@goodmis.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 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.