Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp4602664ybh; Tue, 6 Aug 2019 14:40:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqx+blhGmZXeKJmQYXNvFdceNhTtkW6aBR20FK4eOfAVWXY7sWOFOROKQPKB4+pcajuL+dCS X-Received: by 2002:a17:90a:1c17:: with SMTP id s23mr5236188pjs.108.1565127649086; Tue, 06 Aug 2019 14:40:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565127649; cv=none; d=google.com; s=arc-20160816; b=HcSykvPHLAIUtYSbCz0cWoIvWfWOun9+WREhIcbVX2v8T0/f6R8QjmynMt6zVHpFmV zwdy2mlE9DLhRfX6b1qG2TR4mcyY06yRMaq0NqOCQX4sDkPV8J5cwBVoXRDutoSsMrql ADedi/M4Gimb5n/QBw3cV03Xd53IcGjM5BuOOfJl8GeW61k2CjYoRU4hs4nQzMry9Tfq kNaPagJCgMdbr6TWXY/ngyNFCITSfa/8e4KgdVhwAkoPRg3TdrbOM46fZuYZ/nBLGOXu YZaP5KGjW0o+xjds8FgihxuIgvaajfEu46sWlvSt59TJ7KEd192a7NfHwMX8WiBX0EP8 FfmQ== 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=1FJFlfDqe+xWn5/qUYaR5uiWTEuvu3ESHUo8rewAAwM=; b=W+DZV9aaD5Q0C0dk7JeSPO8fEUT7kbF7mtA8U/eN0udo/TdHEXK67BkF9/iByrY0/Z B6QvPhukx2EGTaQJGdvPLe/0Jvd0p+6AZpWaW1p/gHC/3fFKZFDGZYZnDS+kqnRyliZ3 xi+3rKyo0+9nebl/G9dCXrUv14UtIHqAjKz33pYdpG35seOVrTQKdOY5KkT6IbWEDhyb c6w/SVTqyNS5JV7AUDzOCzI3HdQHq59v4NeVxgMsEMFUScE5zBonsWXDNikJdAMmmXTb L4N9jATt5gp43fG6x2gkmtnQ4aq7V5dRnLCudmNeVuM4U/qBgnerPMjhoHI+ywAz5Ki9 y8Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iKolr7hQ; 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 c2si7533956plz.407.2019.08.06.14.40.34; Tue, 06 Aug 2019 14:40:49 -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=iKolr7hQ; 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 S1729610AbfHFViF (ORCPT + 99 others); Tue, 6 Aug 2019 17:38:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:55698 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729560AbfHFViB (ORCPT ); Tue, 6 Aug 2019 17:38:01 -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 22DB92189D; Tue, 6 Aug 2019 21:37:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565127480; bh=zIiCuKNDpcRRRa9nJ08ZfVRNQarneq0WoQKE0ZlFYf0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iKolr7hQamjIU2KfjhW2nC2MLFrZb4eQXU2ArNtwqkn1paLEEB8Fh1hAyaU2gexc7 QFnYlT8/q3nCyQPTnnU1AW3qNCHCEQJGdM7+nT7WIY5lpIM8AgnCsQoSBmrC0Xza8b 5zd2V2jRTiMuKWMpgZ0KJTNaZlAg2+laInuc9seA= 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.4 05/14] perf header: Fix use of unitialized value warning Date: Tue, 6 Aug 2019 17:37:39 -0400 Message-Id: <20190806213749.20689-5-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: 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 0102dd46fb6da..bcb8e85a40f90 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -2680,7 +2680,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