Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10417874ybi; Wed, 24 Jul 2019 22:51:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqx9PpuwNf6yEyYIaxAf+eqtk1By1yieAHl8lDIVyBYXn2LQa+UDupjj60ttICXNhnzGiT5K X-Received: by 2002:a17:902:b497:: with SMTP id y23mr89705983plr.68.1564033913442; Wed, 24 Jul 2019 22:51:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564033913; cv=none; d=google.com; s=arc-20160816; b=nJOIKvENnt9qzYdn+DKOLg9LFQIS+bcdVlcnuPDn9fWnki6suqpmoGZ7qK9gKIgVpd DhJCnz2IlYjR3zvp3IwuDDrVYLEuK3JhcVoEsRGXTexpyf+vv8r5xPcrWF6m/7br6Y2G 4j3GSoB3JtbOlTFRvN1mHtAENFiFF6zHsRrP7+BWM1r5/+1jjA4AU4L5OLlXNytBfMGV h7aTeqL/aARn4uwZi9vfpoOPdWuPaftDQ+i5QLyrS1FvkUuwlUJ1sDxXYvogZFp+d+sn EGuhEDERo1oyRFZsQv09hr4AlEzbBAiBRQ73MhXpwKuc0BLvlKS9VMUR3FhONSL23zlu OiPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=fusILKOLmxx77CwhoKkqEXw680POTmXlnL5bfavBpig=; b=SM+V7dIuWAP5+yp+4L77KDJf7i6gpLmV3FUxqxJ14o+i6m/AlMyCIEBK9vm4Mr850Q lmPXvuSAwjoyefnKXYYblil97LFQiNmHzPgm5qTC3TvXvhYJhVHl2SnSj7gCXH9CkKwp 3pvL+PVtv7KH4kGo+x8s+kWB5viSVqe2Bh0tMbyWOOlKHD9Bq0OgVBIkbXA4fCy62y0A 0+ejR3me08ZFBs111b0VnzcIFU74ZxATcS+/gYaKImfh4jIKEt9YtCnrL2DVT7J3twx/ HUxGDteBaUQy9XLf2v547LVRWjS76xgKCkaV9AUlLSZz8ahBTFjiJWe1HF9H8vnPqu8k MHdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=nm8Sm35W; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z61si14853039plb.19.2019.07.24.22.51.39; Wed, 24 Jul 2019 22:51:53 -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=@google.com header.s=20161025 header.b=nm8Sm35W; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387839AbfGXXpJ (ORCPT + 99 others); Wed, 24 Jul 2019 19:45:09 -0400 Received: from mail-vk1-f202.google.com ([209.85.221.202]:34597 "EHLO mail-vk1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726832AbfGXXpH (ORCPT ); Wed, 24 Jul 2019 19:45:07 -0400 Received: by mail-vk1-f202.google.com with SMTP id g68so17754612vkb.1 for ; Wed, 24 Jul 2019 16:45:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=fusILKOLmxx77CwhoKkqEXw680POTmXlnL5bfavBpig=; b=nm8Sm35Wuj9GgaNhssIt+yIV7CWagKfpNNEb4SzzakBwRekGAqxrjYZx3fFRUtpPuI uu04M2hSUulDXjHYLoA6oAuNmAWTT8StE8xjpTg4E4V3O57H+FtJLbbad3H5aAsKWn6O 7VtFi/wfaygew9Ni77sRRK9asQhzRwa4l/8lUf1OLwLnrQaAOSpX71N47ezsXgavUn2G sEdp7IlTeJ92OfMJWQY3uyDss/RSNdYKDrx36ihUeOPgZGeQ9HUACb6qTiT1drIKFx1A gmTHanGNbbKG/5TiGqFF0KDkWMlb95X5T1Ugsasp6VbIE3xU10NQslK0OWZTi2EHWLby 5w0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=fusILKOLmxx77CwhoKkqEXw680POTmXlnL5bfavBpig=; b=Ma4fwvzJEwRkB9f9Ut7iaXS+v1YHHa7ZcVhtzpfUBPyK9WWcRVUB/9ceapaOP+wVyi bf+cH+h8KMiVCmCXFTVQDb5aIU9FQvnq9lXqcs19pQrdCcDJettn+xy+GZqGmHES9mic ZDqbE+z5kZcT002/4QDB4BDRcLNbGv2KYVDXiee+ZBrbMrjrDym0KlKe83USzCmeSvtX eS8FFS5L1MnroQ4q/1+CLtGDlVlpvZcv9aENMTp+L7KYGMidnxT58EZRm6zs+w06ae9p oHvoAKOdjDTY6k3XOFG2YD8jvuzY7wg5OsujHHyPOAWq2g9vet1OipwDTM0u+r9sReh+ s9cw== X-Gm-Message-State: APjAAAWWnmz7GiS8guYZzr95EvEY5oYERP1i5IU1a9gbyFzOh3+aJPLo eC5R1OUPw9oESJTH//dQ69kDSRNA X-Received: by 2002:a1f:19ce:: with SMTP id 197mr33942308vkz.60.1564011906611; Wed, 24 Jul 2019 16:45:06 -0700 (PDT) Date: Wed, 24 Jul 2019 16:44:58 -0700 In-Reply-To: <20190724234500.253358-1-nums@google.com> Message-Id: <20190724234500.253358-2-nums@google.com> Mime-Version: 1.0 References: <20190724234500.253358-1-nums@google.com> X-Mailer: git-send-email 2.22.0.657.g960e92d24f-goog Subject: [PATCH 1/3] Fix util.c use of unitialized value warning From: Numfor Mbiziwo-Tiapo To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, songliubraving@fb.com, mbd@fb.com Cc: linux-kernel@vger.kernel.org, irogers@google.com, eranian@google.com, Numfor Mbiziwo-Tiapo Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 calloc initializes 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 --- 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 dec6d218c31c..b9c71fc45ac1 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -3427,7 +3427,7 @@ int perf_event__synthesize_attr(struct perf_tool *tool, size += sizeof(struct perf_event_header); size += ids * sizeof(u64); - ev = malloc(size); + ev = calloc(1, size); if (ev == NULL) return -ENOMEM; -- 2.22.0.657.g960e92d24f-goog