Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2827303pxb; Mon, 1 Nov 2021 02:38:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgl3Ohor3iCkYFypiPBQu0GhGV9wkT5Tw5Ho7livvUbewwTpyfnvgc4aX1ifQCqLI93kyX X-Received: by 2002:a05:6638:13d2:: with SMTP id i18mr20984942jaj.3.1635759538043; Mon, 01 Nov 2021 02:38:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635759538; cv=none; d=google.com; s=arc-20160816; b=lVtITkNlRvllh8aURlULoU3tumnlmMzsKeqKYJ24pG54XIL5exzjfzKSmSAU0Uveh0 8skhfioUtinYnNpuHWA8C0B8bfGQ+Hs0HhfHAHt8ePSXnIKX0PhTpuo+MYwpNmXaJOkT 5sTWFo6tmdTBruh7CJJsU64zs/IYcVRdZ4OEEolLX0LpYOFD3zH5Jgc0+MOsFKb8WooH khEr/ZX8H6dmMueGhIvLqsf34+/jDpqvoGD36JEzckDG1k5WZll8wg1Jj9skAjzLMY0G vB+g4VmLJgswFYspfT2/zgntHXTt+eoFZ8cj/aRoTNK6/sY0Mf2Bsq8Cs8A2r3uj3st8 o/Hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TFJLI1I2lML6UVSTw+cnD/gELug4DAYu4/QWI3xhNKI=; b=c71w7aN2/VM5vu+h6OpbW/BY5F9AZiT5mnyM984zDYGA+8OROD2oF+T+cZmil84kPV g5jwWP0OJ0GMPuIcoTkFqfgZ8PBhhNwDOtn6brqRaIK2iYgOM/6J6DDe7ZCLbPVlZ/r9 q6TRjWtlt7rZXMEM6lYAqb/2ljqcUeMJnm59jS0V5Mc9hy8hlDyeMjbz3V3eFHpUNviV 3z9dT8tTvmkaEnkvEB9sWvez6d+FH18na2CNKq/KXlS/zZgqXR3hdqFPOIVDo25yosnm 34FwnN6DFoByCxhRACP+pRRkgBjOV51s5FRwx0YTc4pXKCj9ytQenYCNo6Xpy8w753x3 o3mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YPu5L9M4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b11si11013341ilv.42.2021.11.01.02.38.46; Mon, 01 Nov 2021 02:38:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YPu5L9M4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233258AbhKAJkY (ORCPT + 99 others); Mon, 1 Nov 2021 05:40:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:43770 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232033AbhKAJiB (ORCPT ); Mon, 1 Nov 2021 05:38:01 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EF43260F4F; Mon, 1 Nov 2021 09:27:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1635758828; bh=CDMlvG5duSBUuvRV8fQFE52vESjelhXLk01PF/XH+Hc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YPu5L9M4i1CyS8BZB4/cD35z0sUOrQ85hr0lpwj98wQRQBx+zXjiJlh7VXxUgRIhc KmVMPYJYcgdzL9CF0REHU9jsv1dAulgHWh+EMMhGXJumPFnd93M7ugVh2Li4mV97UQ WvCBLVKdOdqCCzacUiTTxyqPIp5PZ0ArfuhWgfVQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Song Liu , Peter Zijlstra , kernel-team@fb.com, Arnaldo Carvalho de Melo Subject: [PATCH 5.10 77/77] perf script: Check session->header.env.arch before using it Date: Mon, 1 Nov 2021 10:18:05 +0100 Message-Id: <20211101082527.560848483@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211101082511.254155853@linuxfoundation.org> References: <20211101082511.254155853@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Song Liu commit 29c77550eef31b0d72a45b49eeab03b8963264e8 upstream. When perf.data is not written cleanly, we would like to process existing data as much as possible (please see f_header.data.size == 0 condition in perf_session__read_header). However, perf.data with partial data may crash perf. Specifically, we see crash in 'perf script' for NULL session->header.env.arch. Fix this by checking session->header.env.arch before using it to determine native_arch. Also split the if condition so it is easier to read. Committer notes: If it is a pipe, we already assume is a native arch, so no need to check session->header.env.arch. Signed-off-by: Song Liu Cc: Peter Zijlstra Cc: kernel-team@fb.com Cc: stable@vger.kernel.org Link: http://lore.kernel.org/lkml/20211004053238.514936-1-songliubraving@fb.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Greg Kroah-Hartman --- tools/perf/builtin-script.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -3820,11 +3820,15 @@ int cmd_script(int argc, const char **ar goto out_delete; uname(&uts); - if (data.is_pipe || /* assume pipe_mode indicates native_arch */ - !strcmp(uts.machine, session->header.env.arch) || - (!strcmp(uts.machine, "x86_64") && - !strcmp(session->header.env.arch, "i386"))) + if (data.is_pipe) { /* Assume pipe_mode indicates native_arch */ native_arch = true; + } else if (session->header.env.arch) { + if (!strcmp(uts.machine, session->header.env.arch)) + native_arch = true; + else if (!strcmp(uts.machine, "x86_64") && + !strcmp(session->header.env.arch, "i386")) + native_arch = true; + } script.session = session; script__setup_sample_type(&script);