Received: by 10.192.165.148 with SMTP id m20csp827366imm; Fri, 27 Apr 2018 08:08:13 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoY5QLsX46tFH496hZ9rPM3QRNoE065UkDXh8oQmo0ThztQN/zb/l8YOCUmOc4Ck9EjXcio X-Received: by 10.98.14.198 with SMTP id 67mr2562236pfo.36.1524841693336; Fri, 27 Apr 2018 08:08:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524841693; cv=none; d=google.com; s=arc-20160816; b=wQVzadet38eb6dDHCy64dV5xpHxgeF1oqrqiEYuXcoLBP8qnxE/g56NQi+jaQS60kB x8QdDIZ7JGjujazrtq+OLmviYWACZEiSpB6c52sisUTNABGzeced4iX/W0nxsLMAWlbO Twc6zRGpycgdd/QxFfei+XsqLx8kTaxX/yvBcjIsZAXWgXuaHSvGtNVRVfJpsX8p/Ryv 5jh3fSXetKNAsDFKpW4CpALYyykN45qmv7LnWUlGpSSOWDNdh0prUG94hbC5HGZsKKwb Ig5Ud6AHwkXQ1O57ENVLo1kA1quyU9LgSwSyO81JhH7iM1OZ5EpjHwykZkWvClVyEQU+ +1cw== 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:dmarc-filter :arc-authentication-results; bh=jni9b+A83E0BeytYzgde98ADEv1X1baDDp4qc8QIvZY=; b=B+b920ig+qsCRZMBloKklZ583H1VP+7+1vLz0XYiDwh4R3ber/7Pdd+Xci9XGbQ/qn tv7xdCEY2lnndxHfozY6/VDxuqgb/bgZbkga4AHpeNBgmO2vWxkO0OwWA2av8GJzRAb3 u4nqWHRPaFvln4odD0t4omOAEFOWlLd2koHn0Ja5U7YkemkGPbuwbT93aNnWvmECFOgt PUahmXxJY0N7vZvjh4WRTKzFF+Nmy+5DZt3ZIVFfpe0bANtRcw3MlXKv+J/xpy1/yN79 jy/CXuCgE+yIVj4sSLmPxm5OcJgntsC5GKG3Q3PDeDQFaNDv0m+W8+Bcbb+DVCxRdMrW Dd1g== 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 x1-v6si1374853plb.8.2018.04.27.08.07.58; Fri, 27 Apr 2018 08:08:13 -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 S933883AbeD0PG5 (ORCPT + 99 others); Fri, 27 Apr 2018 11:06:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:51032 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933754AbeD0OEo (ORCPT ); Fri, 27 Apr 2018 10:04:44 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 791B7218A2; Fri, 27 Apr 2018 14:04:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 791B7218A2 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=gregkh@linuxfoundation.org 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.9 19/74] perf: Fix sample_max_stack maximum check Date: Fri, 27 Apr 2018 15:58:09 +0200 Message-Id: <20180427135710.702703557@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180427135709.899303463@linuxfoundation.org> References: <20180427135709.899303463@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.9-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 @@ -117,19 +117,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; }