Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1003592ybt; Wed, 8 Jul 2020 17:58:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyI6A2dAUyKy3DOSY0yGgTqc6hMWnv7kviTx4IKDGLTKe0z6lDi/kdCUvcVTK1nXAGjYjzz X-Received: by 2002:a05:6402:1778:: with SMTP id da24mr58716468edb.126.1594256294281; Wed, 08 Jul 2020 17:58:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594256294; cv=none; d=google.com; s=arc-20160816; b=WDwzMnZnARfjQb1YSE9s/y+dL5EDp8CpPzONeBl1S3zfVHyD4h/k1yHfX7+nJ9fvTB rh5h4Y7LpZ3SYRUUe9ca38zqceyP/yktP3owTy2TZzfOiH9ms9VQVHLsdduS6/6AkMD9 C3Q8SUHHN9xzHd9aYHsRqA0mOofS7rWvwFi9BgjD4UaBAT3tXrMdcMsQ1SlwDklbV1Wo wNG7bU1WqFENd2dgnT48v96lfFVyc9qHKwC4aLvw9TAr4CaLz6u/lbVIQ5l2ihFZVArc gN3CGMfUNvHfSfZuACcBl8LpZWGYQXROmuVaTVpKst/SjOACtDzMCJloScu+GaSUEFBS Y4Ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=msvpLDvjqecx9LlMMsehXjCPgkXnE5LEOAtj+KVjieQ=; b=oY378tzcbJ/0ChrEHBHHCneoQeXWD6CadH2IGWJfhYr7AJvF3/zWIblipqtLPgP5ld pKABOdBS30ccOlolTHZBbGi56VU4DVJ19fJMBHB4AabuR70hcgUS02iCqttZluDCdFO6 EaVekEUICk4JItoDJFf6rotOAzrAe/hGjXHTwe/pWaCrEzH3dGSo7L/mbOkhPATEYRVn CCx216ZrIympgROnesT4+FbPqMEqjUr2zqPuAL5BQ/SNBEIBy2pPfX1TTdMrN53rRnkO Z1h5Hi36CQRqMRjSbebKE4+udrUQ+BfFtsrHQ6mspW5fpPc2jZl/6b5KOCNpyZ6ijZwC sq0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=eo+ggAGI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id rl28si905194ejb.353.2020.07.08.17.57.51; Wed, 08 Jul 2020 17:58:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=eo+ggAGI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726184AbgGIAzB (ORCPT + 99 others); Wed, 8 Jul 2020 20:55:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725903AbgGIAzB (ORCPT ); Wed, 8 Jul 2020 20:55:01 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20876C061A0B for ; Wed, 8 Jul 2020 17:55:01 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id g75so152668wme.5 for ; Wed, 08 Jul 2020 17:55:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=msvpLDvjqecx9LlMMsehXjCPgkXnE5LEOAtj+KVjieQ=; b=eo+ggAGITdc8fuaE4ILhLXGMOxi7eyHtVCzhUwVFbocWguJcpI9X9AQ6ZJAot6Fi3R xmmNMr/RazTdJWybePFdbCoS+H3SWdb+2vQ38XbksvuqYQxgv8SGmwH+PqFpook6Cu5/ XXU1sOpwHTLW7xXz/jPCXkAFgbh4laLI+3Fc7iDe6M0BukjU2YLTqETNMAa1upeIF6n2 bc2VTcxzfhyE6BxDDupY9weFdhlObC45aIS3kN/7+TZzDVoP6Cn7FvugSayv8ShdVijJ 2U4SoXzlH8RVvkcRiYJA/SYu9tgt1xMuzrCtBCv1Z0AzXtwmhk95F91BnMky/JtXq5VW IAIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=msvpLDvjqecx9LlMMsehXjCPgkXnE5LEOAtj+KVjieQ=; b=jQs6ic8XGmwSJAgcRXH1AtwpG11c0ClaQYMbHNTOw/bCQv8ej9IO5cC52Zv5pWjHu0 Ix9MXVOCVd+MwIjT3ZP6Qu7Wc8W+SApq9f3TQ5oVXysaoiukYqUxvrLPNj/C0bZ70Lrr rt9VB2QfVs39QcDjLIQHVDU2K9gVgEUHVFAVsRRAGz4an6EdBfd+8GcXoJdxn0r2+GwG iPOBVUz/Guj+e2/9Ei7u29895Q8lPmR9I2GLukGsAqdO3U7UkYFK8zzyKI4a9cd6uadH +QCaR5cJoVbw6bey111dPabZaipKQCdE67JllQnl1J0c1ctbyvscn2BsgV6BfA25yrLV g2KA== X-Gm-Message-State: AOAM531guQ2PUuP1S/KbicUJozrprlQBY5AFnb3D1nn9p+0vLtO4afI/ 11BQ1h8oKLTtk20vZpCLUOm1V4Ts4Eco3r+bx22DRw== X-Received: by 2002:a1c:398b:: with SMTP id g133mr11384746wma.76.1594256099409; Wed, 08 Jul 2020 17:54:59 -0700 (PDT) MIME-Version: 1.0 References: <20190726194044.GC24867@kernel.org> <20190729205750.193289-1-nums@google.com> <20190807113244.GA9605@krava> In-Reply-To: From: Ian Rogers Date: Wed, 8 Jul 2020 17:54:47 -0700 Message-ID: Subject: Re: [PATCH v2] Fix annotate.c use of uninitialized value error To: Jiri Olsa Cc: Numfor Mbiziwo-Tiapo , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Namhyung Kim , Song Liu , mbd@fb.com, LKML , Stephane Eranian 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 On Fri, Oct 25, 2019 at 3:11 PM Ian Rogers wrote: > > It looks like this wasn't merged to tip. Does anything need addressing > to get it merged? > > Thanks, > Ian > > On Wed, Aug 7, 2019 at 4:32 AM Jiri Olsa wrote: > > > > On Mon, Jul 29, 2019 at 01:57:50PM -0700, Numfor Mbiziwo-Tiapo wrote: > > > Our local MSAN (Memory Sanitizer) build of perf throws a warning > > > that comes from the "dso__disassemble_filename" function in > > > "tools/perf/util/annotate.c" when running perf record. > > > > > > The warning stems from the call to readlink, in which "build_id_path" > > > was being read into "linkname". Since readlink does not null terminate, > > > an uninitialized memory access would later occur when "linkname" is > > > passed into the strstr function. This is simply fixed by null-terminating > > > "linkname" after the call to readlink. > > > > > > 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 > > > > Acked-by: Jiri Olsa Acked-by: Ian Rogers Arnaldo, I think this got overlooked. Thanks, Ian > > thanks, > > jirka > > > > > --- > > > tools/perf/util/annotate.c | 15 +++++++++++---- > > > 1 file changed, 11 insertions(+), 4 deletions(-) > > > > > > diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c > > > index 70de8f6b3aee..e1b075b52dce 100644 > > > --- a/tools/perf/util/annotate.c > > > +++ b/tools/perf/util/annotate.c > > > @@ -1627,6 +1627,7 @@ static int dso__disassemble_filename(struct dso *dso, char *filename, size_t fil > > > char *build_id_filename; > > > char *build_id_path = NULL; > > > char *pos; > > > + int len; > > > > > > if (dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS && > > > !dso__is_kcore(dso)) > > > @@ -1655,10 +1656,16 @@ static int dso__disassemble_filename(struct dso *dso, char *filename, size_t fil > > > if (pos && strlen(pos) < SBUILD_ID_SIZE - 2) > > > dirname(build_id_path); > > > > > > - if (dso__is_kcore(dso) || > > > - readlink(build_id_path, linkname, sizeof(linkname)) < 0 || > > > - strstr(linkname, DSO__NAME_KALLSYMS) || > > > - access(filename, R_OK)) { > > > + if (dso__is_kcore(dso)) > > > + goto fallback; > > > + > > > + len = readlink(build_id_path, linkname, sizeof(linkname) - 1); > > > + if (len < 0) > > > + goto fallback; > > > + > > > + linkname[len] = '\0'; > > > + if (strstr(linkname, DSO__NAME_KALLSYMS) || > > > + access(filename, R_OK)) { > > > fallback: > > > /* > > > * If we don't have build-ids or the build-id file isn't in the > > > -- > > > 2.22.0.709.g102302147b-goog > > >