Received: by 10.192.165.148 with SMTP id m20csp530727imm; Wed, 25 Apr 2018 03:46:25 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq3IY924+xv+fGicFG3A5tjm+51BQtgT5g9D3p4npAaBYfleS2JprDtqX0IXUng1oo8Y+aC X-Received: by 10.99.65.197 with SMTP id o188mr5787692pga.280.1524653185697; Wed, 25 Apr 2018 03:46:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524653185; cv=none; d=google.com; s=arc-20160816; b=ujzMJ+q/I1psEHTZ88sxnkxiO83f69DLIDrUSfLaMzs8Pc6jceRz/N/PuvMiZt3KLD 4kpb0OZ9gTaXXcHoGJNaidrwzNKhhY3hFDjQYFQrfNGF+hJKrpBFs8p7Qx/9GWRtaPn4 1dmU7V4FJdepp8MEfaF6o3kLftLHpytQvHHDoIu9YWl/5SDXE5zG6WWoFkK4RutsF9zE rkpci8VydPieLct3Nz1yOhU7srNfMg4Q7k5kX8VRiR/kAAR6FQ8QvBLGVuGBwLDBcOYJ j52F2CVve1GjBs1zmyVMz4b8Ye07PKrC3MSWkXLNNTR290A1oTNxxD3HjbmCCEJkoYlF 1O+A== 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=lX1FAT/JLS7kL7/nACWHFrUlJeh2fPDvPr45y8oUIAA=; b=OYt90ckUHH33d84ed2PHeJkOQv/IZ2hBuTQs8Hs0M38PG03Y7UNgyJDl0IKOqYcTPx 9b26estUUyHTMZ5yQxS/NjQbQ0Um6P7q+oMN/R7TRTOFKkTPWh1lUEEJhGD0UEFX9a5V V4LWOvkkaTuWghvpxd9U7hEZL5bwgmM50bWRbQ+N1A46nQKNzLsnIWSSaauV6CIdxr7C JTJ3yVAsI0qmGzgkY+Q92byQpcXRp5u7wAWHGAjzJ9WLPReaOfNK3xz8g/oJLGYgn+JT I21o/jreE0jQdEFjPNUaN3d3dbc/4tVMe2zzG86kzAVXD6ZW4SCGmVoMyrtKnwkpigZK nEqA== 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 r12si11772623pfk.83.2018.04.25.03.46.11; Wed, 25 Apr 2018 03:46:25 -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 S1754483AbeDYKpB (ORCPT + 99 others); Wed, 25 Apr 2018 06:45:01 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:53420 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754451AbeDYKov (ORCPT ); Wed, 25 Apr 2018 06:44:51 -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 784F536; Wed, 25 Apr 2018 10:44:50 +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.14 179/183] perf: Fix sample_max_stack maximum check Date: Wed, 25 Apr 2018 12:36:39 +0200 Message-Id: <20180425103249.693866587@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425103242.532713678@linuxfoundation.org> References: <20180425103242.532713678@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.14-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; }