Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp3327452ybn; Fri, 27 Sep 2019 04:50:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqzl8450SkqAjdR7YwIOIJI53Gk0dQOF1eZRcq5btf84FTMTnLkJMXXcIANLrCzPXHu0fADq X-Received: by 2002:a17:906:e288:: with SMTP id gg8mr7270155ejb.24.1569585013150; Fri, 27 Sep 2019 04:50:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569585013; cv=none; d=google.com; s=arc-20160816; b=A+N8Fepxkjtev+8BKtm8hj/nV5NXep49ge6PMQpMqaQo/MR5Qp7MTic4gP5ZOq1fqr 5p4OT7EAj/MHHho9NDhCB6AkDR9VDlhM5PhLVDd66UCz33Dapzhy04UnB1GVysYHW1+f cvArAX/1nhgpuEm7qYUADxU1aQaqq3v/xccLjBG6hUkE2MzEDcagBzY1wRbQo1oYUxH6 HVQDD3XLY8jpQrzHtWIg1DwfKPmv1soGsNtJTflCsdVT1vu04wNDuPOIcthDgLz9Mr56 vaAAwz7BjCGupGsC9eNpftCf2FdE7JWP7dTKYCCV540MYzWlczvwTKcAXlDihE13omh+ YKQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Mo7w1y+kTxQvAhwo3KNKSDDsQrA2Q4cN6VWd/Y+DTgg=; b=egAlcvF770KBcauacT8v5bQPXHZMAjG9bf3PUN8N/kM77pgpuVkZIUn29ZDVuRNBFO KEmWFW5FvSUU0/USg3lQ79Tk+KFv/9VWD9wfg9UfL0bPC3JJE6Y+n13Zyqxes/oQtBF6 VXk50NniXg6I8b82uDTKdx55QFyX4JFt75RFroQn4IPrIeoj+3pQG255GCp+l/ClMpRq CarqjYeCkvqUDVE+PUs9SFaICXk4B0DnbClEF72UshySxd0UgMSH4xjmxmtDjgHdlD8V jEhWu94LCn8FuuiKq1BFOdIIv2aNpkb9pzhC+3ul0S+3ZGDzn0YgY4gnYzIEDB9ui714 9ZMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=eLQf3+58; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a53si1467929edc.175.2019.09.27.04.49.48; Fri, 27 Sep 2019 04:50:13 -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=@google.com header.s=20161025 header.b=eLQf3+58; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727184AbfI0Lqw (ORCPT + 99 others); Fri, 27 Sep 2019 07:46:52 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:41404 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726441AbfI0Lqw (ORCPT ); Fri, 27 Sep 2019 07:46:52 -0400 Received: by mail-wr1-f66.google.com with SMTP id h7so2368172wrw.8 for ; Fri, 27 Sep 2019 04:46:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Mo7w1y+kTxQvAhwo3KNKSDDsQrA2Q4cN6VWd/Y+DTgg=; b=eLQf3+58GleOYNxjl36MGqUEZ9Mz97JQrIZ0wcBlZySF37+bB4SXVYkO9JeCO1ZdTu WpsxmTCLhiUx4a56NRkegqpijByiDrYtr5E10yx2AOL7moE7RRGoOcO/9MS0Dp25qLan UUyTEYT/atpvCbBcG1zBLdqANesE2OhVPr/MqHZmL3SVT9ZMhl7yt7vTZf/LMSDjyaKw QcjK+R8UJevHyp+Bqp5bJtCu4ERVMKT3/8cqBqSNgvRSSyOU9oHQ+Cx6jWzzis82lj02 CdP8Eof5378ZxsQGgWIkEwPOghh8v9imHLXt5JOudD1vUrC9XwW/9k1t+wG0ZSpEQMnW tRNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Mo7w1y+kTxQvAhwo3KNKSDDsQrA2Q4cN6VWd/Y+DTgg=; b=g9BdshwrexbbYFLjx0sAbRSa6rwXOoTxplbrTUowLn1OA98yYcWZ8rYQJAhollgwb8 UGPaWJR9tpvT6H5vrWjnP7DhjNKQb5c5k0f9IK0WtvIiDt0H8704fcI2JgneVOfPtQC0 Z2+AtbRp8FNuU2lLtogpKHcAedJZUYdHGJk34Calomfe6Fpwe8yviE02m0VDs2INsR3E Hr2jTKho1z9M5AAxTccaSRalda3apkeAMH3fPcKFDDae1fXaYhCeWyrNVIXoWMFcN3oK SU6az0j40uSBZsrRb7ffaYM+QWgoenwTfH3yfn3NpOa9B/8PVoahwi/1lUY0V8FeD9iU ofmQ== X-Gm-Message-State: APjAAAVG+jzXKDVCFNhW2kS9/mS1S+zbuc/aiaH21a4AzeuHsHWGKMA6 ehPiBO+/3fS40sYx+/bHciFO7w== X-Received: by 2002:a5d:6885:: with SMTP id h5mr2701094wru.92.1569584809858; Fri, 27 Sep 2019 04:46:49 -0700 (PDT) Received: from google.com ([2a00:79e0:d:210:e8f7:125b:61e9:733d]) by smtp.gmail.com with ESMTPSA id o19sm6262169wmh.27.2019.09.27.04.46.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Sep 2019 04:46:49 -0700 (PDT) Date: Fri, 27 Sep 2019 12:46:46 +0100 From: Matthias Maennich To: Masahiro Yamada Cc: Jessica Yu , Greg Kroah-Hartman , Joel Fernandes , Martijn Coenen , Will Deacon , Michal Marek , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Shaun Ruffell Subject: Re: [PATCH 1/7] modpost: fix broken sym->namespace for external module builds Message-ID: <20190927114646.GA259443@google.com> References: <20190927093603.9140-1-yamada.masahiro@socionext.com> <20190927093603.9140-2-yamada.masahiro@socionext.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20190927093603.9140-2-yamada.masahiro@socionext.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 27, 2019 at 06:35:57PM +0900, Masahiro Yamada wrote: >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(). Thanks for addressing this. Greg had reported this earlier this week and Shaun was proposing a fix earlier today. Shaun's fix also ensures that memory is released when updating the namespace. But judging from the code around 'symbolhash' it seems that leaking this is accepted for modpost. Not sure about that. Having said that, please feel free to add Reviewed-by: Matthias Maennich Cheers, Matthias >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 >