From patchwork Tue Oct 23 22:15:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 10653843 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8624D13B5 for ; Tue, 23 Oct 2018 22:15:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 710FD2A2D8 for ; Tue, 23 Oct 2018 22:15:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 64F862A45C; Tue, 23 Oct 2018 22:15:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E84FB2A2D8 for ; Tue, 23 Oct 2018 22:15:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725787AbeJXGlC (ORCPT ); Wed, 24 Oct 2018 02:41:02 -0400 Received: from mail-pg1-f201.google.com ([209.85.215.201]:36663 "EHLO mail-pg1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725985AbeJXGlC (ORCPT ); Wed, 24 Oct 2018 02:41:02 -0400 Received: by mail-pg1-f201.google.com with SMTP id a13-v6so1492332pgw.3 for ; Tue, 23 Oct 2018 15:15:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=alsxCznKlRvNPj0cP4LLsmMjM7la4Q0Zm87PjkEbJ8w=; b=lfJlInGALFAd1OIp6iUwGTXWlQqWu2DWOy/a4oxUqQi3nTBPR4mjOobZFccaCqT85g kADqBEoqv/wWpP2GGhEllXqYb9SQQnGZj7wIicq+rNw4JnGaH3+6+1YpU16nDluLdSVz xznVvlyecwJoZ5v+LkoxZsPqu3xK70wCy+DUG1tqZmVf73mFyLW06WwwT6gEzPfJTRo0 NCnpmiTT2azJBhkrlZiumDAtnofURuoTkwZ5q+gtLuUuPTJ3gXezi8yPB4bcx518ly6L PZ1blWLzDD93gDd3frPDA6YZfBP9KCptC6+mBnsbe36LJm0zxph5FhRBhhH6SzUm12je vewQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=alsxCznKlRvNPj0cP4LLsmMjM7la4Q0Zm87PjkEbJ8w=; b=csMaHKcRKlbQJZWVQZNY1O3dMrHXSKU91zdRgD4PpQtjk22BgNt9PDPiUH3wNp72q/ 5zvTQGcaD8Pj6HJjwyK/nBJDM+in4LesO2JWMt/N66pQGKD9vlJeAR+4SyhKcCeKrFlA HN7pX9G/2ihY2CmYs2/IEgXV3Z/qSGGAhX3RquOAnHhEYflohfgVhf7Mm+Nz/6ZXbElL y+lqegL7tgS+QEDWQBaQHtw9VJcTppPz4qKy2uFEuVIpa8kIedIzpRhmSUcgyWJaYl1X 0MB60sNduaExH5l7ljYwLQlDZwF6U0usmkjfzP9y/3iq3lW7TlEeb8UnyrQycdO/eCQG Oddw== X-Gm-Message-State: AGRZ1gIXzelBXXTnVzGSO+9wrhhObO5E1yQuuF/Q2BuMyeGEfWhM/SJu ECVotbxQ0vN5GCBsS8+NWCXLAvPOJenGepFRJTE= X-Google-Smtp-Source: AJdET5c3UK5TFHmwurixIcGKuD+7CpQQhAxY18huCnlDWkhbaOuhf9LsZHTB968Fre3Jj5rKGuXHe1x/jQ5c8bNHfBA= X-Received: by 2002:a62:2055:: with SMTP id g82-v6mr87502pfg.28.1540332941776; Tue, 23 Oct 2018 15:15:41 -0700 (PDT) Date: Tue, 23 Oct 2018 15:15:35 -0700 Message-Id: <20181023221535.4740-1-samitolvanen@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.19.1.568.g152ad8e336-goog Subject: [PATCH] modpost: validate symbol names also in find_elf_symbol From: Sami Tolvanen To: Masahiro Yamada , Michal Marek Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Sami Tolvanen Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 0d998c54564d..b709b2e623d6 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.