From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6DE76C32751 for ; Tue, 6 Aug 2019 21:40:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 42F2C2189E for ; Tue, 6 Aug 2019 21:40:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565127651; bh=ZYa+k17RJXfbbcqFPq9IwDXjhOi5CzyHoi9u/5eofKQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=q1wEag/fMTSk/GbxnKBJfawfYjLoboshw+WnRYf0fHiB86L7P4wY4rbtNS7YL5tBJ acafl1JoDave7ModAeIcVnnt0ArBj9PtUPWWx9CUNKVszva56l2pWyMp3uc54I8p0Q KKggvvUH29Eo1Mafql7trRMVZoQQOPLBn7d7qFH4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727938AbfHFVgo (ORCPT ); Tue, 6 Aug 2019 17:36:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:54526 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727954AbfHFVgn (ORCPT ); Tue, 6 Aug 2019 17:36:43 -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 E545621874; Tue, 6 Aug 2019 21:36:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565127402; bh=ZYa+k17RJXfbbcqFPq9IwDXjhOi5CzyHoi9u/5eofKQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0x02gF6iR86lC+gZX7MNG0VoSCBUTJgScte4Mtr5bVn3odSfzs+A9sV3FWL5aYfk9 TwWBVVBMp5UDVwkykmekM7p1CM5xRlUzlhoaRtvIehj5t5AIlW0PeYpTvviVdDMlAO EpxDjT9OrmojwB1prbZ2AVkQOY+66XRJ/K8jCdEc= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Numfor Mbiziwo-Tiapo , Alexander Shishkin , Ian Rogers , Jiri Olsa , Mark Drayton , Namhyung Kim , Peter Zijlstra , Song Liu , Stephane Eranian , Arnaldo Carvalho de Melo , Sasha Levin , clang-built-linux@googlegroups.com Subject: [PATCH AUTOSEL 4.14 08/25] perf header: Fix use of unitialized value warning Date: Tue, 6 Aug 2019 17:36:05 -0400 Message-Id: <20190806213624.20194-8-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190806213624.20194-1-sashal@kernel.org> References: <20190806213624.20194-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Numfor Mbiziwo-Tiapo [ Upstream commit 20f9781f491360e7459c589705a2e4b1f136bee9 ] When building our local version of perf with MSAN (Memory Sanitizer) and running the perf record command, MSAN throws a use of uninitialized value warning in "tools/perf/util/util.c:333:6". This warning stems from the "buf" variable being passed into "write". It originated as the variable "ev" with the type union perf_event* defined in the "perf_event__synthesize_attr" function in "tools/perf/util/header.c". In the "perf_event__synthesize_attr" function they allocate space with a malloc call using ev, then go on to only assign some of the member variables before passing "ev" on as a parameter to the "process" function therefore "ev" contains uninitialized memory. Changing the malloc call to zalloc to initialize all the members of "ev" which gets rid of the warning. To reproduce this warning, build perf by running: make -C tools/perf CLANG=1 CC=clang EXTRA_CFLAGS="-fsanitize=memory\ -fsanitize-memory-track-origins" (Additionally, llvm might have to be installed and clang might have to be specified as the compiler - export CC=/usr/bin/clang) then running: tools/perf/perf record -o - ls / | tools/perf/perf --no-pager annotate\ -i - --stdio Please see the cover letter for why false positive warnings may be generated. Signed-off-by: Numfor Mbiziwo-Tiapo Cc: Alexander Shishkin Cc: Ian Rogers Cc: Jiri Olsa Cc: Mark Drayton Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Song Liu Cc: Stephane Eranian Link: http://lkml.kernel.org/r/20190724234500.253358-2-nums@google.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/header.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index c78c2ed009ea0..cdbc877b79d4e 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -2990,7 +2990,7 @@ int perf_event__synthesize_attr(struct perf_tool *tool, size += sizeof(struct perf_event_header); size += ids * sizeof(u64); - ev = malloc(size); + ev = zalloc(size); if (ev == NULL) return -ENOMEM; -- 2.20.1