Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2724781imj; Mon, 11 Feb 2019 07:33:06 -0800 (PST) X-Google-Smtp-Source: AHgI3IY7bo7SZxMkF59Z02YCRIpwXpbh52RqugBdJ0/FP56jfgOcn/tEb4aQJrOZLfAK5TMXLLJN X-Received: by 2002:a17:902:6941:: with SMTP id k1mr15418073plt.195.1549899186448; Mon, 11 Feb 2019 07:33:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549899186; cv=none; d=google.com; s=arc-20160816; b=aOGh3GhfQ5jVw/ZDEKNcGBTI6uqGcc/8UG3TcwJEozIUhkMDYzFMIh6L7MDknuhQON ZkfTx4TIIGLSO4nYgO1fBR8Y2YRh6Brnz/8H/fl5JS8ZjrjvvXrBNNlbb/OH4ZrVuw5o SlxMfJ9mEHWiseijgDz8stiMV+doO66z+xKLFYGJadCKR0NWkWr1vFtHSjN6kUozQ+Is 4/v6MTzl31IFt5d2R4fuKoUxtCXs8/q3YNAp+Mpg9DJw4zAqBds3UEqpdL33FRDze48O VWBxquNZx21B4y/xvvnwRxCzyAwW4lwNMzGOAg8CebN9nfjhYPpGiLnmHO9ymlbJxK58 z6Vw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GUF6Fjep+w5xKky54tf5TxLRs9h6l0lzya90cmuXYs0=; b=Di78q8qyK68Tot/wpcmndrdbMUTyE9vJC4GLdJ4IP6MVdwQl1pMVIh1tcXqPJlpkBI EBvGm/c1fyCIgCRsdQ+7V2KiFn+iGPKAWqgPPmuxr7ZZpB9/q+4nG8oZg96zLbrL6IOQ q7IxtmIb0E/Gletiic2L7pU9y1+2If2PtJ2FPSx0t1Dip/YpsbPIX3/xNFGFGrTIRFhc NttRbrOFYxO/23PYbbZE307z5bh5wLPczPSR2rSiGKdE0bjegmtfC0lB/kSVVmw3WRMv KuB5414JzSyBQ5SS4MVDg0MhbDfO3IkrMnbW1S3wMEXs/9zpjFFQqfpLJoBb5p6+tKl/ wLRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mO2BD9qh; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 35si7927559pgn.278.2019.02.11.07.32.50; Mon, 11 Feb 2019 07:33:06 -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=mO2BD9qh; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388947AbfBKOzT (ORCPT + 99 others); Mon, 11 Feb 2019 09:55:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:42230 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728874AbfBKOzP (ORCPT ); Mon, 11 Feb 2019 09:55:15 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 AF96A2229E; Mon, 11 Feb 2019 14:55:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549896914; bh=zbk7SqNJ7efIYq2sgDwoiy0FrdC6MKgCTS3/1A05Qao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mO2BD9qhbu5ZCMxVFSlbBctwAaRGgd2Ql5BCNM21dboi1aWtZCdqTtMFCSxBkNBxW aESBkUXW2Ulf2RSTirTWBrq/5A2tL56ir5q6Za+O+LHwX/48HzrnYa1NU3mPnB+A0t /pY5EPAXO2z3eBg5WGcxlG37q+jbWVb/LmxI4CZs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sami Tolvanen , Masahiro Yamada , Sasha Levin Subject: [PATCH 4.14 030/205] modpost: validate symbol names also in find_elf_symbol Date: Mon, 11 Feb 2019 15:17:08 +0100 Message-Id: <20190211141829.730972001@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141827.214852402@linuxfoundation.org> References: <20190211141827.214852402@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ [ 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 18bc8738e989..e36a673833ae 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1215,6 +1215,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 @@ -1240,6 +1264,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 */ @@ -1258,30 +1284,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