Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1486650ybl; Thu, 22 Aug 2019 15:39:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqymaKnpEOD9QzQEqVnZJWdicwDu55blSFJMZId/qTOXNkndaZ0zCaAfOExqVxCoc11bOAGB X-Received: by 2002:a63:7a06:: with SMTP id v6mr1295765pgc.115.1566513556508; Thu, 22 Aug 2019 15:39:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566513556; cv=none; d=google.com; s=arc-20160816; b=H3gbhZWXRzJd0+njYWaw1tJua3KVeu/zpRJHROFM8Irjtp/XG2/6GyZacAJJWk6G9x T+pAy2PnMN+hvb1gdp9nZNX2/PNeWZJi9ZfT7QHuVoxjS+QBkAmiENr3j1ZToWSZBkeY cHwxEXJZ2sE4ENSOL5mpTdlWdkvvQSZ5tznbNs18LSnmlHw8JCib3EvJtJuDguCcuRrf 2Hu4DPbxbbmFtZvpSR97hhrKEpi5izRtMVZVEl2QhguJKthx4Q0/Om6Y3dYT0fhIx8M2 RaXag7kVxDR5PYPI37wMadKWJBdxInACsFBP8QWVU1999Vgq9pqmPeyALbewtcBY17xI 3QFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YHCWkOyNFe1D+Yh/di3X9JUUaOKMavSfO+jkChpy0vo=; b=oj+kQwMpBadqBXXmF2MgWLj3VAgbr2X6NcvFp8TjQIPYhPpEvYqn4wH+zRQXAYDWSb FETJ4Any+OMcuwislZTq1oWnSxV1YFsHa16A/tMwNHfvOSJbqHMZDO9ex/khlM7xbDv4 pc7CXcSRva1tyUzDsc0FVUDQMxWwvq4kYKD3L9mQuJmKVPRXfA0oPMVfwqiPR3p9SqKv IddN5u2GwLxYch6KxZqJKUgeTIJ8i6PM/tFp4KTAoIrDBqy6lAZVCL/h28blscOZIcgX +E/lRzKZ1omBr9geZyIYDmT26Cez2Ib7b64jLwGiaC2Rh7X/FtyqeUaIAC6jCw1s3bmh aLaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mZ+m2DiV; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n129si465733pgn.254.2019.08.22.15.39.01; Thu, 22 Aug 2019 15:39:16 -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; dkim=pass header.i=@kernel.org header.s=default header.b=mZ+m2DiV; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391180AbfHVRPh (ORCPT + 99 others); Thu, 22 Aug 2019 13:15:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:58190 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390459AbfHVRIm (ORCPT ); Thu, 22 Aug 2019 13:08:42 -0400 Received: from sasha-vm.mshome.net (wsip-184-188-36-2.sd.sd.cox.net [184.188.36.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5EBED233FC; Thu, 22 Aug 2019 17:08:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566493721; bh=sz3DWKeYsysDBtyRq4WhvVf/U3OY+yB8ZuYeKLkRamM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mZ+m2DiVsCJD46FRxkSs8wBjHr4IzoOH7QgvLcE9N89YgfHL8/StCbvBnTGsGO42D 08FKA0k1/DTqU6UJAczH+c7tn77luJ1jNK8gC1Uz7cUI+Cc+XDXrKUcBbzZnvgSPn0 RoVFt7k9VMgUEUYlHwykVvu0x5HSbrIs8GyIg8co= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Vince Weaver , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Peter Zijlstra , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.2 051/135] perf header: Fix divide by zero error if f_header.attr_size==0 Date: Thu, 22 Aug 2019 13:06:47 -0400 Message-Id: <20190822170811.13303-52-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190822170811.13303-1-sashal@kernel.org> References: <20190822170811.13303-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.2.10-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.2.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.2.10-rc1 X-KernelTest-Deadline: 2019-08-24T17:07+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vince Weaver [ Upstream commit 7622236ceb167aa3857395f9bdaf871442aa467e ] So I have been having lots of trouble with hand-crafted perf.data files causing segfaults and the like, so I have started fuzzing the perf tool. First issue found: If f_header.attr_size is 0 in the perf.data file, then perf will crash with a divide-by-zero error. Committer note: Added a pr_err() to tell the user why the command failed. Signed-off-by: Vince Weaver Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/alpine.DEB.2.21.1907231100440.14532@macbook-air Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/header.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index e84b70be3fc11..cab9ed6acf35a 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -3478,6 +3478,13 @@ int perf_session__read_header(struct perf_session *session) data->file.path); } + if (f_header.attr_size == 0) { + pr_err("ERROR: The %s file's attr size field is 0 which is unexpected.\n" + "Was the 'perf record' command properly terminated?\n", + data->file.path); + return -EINVAL; + } + nr_attrs = f_header.attrs.size / f_header.attr_size; lseek(fd, f_header.attrs.offset, SEEK_SET); -- 2.20.1