Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1508777ybt; Thu, 9 Jul 2020 08:39:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWPIb3pG3eD+Hc+kTM+1ak2JeU/ttbgjd2vyszI0bqcMG3awqv6QPS7RNbLWBpCoBnHGNz X-Received: by 2002:a17:906:c1c3:: with SMTP id bw3mr57599371ejb.8.1594309186914; Thu, 09 Jul 2020 08:39:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594309186; cv=none; d=google.com; s=arc-20160816; b=xZfdxD+B7/jgcCNVKXOW7EfzdrEcUj7G7OpEH/RGXC5ycW8npeCGpjV/0jaj6yCd5w AkHgE7+5iwpV+SVZFt1Jnidjoq5hOCv6f/L5+BpRYmp+XuFhW3zUSBn4LAfqrEP8n/iu oeUqq3iFU6+P7c3XDHhiNzzm/6Qnspxnyc6qQIFOyUw5ttaQnoRssEpoCZhMMPy9JOYm ETbNOo83fUeQ1P3pDgFH9MgGpHTltSyQOx5d//gv1EsgyIPPCHw/cuMW5kOtq5ElU4Q+ +khOC4E4chiZMoVj79UIbbPOG9WzoOIK1tSRybNqNm87uo0Y7bf4hL0pdsm6VRfpdZ1V 0WKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=SjHAV7dvNd//RvgV8SjSba3j/0gCXXBlFZTbdrPOP8U=; b=HiNf/rZDj10O4X8mZhZMNr9qxt3Yl9oGa3NIy7lbkbY/6r3oMyX8WoMY9RFsy3icCg uJ5KQSrh4fj+1vNospReHMe97nEuyRrOH9Y7fw2ltHCFa+VvWG/BcdN//kG5hE5GGXZ5 So4L4aZOlfBnauHhm06GAiIVDuRt1X93LSuNBc/k9ZoqV/Xa7ebJudUfr7ok+0q7nTyN 8Kg3IHIJ+CmEhwLdUleSY+3wzJh8O9cw3tZ8EcQCF7fB86paCluHgM2mnWQ1u6mZs0Qg PwutmeVSn3djvt5rM4x+wZgjK3dmBOkZu0a1fDYiH5oL9KX7ISe5WW2I4Hb7g9GfyEg1 EHug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BbT1W8mO; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g22si2388723edq.111.2020.07.09.08.39.23; Thu, 09 Jul 2020 08:39:46 -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=@kernel.org header.s=default header.b=BbT1W8mO; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726910AbgGIPir (ORCPT + 99 others); Thu, 9 Jul 2020 11:38:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:44298 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726339AbgGIPir (ORCPT ); Thu, 9 Jul 2020 11:38:47 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.37.151]) (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 012D720720; Thu, 9 Jul 2020 15:38:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594309126; bh=L0YHyaVnrGtsrYU/MOJaw8jpmow7WmEpb0uvKXYmZ/w=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BbT1W8mOKlsd9oZlX+zEwJ+k4sQrfbiB+LYaqVy6quzl84kh3UMvL9E1ZEqLes9kv jDh9/S7dyTE+tehwP+Ctr+jup7P9ZqNHyc1HjpYaGbAxzNvdKHj1YlAROST2en5Ka8 7LAW7cT5QZHXANkqGHgq8FWp34kCXYUh55kU/RuA= Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 11AD4405FF; Thu, 9 Jul 2020 12:38:44 -0300 (-03) Date: Thu, 9 Jul 2020 12:38:44 -0300 From: Arnaldo Carvalho de Melo To: Ian Rogers Cc: Jiri Olsa , Numfor Mbiziwo-Tiapo , Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Namhyung Kim , Song Liu , mbd@fb.com, LKML , Stephane Eranian Subject: Re: [PATCH v2] Fix annotate.c use of uninitialized value error Message-ID: <20200709153844.GA7487@kernel.org> References: <20190726194044.GC24867@kernel.org> <20190729205750.193289-1-nums@google.com> <20190807113244.GA9605@krava> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Wed, Jul 08, 2020 at 05:54:47PM -0700, Ian Rogers escreveu: > 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? Finally processed, thanks for the multiple reminders, - Arnaldo > > 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 > > > > -- - Arnaldo