Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932541AbcLSShZ (ORCPT ); Mon, 19 Dec 2016 13:37:25 -0500 Received: from mail.kernel.org ([198.145.29.136]:48894 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753183AbcLSShY (ORCPT ); Mon, 19 Dec 2016 13:37:24 -0500 Date: Mon, 19 Dec 2016 15:37:16 -0300 From: Arnaldo Carvalho de Melo To: Markus Trippelsdorf Cc: linux-kernel@vger.kernel.org, Ingo Molnar Subject: Re: *** buffer overflow detected ***: /usr/src/linux/tools/perf/perf terminated Message-ID: <20161219183716.GB551@kernel.org> References: <20161219161821.GA294@x4> <20161219165243.GA289@x4> <20161219172842.GB289@x4> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20161219172842.GB289@x4> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.7.1 (2016-10-04) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1658 Lines: 46 Em Mon, Dec 19, 2016 at 06:28:42PM +0100, Markus Trippelsdorf escreveu: > On 2016.12.19 at 17:52 +0100, Markus Trippelsdorf wrote: > > On 2016.12.19 at 17:18 +0100, Markus Trippelsdorf wrote: > > > Running the latest kernel git tree, I get buffer overflow warnings when > > > I try to run "perf top": > > > > > > *** buffer overflow detected ***: /usr/src/linux/tools/perf/perf terminated > > > > It only happens when I link my kernel with gold. > > And perf than chokes when parsing /sys/kernel/notes. > > Started with gold commit: > > commit bfbf34de2f27672282d4fa4c0916cc41890dcc6c > Author: Cary Coutant > Date: Mon Dec 12 18:51:29 2016 -0800 > > When using linker scripts, place linker-generated sections by the output section name. > > I've opened a gold bug: > https://sourceware.org/bugzilla/show_bug.cgi?id=20983 I guess we need something along the lines of below, but I think the max should be set to the filesize, have to spend some more time here, using stat() in such case, etc, wdyt? - Arnaldo diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 99400b0e8f2a..adbc6c02c3aa 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -537,6 +537,12 @@ int sysfs__read_build_id(const char *filename, void *build_id, size_t size) break; } else { int n = namesz + descsz; + + if (n > (int)sizeof(bf)) { + n = sizeof(bf); + pr_debug("%s: truncating reading of build id in sysfs file %s: n_namesz=%u, n_descsz=%u.\n", + __func__, filename, nhdr.n_namesz, nhdr.n_descsz); + } if (read(fd, bf, n) != n) break; }