Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3062874imu; Mon, 19 Nov 2018 10:04:36 -0800 (PST) X-Google-Smtp-Source: AJdET5c8tRzXE/bWnGxSKz7FihgTOYD3Oh1x5Y51EoXMGFV9DsxHI/oe26MtoKTmn8TZ9VYEs8U8 X-Received: by 2002:a63:5a08:: with SMTP id o8mr20814416pgb.185.1542650676664; Mon, 19 Nov 2018 10:04:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542650676; cv=none; d=google.com; s=arc-20160816; b=tpveuc2SRPebxUqnkQqhUm2k+6gaV/HxTqoBB2bYdzppxPmCGPPN7judS7R6mRyalO +VguwwBp0jzTlU7c0ktDnkPBZleyTvIim/4Urhkr/8cSS+hTQ5dOnt10Y/HFr7Qlqa1L vGNcLAqNAXmzwwvqX8O8FakbNDTWEhwrUVLZgEJls2l5RzFRNgdmpKfi/jlZsRjv/BmL nI8RzmefZLEuWHI8RCB0PbQZCcNYnWnboAZa1AnHBm5KYnPmdYP1CgnZEBEDOvnECH3w uVYnTqY9uxwxwzrledKF2DtJquVLtG4Wudrk/DRzFlTai701YJiawJeuBk5nsCMTYdaZ 6ybw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=JG3O9oQi6ksE2gYFydf7+Ob0tZARJDWwckNUwOMmPm8=; b=dB+R0LGDxfU2NZli6gnx/2fi4vEh3+30JvDvCdALVpqQju1aGOphGH+uUTj23f6Jam 41rTg6seWmMnAO9rL0z3grFs+2NsAJZ6Xb3KZ0k3c7F9Y5c2CNiDniwnoGkbcb8WRwCB V6DIo/OuLooSSWxcbstX6ipe+gdW/xePG+5U2BdOC2/OqjW1CD6+NvP1d/RS/rWpIR15 7KnbwHpL/de3vDujsHQnNdz9LZzfxiBZWzR65UahDYmvu56KfGa297e+uNLZ3zLhy1aF CGYkzOEVVGnCkPn01xjempZRiDXe99Ha/O7yNRJUdLeI4y9wvYLNfB/a7exilA1O8A/L IkJg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h68si1519994plb.375.2018.11.19.10.04.09; Mon, 19 Nov 2018 10:04:36 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731423AbeKTE1P (ORCPT + 99 others); Mon, 19 Nov 2018 23:27:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38756 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730227AbeKTE1P (ORCPT ); Mon, 19 Nov 2018 23:27:15 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CD2B6307D853; Mon, 19 Nov 2018 18:02:40 +0000 (UTC) Received: from treble (ovpn-126-32.rdu2.redhat.com [10.10.126.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4D58C60C67; Mon, 19 Nov 2018 18:02:40 +0000 (UTC) Date: Mon, 19 Nov 2018 12:02:33 -0600 From: Josh Poimboeuf To: Artem Savkov Cc: Peter Zijlstra , linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 2/2] objtool: fix .cold functions parent symbols search Message-ID: <20181119180233.mdvuah3geacujpr4@treble> References: <20181112033800.ujolxvkwzz72lxhm@treble> <20181112125519.26855-1-asavkov@redhat.com> <20181112125519.26855-3-asavkov@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20181112125519.26855-3-asavkov@redhat.com> User-Agent: NeoMutt/20180716 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Mon, 19 Nov 2018 18:02:40 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 12, 2018 at 01:55:19PM +0100, Artem Savkov wrote: > Because find_symbol_by_name() traverses the same lists as read_symbols() > changing sym->name in place without copying it affects the result of > find_symbol_by_name() and, in case when ".cold" function precedes it's > parent in sec->symbol_list, can result in function being considered a > parent of itself. This leads to function length being set to 0 and other > consequent side-effects including a segfault in add_switch_table(). > The effects of this bug are only visible when building with > -ffunction-sections in KCFLAGS. > > Fix by copying the search string instead of modifying it in place. > > Fixes: 13810435b9a7 "objtool: Support GCC 8's cold subfunctions" Same here, needs parentheses. > Signed-off-by: Artem Savkov > --- > tools/objtool/elf.c | 17 ++++++++++++++--- > 1 file changed, 14 insertions(+), 3 deletions(-) > > diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c > index 3decd43477df..15d9acfb2c97 100644 > --- a/tools/objtool/elf.c > +++ b/tools/objtool/elf.c > @@ -31,6 +31,8 @@ > #include "elf.h" > #include "warn.h" > > +#define MAX_NAME_LEN 128 > + > struct section *find_section_by_name(struct elf *elf, const char *name) > { > struct section *sec; > @@ -298,6 +300,8 @@ static int read_symbols(struct elf *elf) > /* Create parent/child links for any cold subfunctions */ > list_for_each_entry(sec, &elf->sections, list) { > list_for_each_entry(sym, &sec->symbol_list, list) { > + char pname[MAX_NAME_LEN + 1]; > + size_t pnamelen; > if (sym->type != STT_FUNC) > continue; > sym->pfunc = sym->cfunc = sym; > @@ -305,9 +309,16 @@ static int read_symbols(struct elf *elf) > if (!coldstr) > continue; > > - coldstr[0] = '\0'; > - pfunc = find_symbol_by_name(elf, sym->name); > - coldstr[0] = '.'; > + pnamelen = coldstr - sym->name; > + if (pnamelen > MAX_NAME_LEN) { > + WARN("%s(): parent function name exceeds maximum length of %d characters", > + sym->name, MAX_NAME_LEN); > + goto cold_err; Same here, makes more sense to just return -1 and let elf_close() clean it up I think. -- Josh