Received: by 10.192.165.148 with SMTP id m20csp524306imm; Wed, 25 Apr 2018 03:38:50 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+Xzh/QrPHIxnIIpYKVJ5W8KxVum9vnXh8bEIHepkzJnDKo51cZXVnGVF2fo9T986UFMDL2 X-Received: by 10.101.75.202 with SMTP id p10mr23577830pgr.339.1524652730134; Wed, 25 Apr 2018 03:38:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524652730; cv=none; d=google.com; s=arc-20160816; b=oviYiDdlIPaF/67zCsUC3hbA9GAbApo55VY34vMTBaBp2iI9prf4U9WYsOzFQp1niR nzZtA1+pXGlmIquqiVSrwUsx5B0eAQbER122qMWcEsJweVBz9i3lRjljtDN2PeBg7qop SUBiW8vY3moooy3I8UdBrMm4HeohZs90UxFi4fiw5SpitFdz+nacmQntDNIMK/scjUu+ kT5m5MZCsxUO8YDU8DUcQJsuIv2GDgvTVC6F4QxhGHUdNNgU91o5Lp+49LQfg5z5Iw+v HRBu0/EjQNYDZkAWgkAATD+sDxbxwEjQzOui7H1Z4Ip0on0BEs2uyZf44vr91ApnnimN 8gSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=R8Tmc870lRaxpoF+a1ueEg6UHr2FhtNYsjYq/gr59Mo=; b=or/HhDsfbJ9867AT/ApTYbegk5Qz0+q6SjM9DWLUV8R/EQHjxat2SRxLcz5f4AAEZn uFeFXQ7pWDisKnZOtGNzTKL/3E2O3QF8xbsWNtUTvQQ1q1kbfsiKBr5IgIKJWRSOJBZo 3g4UAWogbLSXcnE3fU+Ev0I4ybmUvCc0cTVxE4aT9+Wqou9K2DcOXmAFfPIYb342zuQn KnE0QBPjvGvCRHgEsBc+UmXk+wGoTJ6a4wm9pKhODYkdj1Eb76pzmvTB63CZ4t/UZYnM D+bPU8pHhM1fUshYLGXQj5j2X1uxe/FEnqM0irx+h4d9cs0cN5+ysELZRN34tSSjg5QF RtTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r3-v6si17787752pli.324.2018.04.25.03.38.36; Wed, 25 Apr 2018 03:38:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751974AbeDYKgs (ORCPT + 99 others); Wed, 25 Apr 2018 06:36:48 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:50876 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752797AbeDYKed (ORCPT ); Wed, 25 Apr 2018 06:34:33 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id D749649B; Wed, 25 Apr 2018 10:34:31 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+7c449856228b63ac951e@syzkaller.appspotmail.com, Jiri Olsa , Alexander Shishkin , Andi Kleen , "H. Peter Anvin" , Namhyung Kim , Peter Zijlstra , Thomas Gleixner , syzkaller-bugs@googlegroups.com, x86@kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH 4.16 23/26] perf: Fix sample_max_stack maximum check Date: Wed, 25 Apr 2018 12:33:32 +0200 Message-Id: <20180425103315.768833894@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425103314.842517924@linuxfoundation.org> References: <20180425103314.842517924@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiri Olsa commit 5af44ca53d019de47efe6dbc4003dd518e5197ed upstream. 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 Cc: Alexander Shishkin Cc: Andi Kleen Cc: H. Peter Anvin Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Thomas Gleixner 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 Signed-off-by: Greg Kroah-Hartman --- kernel/events/callchain.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) --- a/kernel/events/callchain.c +++ b/kernel/events/callchain.c @@ -119,19 +119,22 @@ int get_callchain_buffers(int event_max_ 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; }