Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2836775pxb; Mon, 1 Nov 2021 02:53:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTA1i/1jdtYu8uuyh1U8g+Cy0FHbtl9tymqQIux097tqdWEIeVpp5Z+bZ+nCPSRvsZgc2J X-Received: by 2002:aa7:dbca:: with SMTP id v10mr39433666edt.280.1635760435031; Mon, 01 Nov 2021 02:53:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635760435; cv=none; d=google.com; s=arc-20160816; b=ZvH93OLu0zV2ofS1+bFDIi7bpgd460lvbsk94/CrTA6uuUjsA2xXg/0LwQt0+Qwjwd 67XFQItv0iBd14x6AYzt9Ko2hlufQzaZYzwejZXhOMMfG9QbbXEvdwRtirbkVmoZwqN1 Rx3NO0U0wkUTT2s1MhNwTjpmvUjmhPxow/Ic6SEkDJlhlgaJJvUihMNBQVLOXHUU2zq+ O0+GlNG11A/tKuTPtQcW4kEgm13gAQ7DxMb9+lElgTUXU0l4NYV7hWFXVis+4ngvzvO/ VgZdJ2ZO20pqWcyCwm0A9Pq+V2WaUbWCP1bZqDVp6k9VqAN28JRh0ZB0Ogj3VmGnqeVM rIbA== 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=u414BadMRKY8b2KQ5W4NmhmOTKlEPv/+HObuwMIIgnw=; b=M4thFg3K06uUwfqKOzHWWzA0N+jbqksVqwHneDjWk4L/f3z2mtU2P2tfr2E1jOl+Cw 9LSvKjzG2e4DZjJXc5gWWh47hvRkEuMWnTWxcJNZydxJ4vHVuVLV5a2BhRPKik52nFea y5fxTa+1UaBqE091QnnS9fram+kffl/VEk30UYi9YiLHfz25aI2dTisv0X959h1HWvKX YHY18xgez414tcAIBBc3YffgVql112uOpQ8n4/RLA6a1/cQIIw0OTNle8sP2jLII//2P L0CDYP4GZvN4ZWoIBVhM3AcD1ej6HgwJXBNdVppR6gjpAnyc06Rl8ew+zOXWnhNtwwyv s97Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="no/vWchT"; 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 ce25si21210221edb.319.2021.11.01.02.53.31; Mon, 01 Nov 2021 02:53:55 -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="no/vWchT"; 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 S233694AbhKAJyG (ORCPT + 99 others); Mon, 1 Nov 2021 05:54:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:52156 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233436AbhKAJu3 (ORCPT ); Mon, 1 Nov 2021 05:50:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CED3361411; Mon, 1 Nov 2021 09:31:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1635759113; bh=qyP7yX4a41zPNxZ/dvq89YRR8LfqoDP3oX5QF4+EMN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=no/vWchTafDM1p9p1a8607QZQIxyBr9xxPuCHCWIBqSn1LCbUJTmngaNrDGBBxs8g W4DmsUDM7jyVWYMb9S8PG7QVt3y/33KrRRFrUf9XI0W4Py6PfnUvDR7J5b5noblmk9 lV+FaNz27oTDVJvWmNhkm+xid3D1OBC3mEVanVWo= 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.14 121/125] perf script: Check session->header.env.arch before using it Date: Mon, 1 Nov 2021 10:18:14 +0100 Message-Id: <20211101082555.964972905@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211101082533.618411490@linuxfoundation.org> References: <20211101082533.618411490@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 @@ -4024,11 +4024,15 @@ script_found: 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);