aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2018-04-15 05:23:51 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2018-04-17 08:47:40 -0400
commit5af44ca53d019de47efe6dbc4003dd518e5197ed (patch)
tree4cbc50c2ff819adbbb4cd27648576ae9709b6e32
parent78b562fbfa2cf0a9fcb23c3154756b690f4905c1 (diff)
perf: Fix sample_max_stack maximum check
The syzbot hit KASAN bug in perf_callchain_store having the entry stored behind the allocated bounds [1]. We miss the sample_max_stack check for the initial event that allocates callchain buffers. This missing check allows to create an event with sample_max_stack value bigger than the global sysctl maximum: # sysctl -a | grep perf_event_max_stack kernel.perf_event_max_stack = 127 # perf record -vv -C 1 -e cycles/max-stack=256/ kill ... perf_event_attr: size 112 ... sample_max_stack 256 ------------------------------------------------------------ sys_perf_event_open: pid -1 cpu 1 group_fd -1 flags 0x8 = 4 Note the '-C 1', which forces perf record to create just single event. Otherwise it opens event for every cpu, then the sample_max_stack check fails on the second event and all's fine. The fix is to run the sample_max_stack check also for the first event with callchains. [1] https://marc.info/?l=linux-kernel&m=152352732920874&w=2 Reported-by: syzbot+7c449856228b63ac951e@syzkaller.appspotmail.com Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <andi@firstfloor.org> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: syzkaller-bugs@googlegroups.com Cc: x86@kernel.org Fixes: 97c79a38cd45 ("perf core: Per event callchain limit") Link: http://lkml.kernel.org/r/20180415092352.12403-2-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--kernel/events/callchain.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/kernel/events/callchain.c b/kernel/events/callchain.c
index 772a43fea825..73cc26e321de 100644
--- a/kernel/events/callchain.c
+++ b/kernel/events/callchain.c
@@ -119,19 +119,22 @@ int get_callchain_buffers(int event_max_stack)
119 goto exit; 119 goto exit;
120 } 120 }
121 121
122 /*
123 * If requesting per event more than the global cap,
124 * return a different error to help userspace figure
125 * this out.
126 *
127 * And also do it here so that we have &callchain_mutex held.
128 */
129 if (event_max_stack > sysctl_perf_event_max_stack) {
130 err = -EOVERFLOW;
131 goto exit;
132 }
133
122 if (count > 1) { 134 if (count > 1) {
123 /* If the allocation failed, give up */ 135 /* If the allocation failed, give up */
124 if (!callchain_cpus_entries) 136 if (!callchain_cpus_entries)
125 err = -ENOMEM; 137 err = -ENOMEM;
126 /*
127 * If requesting per event more than the global cap,
128 * return a different error to help userspace figure
129 * this out.
130 *
131 * And also do it here so that we have &callchain_mutex held.
132 */
133 if (event_max_stack > sysctl_perf_event_max_stack)
134 err = -EOVERFLOW;
135 goto exit; 138 goto exit;
136 } 139 }
137 140