Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp4603254ybh; Tue, 6 Aug 2019 14:41:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqwMsSE2VW9vBlqHMp+zfk+PSB+9HNGYxZZAweNg6HrDtTC1JFLD+zmytWZgp+Kp0JWx29NK X-Received: by 2002:a17:90a:8a15:: with SMTP id w21mr5219613pjn.134.1565127696485; Tue, 06 Aug 2019 14:41:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565127696; cv=none; d=google.com; s=arc-20160816; b=wySWRYuaWcYyYhpBOq4nMc7enVAEbdiB4Em/cUIaf1fYGfADNsVcy2kg31S6CBu7HD voJQbTeQ+ApPAb8vlkpi2Ezw3hy6ZWKsNRawSWl703Qgc4nf0ximdmsaHmMT9WOnDhtS VwMXkFq1Xbj7B0SxQlnZKI2k75HkV06Ci+inEpcX/nXnTMxYdFkz8tv6yuby5kqNzfi1 vBFsoUNk3FyhFtEjQYi/R3H4hU8jE33LAz19+s70WfzJTry47ukWbDkGwNtoZGd/OX+N hf/sH3UfpSLJae8m+HfiNmxKY/2a+qnZUWCFVaDwHdWE0K/J3/Hk9yRuOGjlN0pUBmVi Gf0g== 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=qtGfcl5LfY9qVNf10gf0jzq0AaKqtiYqh5qjdT3+6A8=; b=M0/grIbJ68lD6TV4OhQ9a/DzhkY43XUbUQngz3UWhxqdhZNajE5bTvdYHFCO6Wyadh iiDD6BFhTSNX4RpYWoWIzNE9TqkJk2dD1khZRroe4yj2losuweWlvsIdNioy9FW5nBns 9eMEbDBWMaQ8/5B/8Opr38vlyfQlEsCUSgHsjq4SrK7ZqKbqM3SBBrW74eXTedH/lHNm c6O5FQ6utkDJhq8TRmm/6vohbkHzRxzdBuCVMXzgVjWDyC6u9+Fk8/zlSoFZbztTNNMY NOxEPRvVX6nt35+Odzqcq2wePHHByp3eRJzaHI5ThitI0abhiYm0OF7vHKl5+Jev1gvd IERg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Hr5XxbBz; 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 r10si46201563pgv.530.2019.08.06.14.41.21; Tue, 06 Aug 2019 14:41:36 -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=Hr5XxbBz; 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 S1729565AbfHFViB (ORCPT + 99 others); Tue, 6 Aug 2019 17:38:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:55644 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729552AbfHFVh6 (ORCPT ); Tue, 6 Aug 2019 17:37:58 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (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 8CC622189E; Tue, 6 Aug 2019 21:37:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565127477; bh=X0bt+3bsoL7JQXhTEl0wIgpBBJJbdIw+VmG3y1NgqqE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hr5XxbBzjZqNCnCeehdDUy3EjhzIsfe+Bm1a00qjABKFwOgQmVCz3pGrSCjKDqj8z CfTNIt+WeCa21+cx2Qv3LfzdLFxi/9w3yadUy3ID5Sblr4DI3sNVGdCo6+SPkQtj/r HNFddmiUFSWWxkegix9+CDfdx2qQouX/3MuM3hjc= 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 AUTOSEL 4.4 04/14] perf header: Fix divide by zero error if f_header.attr_size==0 Date: Tue, 6 Aug 2019 17:37:38 -0400 Message-Id: <20190806213749.20689-4-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190806213749.20689-1-sashal@kernel.org> References: <20190806213749.20689-1-sashal@kernel.org> MIME-Version: 1.0 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 304f5d7101436..0102dd46fb6da 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -2591,6 +2591,13 @@ int perf_session__read_header(struct perf_session *session) 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