linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
	Fengguang Wu <fengguang.wu@intel.com>,
	linux-kernel@vger.kernel.org, Wang Nan <wangnan0@huawei.com>,
	Ingo Molnar <mingo@redhat.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@redhat.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Will Deacon <will.deacon@arm.com>,
	lkp@01.org, Dmitry Vyukov <dvyukov@google.com>,
	kasan-dev@googlegroups.com, kernel-team@lge.com
Subject: Re: BUG: KASAN: slab-out-of-bounds in perf_callchain_user+0x494/0x530
Date: Wed, 6 Dec 2017 14:40:53 +0100	[thread overview]
Message-ID: <20171206134053.xksmiam2ajmkpmhc@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20171205081156.GB16663@sejong>

On Tue, Dec 05, 2017 at 05:11:56PM +0900, Namhyung Kim wrote:
> From c12126c4ff9835f0899619db3ee7b4a3151ff2bb Mon Sep 17 00:00:00 2001
> From: Namhyung Kim <namhyung@kernel.org>
> Date: Tue, 5 Dec 2017 16:54:50 +0900
> Subject: [PATCH] perf/core: Fix overflow on perf_callchain_entry
> 
> The commit 97c79a38cd45 add a check whether per-event max stack is
> greater than the global max.  But it missed to do it for the first
> event.  So if the event had a stack depth greater than the global max,
> it could overflow the callchain entry list.
> 
> Reported-by: Fengguang Wu <fengguang.wu@intel.com>
> Fixes: 97c79a38cd45 ("perf core: Per event callchain limit")
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Indeed, nice catch.

Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>

Ingo, can you make this happen in perf/urgent ?

> ---
>  kernel/events/callchain.c | 21 ++++++++++++---------
>  1 file changed, 12 insertions(+), 9 deletions(-)
> 
> diff --git a/kernel/events/callchain.c b/kernel/events/callchain.c
> index 1b2be63c8528..e449e23802eb 100644
> --- a/kernel/events/callchain.c
> +++ b/kernel/events/callchain.c
> @@ -119,19 +119,22 @@ int get_callchain_buffers(int event_max_stack)
>  		goto exit;
>  	}
>  
> +	/*
> +	 * If requesting per event more than the global cap,
> +	 * return a different error to help userspace figure this out.
> +	 *
> +	 * And also do it here so that we have &callchain_mutex held.
> +	 */
> +	if (event_max_stack > sysctl_perf_event_max_stack) {
> +		err = -EOVERFLOW;
> +		goto exit;
> +	}
> +
>  	if (count > 1) {
>  		/* If the allocation failed, give up */
>  		if (!callchain_cpus_entries)
>  			err = -ENOMEM;
> -		/*
> -		 * If requesting per event more than the global cap,
> -		 * return a different error to help userspace figure
> -		 * this out.
> -		 *
> -		 * And also do it here so that we have &callchain_mutex held.
> -		 */
> -		if (event_max_stack > sysctl_perf_event_max_stack)
> -			err = -EOVERFLOW;
> +
>  		goto exit;
>  	}
>  
> -- 
> 2.15.0
> 

      parent reply	other threads:[~2017-12-06 13:41 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-30  2:32 BUG: KASAN: slab-out-of-bounds in perf_callchain_user+0x494/0x530 Fengguang Wu
2017-11-30  8:20 ` Peter Zijlstra
2017-11-30 19:37   ` Arnaldo Carvalho de Melo
2017-12-05  8:11     ` Namhyung Kim
2017-12-05 13:37       ` Arnaldo Carvalho de Melo
2017-12-05 14:47         ` Namhyung Kim
2017-12-06 13:47           ` Peter Zijlstra
2017-12-06 14:12             ` Arnaldo Carvalho de Melo
2017-12-06 14:31             ` Namhyung Kim
2017-12-06 15:45               ` Peter Zijlstra
2017-12-06 15:49                 ` Namhyung Kim
2017-12-06 16:39                   ` Peter Zijlstra
2017-12-06 15:46               ` Namhyung Kim
2017-12-06 13:40       ` Peter Zijlstra [this message]

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=20171206134053.xksmiam2ajmkpmhc@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=dvyukov@google.com \
    --cc=fengguang.wu@intel.com \
    --cc=jolsa@redhat.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=kernel-team@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@01.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=wangnan0@huawei.com \
    --cc=will.deacon@arm.com \
    /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;
as well as URLs for NNTP newsgroup(s).