linux/scripts/mod
Masahiro Yamada 389eb3f5f4 modpost: fix broken sym->namespace for external module builds
Currently, external module builds produce tons of false-positives:

  WARNING: module <mod> uses symbol <sym> from namespace <ns>, but does not import it.

Here, the <ns> 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() 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], sym_add_exported() calls strdup() for s->namespace.
The namespace from sym_extract_namespace() must be freed to avoid
memory leak.

For [2], I changed the if-conditional in check_exports().

This commit also fixes sym_add_exported() to set s->namespace correctly
when the symbol is preloaded.

Reviewed-by: Matthias Maennich <maennich@google.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Jessica Yu <jeyu@kernel.org>
2019-10-07 18:24:58 +02:00
..
.gitignore kbuild: trivial - remove trailing empty lines 2014-06-10 00:04:06 +02:00
devicetable-offsets.c platform-drivers-x86 for v5.1-1 2019-03-10 13:16:37 -07:00
empty.c
file2alias.c modpost: add guid_t type definition 2019-09-04 22:55:42 +09:00
Makefile kbuild: move modpost out of 'scripts' target 2018-12-01 23:09:34 +09:00
mk_elfconfig.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
modpost.c modpost: fix broken sym->namespace for external module builds 2019-10-07 18:24:58 +02:00
modpost.h modpost: add support for generating namespace dependencies 2019-09-10 10:30:38 +02:00
sumversion.c kbuild: remove the first line of *.mod files 2019-07-18 02:19:31 +09:00