Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp3198345ybn; Fri, 27 Sep 2019 02:41:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqw9FKZoqidwbe8n/NmZyYMAtpHlHEFEyQTCcEyaMiSUGHbQKQXHDdnrdh1q9GgSIB6Qep3T X-Received: by 2002:aa7:d386:: with SMTP id x6mr3385032edq.264.1569577269300; Fri, 27 Sep 2019 02:41:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569577269; cv=none; d=google.com; s=arc-20160816; b=Nyz19/EvKYD6CHLa3mHgZ82/dwqDd37R6vssjmAam3+j8ScmXd/6YDcY2wMSStRaBY 3zEzJmmP6aC+RJQ4LtOH/4huKHjZApkLuclhwa1Ylhynq1ecly7f9Anr4J960+NGuYBR XoQf7cpGEFh6IWf71++OjYpjhOgOsF/bBvPonBbSY6Xnz5t24pJn6/DQ1X01PFSvBoOI IiANWWxv2MlAKaK3fQbHqT/3BvJGlFnzWhZS5Ied1gzpX9k7zuTW8XGYz5vtzJnCD/xE 0V9jUpq/2Q9jds9Oelkt8APtHJdQntnJdRTs57xxkWNMo8j7snBNwJhlHQcfuZpY/srl +pAw== 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 b11si2486424eja.38.2019.09.27.02.40.43; Fri, 27 Sep 2019 02:41:09 -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 S1727154AbfI0JhW (ORCPT + 99 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(-) 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; -- 2.17.1