Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp3117506ybn; Fri, 27 Sep 2019 01:06:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqymI7cESHz4az/T5RPsI45GSyxhheNLPZQNyV1UL2s4gbAMTmmSZ18OgDrXJg7xx0dmM6j9 X-Received: by 2002:a50:e616:: with SMTP id y22mr3024994edm.253.1569571590799; Fri, 27 Sep 2019 01:06:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569571590; cv=none; d=google.com; s=arc-20160816; b=xPL49y8VPCy4VSzhfgDc0jMIDzTDbA1TNS6V4K9n91ghcUwvhWKiNgmcYX+Nk90eIH YeD4QQw2GX9T6LBeWj0ik+d5tN79IaUA9d6ZjRVS8qnqP3Yp5hsqliwU5ttbeN6jnYkd mD+qyRiJ6AgK8Pn/WpsdPrvHPM5Xq3GTa6+BbEdKZnZ7pcwhhX+nxB5ehgOpJzMBqQkr Ok27q2W7yhmIJYhjC4A32KS0RkGe4R8Hi0EIA5edR/GNyHUDd6x6SxSTUCVVX9cP0AWt dQqQoirJV9nFeKFc9wsss/Fx5ZntoEf8hOqgfj2DRkRnL4K0+F6+19Z12SFtddnRR/A/ rsLg== 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=iXDECIdI+5sEzaIUkCBUCMKW4ivbvbfbv+7BIMvn93U=; b=N902hEgTho8iCh9CicxqaZzcY/5XCFe18U44xALDmI/SrB1T2Qo4V9bqzDEdKE7QqW 7NMpf+mgK184sbMSLYOXe58uCxHRl+FT4mdqK2/D8QSSXUSdzxmbkGwp7F7ygnxUciJU nmwe72RL1DfTBgUp+K0ttT/5r6rVQ0/LmvBZPQBKYO+8Y7LTw672xkN9aEJRa3xtt811 ERTWkPGYnK6jNTB1KrFcoRhAxIm2/B0Wom9TWLLSVImFiUlJhZzHnaz2HHdFMDPCSWlB A8+RfGqE4LCBM3PsjINhNWpsUIxatn+6jbANaFXM8UxYmByPmim2tVs6k2dk4nvQQHOe msCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Z1ofcE/k"; 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 y43si1028667edd.42.2019.09.27.01.06.05; Fri, 27 Sep 2019 01:06:30 -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="Z1ofcE/k"; 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 S1726717AbfI0IDy (ORCPT + 99 others); Fri, 27 Sep 2019 04:03:54 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:37676 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725804AbfI0IDx (ORCPT ); Fri, 27 Sep 2019 04:03:53 -0400 Received: by mail-wr1-f68.google.com with SMTP id i1so1606635wro.4 for ; Fri, 27 Sep 2019 01:03:51 -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=iXDECIdI+5sEzaIUkCBUCMKW4ivbvbfbv+7BIMvn93U=; b=Z1ofcE/kKnhiFs1EHfqUgBzBhP7aONFvXUk1CaT579REfuDhrl34PTSbnIUYv/U8CE xF1dMcA0YEGeOpdYXQhn5w118mXhDAdea8FnsBVDaQJnxio45TSgShXgL/MOaYxCafmB oTzwctwO+llfcZynufRP+CPpdBgsNF0JOXDyyyV+pUEoDFZewXATbqwW6fwUhxfb9w9v wgb5vO4nHN1NMYeMoRsvscZ/loGaeACvFJdfmNtIQIleuzpPDs6W/c19ASsC99mIeCU/ kp7GgjrBsoQvA3u3xrkwdgCEMGQq/9o2e//uCJzmXvABnBJzgZAHgN8CcgjJOziO2/+F ALYA== 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=iXDECIdI+5sEzaIUkCBUCMKW4ivbvbfbv+7BIMvn93U=; b=dWkh0KXp2PHoY2cKQjtk2MT9Be3snvBOdPSEULj7dLtv+BOBRWKjhS3xl5MdF4whja hvEDsEvVY9tzvU7vCUweW8AsRY2N1ZWBi03ygVC2sQkkT0cDterRCYNfCNcWZb+YiJ6J UoFQoHaeKizcs96/Zar4wBOUx8QTSU0iYo+eAEHCFOr9idosnjbEmfEP8O52jZgg6woH DVmRDN9uBQRgAwHDhbFc/hUb37cOo5ykBhzZQeGA7IogyDh390kRuVl7LwcTsPi298wT fP6C8epFoJG/AWY6ppE4XMNOKHbvFqLXB4cDGSjPAF5biufxRdV3wyoltd9qnhIGun+U cDWQ== X-Gm-Message-State: APjAAAXVVPuM6KSt8qHFTe9QDNyeccG4P96uZq/io8VklhjpsMrGFhFQ 49nwMfRnaN3wT9TvyN0d0bKln1m7uOtcrzT8 X-Received: by 2002:a5d:460b:: with SMTP id t11mr1694797wrq.377.1569571430103; Fri, 27 Sep 2019 01:03:50 -0700 (PDT) Received: from google.com ([2a00:79e0:d:210:e8f7:125b:61e9:733d]) by smtp.gmail.com with ESMTPSA id y13sm3051266wrg.8.2019.09.27.01.03.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Sep 2019 01:03:49 -0700 (PDT) Date: Fri, 27 Sep 2019 09:03:46 +0100 From: Matthias Maennich To: Shaun Ruffell Cc: linux-kernel@vger.kernel.org, Martijn Coenen , Joel Fernandes , Greg Kroah-Hartman , Jessica Yu Subject: Re: [PATCH] modpost: Copy namespace string into 'struct symbol' Message-ID: <20190927080346.GC90796@google.com> References: <20190906103235.197072-5-maennich@google.com> <20190926222446.30510-1-sruffell@sruffell.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20190926222446.30510-1-sruffell@sruffell.net> 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 Thu, Sep 26, 2019 at 05:24:46PM -0500, Shaun Ruffell wrote: >When building an out-of-tree module I was receiving many warnings from >modpost like: > > WARNING: module dahdi_vpmadt032_loader uses symbol __kmalloc from namespace ts/dahdi-linux/drivers/dahdi/dahdi-version.o: ..., but does not import it. > WARNING: module dahdi_vpmadt032_loader uses symbol vpmadtreg_register from namespace linux/drivers/dahdi/dahdi-version.o: ..., but does not import it. > WARNING: module dahdi_vpmadt032_loader uses symbol param_ops_int from namespace ahdi-linux/drivers/dahdi/dahdi-version.o: ..., but does not import it. > WARNING: module dahdi_vpmadt032_loader uses symbol __init_waitqueue_head from namespace ux/drivers/dahdi/dahdi-version.o: ..., but does not import it. > ... > >The fundamental issue appears to be that read_dump() is passing a >pointer to a statically allocated buffer for the namespace which is >reused as the file is parsed. Hi Shaun, Thanks for working on this. I think you are right about the root cause of this. I will have a closer look at your fix later today. >This change makes it so that 'struct symbol' holds a copy of the >namespace string in the same way that it holds a copy of the symbol >string. Because a copy is being made, handle_modversion can now free the >temporary copy > >Fixes: cb9b55d21fe0 ("modpost: add support for symbol namespaces") >Cc: Martijn Coenen >Cc: Joel Fernandes (Google) >Cc: Greg Kroah-Hartman >Cc: Matthias Maennich >Cc: Jessica Yu >Signed-off-by: Shaun Ruffell >--- > >Hi, > >I didn't test that this change works with the namespaces, or investigate why >read_dump() is only called first while building out-of-tree modules, but it does >seem correct to me for the symbol to own the memory backing the namespace >string. > >I also realize I'm jumping the gun a bit by testing against master before >5.4-rc1 is tagged. > >Shaun > > scripts/mod/modpost.c | 31 +++++++++++++++++++++++++++++-- > 1 file changed, 29 insertions(+), 2 deletions(-) > >diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c >index 3961941e8e7a..349832ead200 100644 >--- a/scripts/mod/modpost.c >+++ b/scripts/mod/modpost.c >@@ -364,6 +364,24 @@ static const char *sym_extract_namespace(const char **symname) > return NULL; > } > >+static const char *dup_namespace(const char *namespace) >+{ >+ if (!namespace || (namespace[0] == '\0')) >+ return NULL; >+ return NOFAIL(strdup(namespace)); >+} >+ >+static bool is_equal(const char *n1, const char *n2) >+{ >+ if (n1 && !n2) >+ return false; >+ if (!n1 && n2) >+ return false; >+ if (!n1 && !n2) >+ return true; >+ return strcmp(n1, n2) == 0; >+} >+ > /** > * Add an exported symbol - it may have already been added without a > * CRC, in this case just update the CRC >@@ -375,7 +393,7 @@ static struct symbol *sym_add_exported(const char *name, const char *namespace, > > if (!s) { > s = new_symbol(name, mod, export); >- s->namespace = namespace; >+ s->namespace = dup_namespace(namespace); > } else { > if (!s->preloaded) { > warn("%s: '%s' exported twice. Previous export was in %s%s\n", >@@ -384,6 +402,12 @@ static struct symbol *sym_add_exported(const char *name, const char *namespace, > } else { > /* In case Module.symvers was out of date */ > s->module = mod; >+ >+ /* In case the namespace was out of date */ >+ if (!is_equal(s->namespace, namespace)) { >+ free((char *)s->namespace); >+ s->namespace = dup_namespace(namespace); >+ } > } > } > s->preloaded = 0; >@@ -672,7 +696,6 @@ static void handle_modversions(struct module *mod, struct elf_info *info, > unsigned int crc; > enum export export; > bool is_crc = false; >- const char *name, *namespace; > > if ((!is_vmlinux(mod->name) || mod->is_dot_o) && > strstarts(symname, "__ksymtab")) >@@ -744,9 +767,13 @@ static void handle_modversions(struct module *mod, struct elf_info *info, > default: > /* All exported symbols */ > if (strstarts(symname, "__ksymtab_")) { >+ const char *name, *namespace; >+ > name = symname + strlen("__ksymtab_"); > namespace = sym_extract_namespace(&name); > sym_add_exported(name, namespace, mod, export); >+ if (namespace) >+ free((char *)name); This probably should free namespace instead. > } > if (strcmp(symname, "init_module") == 0) > mod->has_init = 1; >-- >2.17.1 Cheers, Matthias