From patchwork Fri Sep 27 09:35:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 174622 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp3245746ill; Fri, 27 Sep 2019 02:37:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqxHSRzoiJRwa9+YuDPksk7LMI8wp+y9xi3d1LzvW23GwvtDGz5WDAYiixICAtSO3g6EXTNb X-Received: by 2002:a50:93a4:: with SMTP id o33mr3514769eda.0.1569577045685; Fri, 27 Sep 2019 02:37:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569577045; cv=none; d=google.com; s=arc-20160816; b=huYKi9Mig/lntXtFuPU0mBKHBJ25LfF2/U7AP6kMKB2+fXBnsgUIwm0N8a18JCTtYK jSAMmGGZjuxq4+FAzMbA6D9u3YMQZ07u+OV7g6Bar7+l1YrSTB90Hlh6QLITGi/G/tPL AKv6Q2h5RjQkctiqtTLY8v5aGbt/fI+PimdVb1f20ijN4GOwVqB2S3wezywhYorw3VIe vBRDHaTcp0a04FPdfib0urECeC5DxD5sOFT3I6hfllUyEG3kL8xanAPo8m52pUPrn4gk FvvtEjAZyZx7eOrclxiTFMVlMm9AVYVkoBOs4l2kQfza2Myvbvw8uozCPmcx20EDC8Pi R4PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=vJzF8WlgUqc1RsR95UB9lwwYV0dr5aBFLgK7a4VpJl0=; b=oN19MpCtg/MiGHa/kdmNMjfdUtpTUfQ6sZbT4CEvZoO5BYzZC2fej6EJjMc1aiMfax KvV4/sIErVXAw7qWaScuUUe4YccjDVVObo5xkCadVzs7HY0jQjDqrU40jw8wp1rc5p4m 8DG7+HofUNCdTisFwM96zDvKRfZZWHnNjs2z8Eatb4zhAYo3zM4xsvt03sBhH6LEtHkX QKZ7WB0SQhfM4Cxk5TTO89h3ixn9DNLSeVa4bFqjrbBdytDPKavBhdP1ga9pCAIlTJPN gQD5N1BL8xvVaqaUMmBI6IopFyxfQMiYieMexZzc0pYtMkm0FUFdqQ87E8OQE4koq8fV ubkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b="a/t82mTw"; 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 z7si2386219ejr.99.2019.09.27.02.37.25; Fri, 27 Sep 2019 02:37:25 -0700 (PDT) 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=@nifty.com header.s=dec2015msa header.b="a/t82mTw"; 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 S1727164AbfI0JhW (ORCPT + 26 others); Fri, 27 Sep 2019 05:37:22 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:33057 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726438AbfI0JhC (ORCPT ); Fri, 27 Sep 2019 05:37:02 -0400 Received: from localhost.localdomain (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-07.nifty.com with ESMTP id x8R9a5ub001372; Fri, 27 Sep 2019 18:36:07 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com x8R9a5ub001372 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1569576967; bh=vJzF8WlgUqc1RsR95UB9lwwYV0dr5aBFLgK7a4VpJl0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a/t82mTwbwWZPr0/tQv9F1qEmfxY+FFesX4KbzmGMTG21vQhlXMBP7rrvpG/Gvk6w EC+o8FZKVJbbAVEZoykh5cD2QqCDz/m+73YH1vmQ2Up3QMvK99h0chvD0XxdoYMafC uOsZH+QvFnmPwiHz1IRaSCJXFXASiKeDWhOTxiFDswTY2pRWlD9V3c//TfIpSFUCwr Rz0S84dpoQubEEROWm9wXT/T9ga6jnFTjaA5V4G6/pBsqw1cEZTCcCRkj3XXFk4KLL 2mhnuT7X3lne5Abip9GRwCQrTuntCf8So9MR7YqWsmfYyqDEW/17TOx+STvRxZF6TM Cy6NJ4OYl1HKw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: Jessica Yu Cc: Matthias Maennich , Greg Kroah-Hartman , Joel Fernandes , Martijn Coenen , Will Deacon , Masahiro Yamada , Michal Marek , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/7] modpost: fix broken sym->namespace for external module builds Date: Fri, 27 Sep 2019 18:35:57 +0900 Message-Id: <20190927093603.9140-2-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190927093603.9140-1-yamada.masahiro@socionext.com> References: <20190927093603.9140-1-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, external module builds produce tons of false-positives: WARNING: module uses symbol from namespace , but does not import it. Here, the part shows a random string. When you build external modules, the symbol info of vmlinux and in-kernel modules are read from $(objtree)/Module.symvers, but read_dump() is buggy in multiple ways: [1] When the modpost is run for vmlinux and in-kernel modules, sym_extract_namespace() correctly allocates memory for the namespace. On the other hand, read_dump() does not, then sym->namespace will point to somewhere in the line buffer of get_next_line(). The data in the buffer will be replaced soon, and sym->namespace will end up with pointing to unrelated data. As a result, check_exports() will show random strings in the warning messages. [2] When there is no namespace, sym_extract_namespace() returns NULL. On the other hand, read_dump() sets namespace to an empty string "". (but, it will be later replaced with unrelated data due to bug [1].) The check_exports() shows a warning unless exp->namespace is NULL, so every symbol read from read_dump() emits the warning, which is mostly false positive. To address [1], I added NOFAIL(strdup(...)) to allocate memory. For [2], I changed the if-conditional in check_exports(). Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.17.1 Reviewed-by: Matthias Maennich diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 3961941e8e7a..5c628a7d80f7 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -2195,7 +2195,7 @@ static int check_exports(struct module *mod) else basename = mod->name; - if (exp->namespace) { + if (exp->namespace && exp->namespace[0]) { add_namespace(&mod->required_namespaces, exp->namespace); @@ -2453,7 +2453,7 @@ static void read_dump(const char *fname, unsigned int kernel) mod = new_module(modname); mod->skip = 1; } - s = sym_add_exported(symname, namespace, mod, + s = sym_add_exported(symname, NOFAIL(strdup(namespace)), mod, export_no(export)); s->kernel = kernel; s->preloaded = 1;