linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Numfor Mbiziwo-Tiapo <nums@google.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Ian Rogers <irogers@google.com>, Jiri Olsa <jolsa@redhat.com>,
	Mark Drayton <mbd@fb.com>, Namhyung Kim <namhyung@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Song Liu <songliubraving@fb.com>,
	Stephane Eranian <eranian@google.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Sasha Levin <sashal@kernel.org>,
	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	[thread overview]
Message-ID: <20190806213624.20194-8-sashal@kernel.org> (raw)
In-Reply-To: <20190806213624.20194-1-sashal@kernel.org>

From: Numfor Mbiziwo-Tiapo <nums@google.com>

[ 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 <nums@google.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mark Drayton <mbd@fb.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20190724234500.253358-2-nums@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 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


  parent reply	other threads:[~2019-08-06 21:40 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-06 21:35 [PATCH AUTOSEL 4.14 01/25] clk: at91: generated: Truncate divisor to GENERATED_MAX_DIV + 1 Sasha Levin
2019-08-06 21:35 ` [PATCH AUTOSEL 4.14 02/25] clk: renesas: cpg-mssr: Fix reset control race condition Sasha Levin
2019-08-06 21:36 ` [PATCH AUTOSEL 4.14 03/25] xtensa: fix build for cores with coprocessors Sasha Levin
2019-08-06 21:36 ` [PATCH AUTOSEL 4.14 04/25] xen/pciback: remove set but not used variable 'old_state' Sasha Levin
2019-08-06 21:36 ` [PATCH AUTOSEL 4.14 05/25] irqchip/gic-v3-its: Free unused vpt_page when alloc vpe table fail Sasha Levin
2019-08-06 21:36 ` [PATCH AUTOSEL 4.14 06/25] irqchip/irq-imx-gpcv2: Forward irq type to parent Sasha Levin
2019-08-06 21:36 ` [PATCH AUTOSEL 4.14 07/25] perf header: Fix divide by zero error if f_header.attr_size==0 Sasha Levin
2019-08-06 21:36 ` Sasha Levin [this message]
2019-08-06 21:36 ` [PATCH AUTOSEL 4.14 09/25] libata: zpodd: Fix small read overflow in zpodd_get_mech_type() Sasha Levin
2019-08-06 21:36 ` [PATCH AUTOSEL 4.14 10/25] drm/bridge: lvds-encoder: Fix build error while CONFIG_DRM_KMS_HELPER=m Sasha Levin
2019-08-06 21:36 ` [PATCH AUTOSEL 4.14 11/25] scsi: hpsa: correct scsi command status issue after reset Sasha Levin
2019-08-06 21:36 ` [PATCH AUTOSEL 4.14 12/25] scsi: qla2xxx: Fix possible fcport null-pointer dereferences Sasha Levin
2019-08-06 21:36 ` [PATCH AUTOSEL 4.14 13/25] exit: make setting exit_state consistent Sasha Levin
2019-08-06 21:36 ` [PATCH AUTOSEL 4.14 14/25] ata: libahci: do not complain in case of deferred probe Sasha Levin
2019-08-06 21:36 ` [PATCH AUTOSEL 4.14 15/25] kbuild: modpost: handle KBUILD_EXTRA_SYMBOLS only for external modules Sasha Levin
2019-08-06 21:36 ` [PATCH AUTOSEL 4.14 16/25] arm64/efi: fix variable 'si' set but not used Sasha Levin
2019-08-06 21:36 ` [PATCH AUTOSEL 4.14 17/25] drm/vgem: fix cache synchronization on arm/arm64 Sasha Levin
2019-08-06 21:36 ` [PATCH AUTOSEL 4.14 18/25] arm64: unwind: Prohibit probing on return_address() Sasha Levin
2019-08-06 21:36 ` [PATCH AUTOSEL 4.14 19/25] arm64/mm: fix variable 'pud' set but not used Sasha Levin
2019-08-06 21:36 ` [PATCH AUTOSEL 4.14 20/25] IB/core: Add mitigation for Spectre V1 Sasha Levin
2019-08-06 21:36 ` [PATCH AUTOSEL 4.14 21/25] IB/mad: Fix use-after-free in ib mad completion handling Sasha Levin
2019-08-06 21:36 ` [PATCH AUTOSEL 4.14 22/25] drm: msm: Fix add_gpu_components Sasha Levin
2019-08-06 21:36 ` [PATCH AUTOSEL 4.14 23/25] ocfs2: remove set but not used variable 'last_hash' Sasha Levin
2019-08-06 21:36 ` [PATCH AUTOSEL 4.14 24/25] coredump: split pipe command whitespace before expanding template Sasha Levin
2019-08-06 21:36 ` [PATCH AUTOSEL 4.14 25/25] asm-generic: fix -Wtype-limits compiler warnings Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190806213624.20194-8-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=acme@redhat.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=clang-built-linux@googlegroups.com \
    --cc=eranian@google.com \
    --cc=irogers@google.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mbd@fb.com \
    --cc=namhyung@kernel.org \
    --cc=nums@google.com \
    --cc=peterz@infradead.org \
    --cc=songliubraving@fb.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).