Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3625462imu; Mon, 28 Jan 2019 08:03:32 -0800 (PST) X-Google-Smtp-Source: ALg8bN56sh8uLJ8nSgcZxS8wdGjovi88S7AqVngOEGQY7xqC5kPxikLGmykSPJowPfFY+lxvAn2j X-Received: by 2002:a63:e101:: with SMTP id z1mr20418129pgh.310.1548691412651; Mon, 28 Jan 2019 08:03:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548691412; cv=none; d=google.com; s=arc-20160816; b=PzcRBUFxGC4kwYFOwFI9CmOCSc3HaWbmEqAcbyGgJt+IfHjh9L1a9+h0wU+GMxGsLD HCiHWFoKsucV26SuWR9Ec3UzA+GSXrYK8GOtzxZF/7HKlIDY7JhS2+ETmddYdQ93wHEc 4yeMR7rpvAVvcjckwThOCl/p64yXp5NeG4huTEsaVXrp16/cjF6XC7+CLRt0QsNIZZuG OPKvR0Iy7UEBe9iJoNZXZA94dqakQLOfGBbaGoDZkYGuhykhrGnMVRMht4DcbhTwJ2fM g1/1iTqRfUBxWHzllbhbLPoVZTFOdkYoTX5cKqUy5ykqbhn/AFBVcZ2TwXHSHRU9VnV4 X7TA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nYdIHkytYG7iUF0TOJ1yndLhBwdVUQUU58HPmnTOPz0=; b=w/EB8YSwRljG78dJaLaqhPsMAxV8p5Ml8LSuF8ERp+p9r6sL6y02ibOZ23PYcujd2N dXrUgEtdFcCIj6gobL89nw8xNJWqpFPI2FOBzzKWsVobcOhw7mK8OTvcN0swB57BPfZd hUanHK40KLdstSZCKWcifz6gYlz+lXOqL6ghc721aCZQQD1FkHODqJGpPe9x23k5S1+m YwapPAhyNeOGGIHa9SMxXHRiMlvMWEkt8zLhkJI9rHMw4NO729vpl5N9BH3/8xCJw0LH yEIialtdh2Jn5DOAkpnEFYEZJCdBn/1NyEEtzLpk6kKNoypECRqGE6Tguljs8PHuyBot 4OsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=W3LJ00FQ; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 86si3792316pfl.46.2019.01.28.08.03.16; Mon, 28 Jan 2019 08:03:32 -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; dkim=pass header.i=@kernel.org header.s=default header.b=W3LJ00FQ; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731126AbfA1QBu (ORCPT + 99 others); Mon, 28 Jan 2019 11:01:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:46956 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731097AbfA1QBn (ORCPT ); Mon, 28 Jan 2019 11:01:43 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7223D2082E; Mon, 28 Jan 2019 16:01:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691302; bh=oH1gZkQ/G18Qc3EHxve7AHAYVITaIL9CZNEFG+msbcw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W3LJ00FQoPn3h2/SfLpAamfirkmVcF2JxcwzeBDmQudP49ntJKqCNUNN8kEmCAXzz x82SLAFpS/hcRCyDB4fSMCf7ZoXGT4eHdEKIGHvQPLAyRfi5EicIwpeuxl10DvsUJg DHGREhwhwGesHz3QiA9EhO+SCOMf4OlTXT6a92rk= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Sami Tolvanen , Masahiro Yamada , Sasha Levin , linux-kbuild@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 052/258] modpost: validate symbol names also in find_elf_symbol Date: Mon, 28 Jan 2019 10:55:58 -0500 Message-Id: <20190128155924.51521-52-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128155924.51521-1-sashal@kernel.org> References: <20190128155924.51521-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sami Tolvanen [ Upstream commit 5818c683a619c534c113e1f66d24f636defc29bc ] If an ARM mapping symbol shares an address with a valid symbol, find_elf_symbol can currently return the mapping symbol instead, as the symbol is not validated. This can result in confusing warnings: WARNING: vmlinux.o(.text+0x18f4028): Section mismatch in reference from the function set_reset_devices() to the variable .init.text:$x.0 This change adds a call to is_valid_name to find_elf_symbol, similarly to how it's already used in find_elf_symbol2. Signed-off-by: Sami Tolvanen Signed-off-by: Masahiro Yamada Signed-off-by: Sasha Levin --- scripts/mod/modpost.c | 50 ++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 5a5b3780456f..5a77efd39b3f 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1204,6 +1204,30 @@ static int secref_whitelist(const struct sectioncheck *mismatch, return 1; } +static inline int is_arm_mapping_symbol(const char *str) +{ + return str[0] == '$' && strchr("axtd", str[1]) + && (str[2] == '\0' || str[2] == '.'); +} + +/* + * If there's no name there, ignore it; likewise, ignore it if it's + * one of the magic symbols emitted used by current ARM tools. + * + * Otherwise if find_symbols_between() returns those symbols, they'll + * fail the whitelist tests and cause lots of false alarms ... fixable + * only by merging __exit and __init sections into __text, bloating + * the kernel (which is especially evil on embedded platforms). + */ +static inline int is_valid_name(struct elf_info *elf, Elf_Sym *sym) +{ + const char *name = elf->strtab + sym->st_name; + + if (!name || !strlen(name)) + return 0; + return !is_arm_mapping_symbol(name); +} + /** * Find symbol based on relocation record info. * In some cases the symbol supplied is a valid symbol so @@ -1229,6 +1253,8 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr, continue; if (ELF_ST_TYPE(sym->st_info) == STT_SECTION) continue; + if (!is_valid_name(elf, sym)) + continue; if (sym->st_value == addr) return sym; /* Find a symbol nearby - addr are maybe negative */ @@ -1247,30 +1273,6 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr, return NULL; } -static inline int is_arm_mapping_symbol(const char *str) -{ - return str[0] == '$' && strchr("axtd", str[1]) - && (str[2] == '\0' || str[2] == '.'); -} - -/* - * If there's no name there, ignore it; likewise, ignore it if it's - * one of the magic symbols emitted used by current ARM tools. - * - * Otherwise if find_symbols_between() returns those symbols, they'll - * fail the whitelist tests and cause lots of false alarms ... fixable - * only by merging __exit and __init sections into __text, bloating - * the kernel (which is especially evil on embedded platforms). - */ -static inline int is_valid_name(struct elf_info *elf, Elf_Sym *sym) -{ - const char *name = elf->strtab + sym->st_name; - - if (!name || !strlen(name)) - return 0; - return !is_arm_mapping_symbol(name); -} - /* * Find symbols before or equal addr and after addr - in the section sec. * If we find two symbols with equal offset prefer one with a valid name. -- 2.19.1