Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp561709ybl; Fri, 23 Aug 2019 05:11:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqyIRd5SRwkw6JspMcWxiDfxKLM4MBvNxMBpREdQHVyBe9aCQE8goTS6OrsSUPs+Axwl5Ydw X-Received: by 2002:a17:90a:9b08:: with SMTP id f8mr4959099pjp.103.1566562278130; Fri, 23 Aug 2019 05:11:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566562278; cv=none; d=google.com; s=arc-20160816; b=pxZNpkWNTacsmOcVJlIPCSdCIjX46Ip4YCsWKllxsGPKAHo4Syeh95ncuHfHaVekjW 6pXOBX8sji6PUtDJ3SaoeyZ5YxSWUAOu5s+1VeTIFQlSMYcQQqpVfHUwfufjoQJF2Bna j7AAB2AD/vOYrIOZz5rpr8Q2nR5eovFGDDdzVGMmGWd1sc16JyuS1igGOOyA2zfpjhkG k6UvSKWQ4iBLpEph2g+h1NYoXqzNkDrZf5zwPjeUmfUGaK/NJWDwcq2vF1EG8mmLggeW CEIpPQm14qXpdsNtvMwZ46Bv0/TGq5T4NycLx2NsEN77HheCzXg6kY0x6zfMzUmg3csH t6Yg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DMctiejqKhIYtgJePYqd0kmHV1lsKbc5p/7l2tH1zew=; b=I45JLvKk15KVwAMLv6RXXdaoR8EUUof4/X2RltlDlu+p9kXhJQrkZ3xUhK1bprp1Cp 7XeFrXsg3tYAK+pX9+HAGmJqCMcblYW6EOWrs+EBV8Z2U0vKvsJLs2kJzGN/gK/ol3MO KOVUK1Y7hpId4deqEa+suPLNd+Z5VaHDCZdnk2Ofo61QSlJWfz/RVG8Qa8NQ2nxVbjvo Ne5OhxERsYRIP4WeLVyWBbsK470e6Skofq8uMb+aK92BedkICxLtxmaWDDsSnHam5Tyn neUb2J9AMl3iRWrxFrgZpScv6qFnUuytqQHy8Z6vhcr72wwGfGpRI8kjrbhHD1/ShukK mafg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TnzpbIcw; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y11si2119458pjp.54.2019.08.23.05.11.01; Fri, 23 Aug 2019 05:11:18 -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=TnzpbIcw; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393167AbfHVRrL (ORCPT + 99 others); Thu, 22 Aug 2019 13:47:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:41148 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391421AbfHVRWk (ORCPT ); Thu, 22 Aug 2019 13:22:40 -0400 Received: from localhost (wsip-184-188-36-2.sd.sd.cox.net [184.188.36.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D09F32341D; Thu, 22 Aug 2019 17:22:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566494560; bh=eRi135xqg5cAdxKSzrpkWfbDgI3AVSQeoWbwquYOEXQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TnzpbIcwXvXL0aJnFr/xcvdC1JP9xs7zhToOccm/bt/GQ8gWi4I8Sw5AcS1voWmP1 HRvL0z97FiRU+mjRUW5mHoyPyFmvusukACYSQ2cuETgE9qlzn5Hg3h0FYA67tHLjKb WLw19zi2bsDi51B6cQGDFqaUk+RvfDYUVcphZBOw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, 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 Subject: [PATCH 4.4 47/78] perf header: Fix use of unitialized value warning Date: Thu, 22 Aug 2019 10:18:51 -0700 Message-Id: <20190822171833.401778819@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190822171832.012773482@linuxfoundation.org> References: <20190822171832.012773482@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ 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