lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu,  2 Nov 2023 00:04:04 +0900
From:   Masahiro Yamada <masahiroy@...nel.org>
To:     linux-kbuild@...r.kernel.org
Cc:     linux-kernel@...r.kernel.org, Greg Ungerer <gerg@...nel.org>,
        Jack Brennen <jbrennen@...gle.com>,
        Masahiro Yamada <masahiroy@...nel.org>,
        Nathan Chancellor <nathan@...nel.org>,
        Nick Desaulniers <ndesaulniers@...gle.com>,
        Nicolas Schier <nicolas@...sle.eu>
Subject: [PATCH 7/7] modpost: look up the correct symbol in check_export_symbol()

Greg Ungerer reported modpost produced false-positive
"local symbol '...' was exported" errors when m68k-uclinux-gcc is used.

I had assumed ELF_R_SYM(Elf_Rela::r_info) pointed to the exported symbol
itself if it is in the global scope. This assumption worked for many
toolchains, but as it turned out, it was not true for m68k-uclinux-gcc,
at least.

If the 'sym' argument passed to check_export_symbol() is not the
exported symbol, look up the correct one in the symbol table. It incurs
a search cost, but since we know its section index and address, we can
exploit the binary search.

Reported-by: Greg Ungerer <gerg@...nel.org>
Closes: https://lore.kernel.org/all/1fac9d12-2ec2-4ccb-bb81-34f3fc34789e@westnet.com.au/
Signed-off-by: Masahiro Yamada <masahiroy@...nel.org>
---

 scripts/mod/modpost.c | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 896ecfa8483f..ee67bc6d71ee 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -1021,6 +1021,18 @@ static Elf_Sym *find_tosym(struct elf_info *elf, Elf_Addr addr, Elf_Sym *sym)
 				      true, 20);
 }
 
+static Elf_Sym *find_tosym_with_name(struct elf_info *elf, Elf_Addr addr,
+				     Elf_Sym *sym, const char *name)
+{
+	/* If the supplied symbol has the expected name, return it. */
+	if (!strcmp(sym_name(elf, sym), name))
+		return sym;
+
+	/* Look up a symbol with the given name. */
+	return symsearch_find_with_name(elf, addr, get_secindex(elf, sym),
+					true, 20, name);
+}
+
 static bool is_executable_section(struct elf_info *elf, unsigned int secndx)
 {
 	if (secndx >= elf->num_sections)
@@ -1079,7 +1091,7 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf,
 
 static void check_export_symbol(struct module *mod, struct elf_info *elf,
 				Elf_Addr faddr, const char *secname,
-				Elf_Sym *sym)
+				Elf_Sym *sym, Elf_Addr taddr)
 {
 	static const char *prefix = "__export_symbol_";
 	const char *label_name, *name, *data;
@@ -1096,6 +1108,14 @@ static void check_export_symbol(struct module *mod, struct elf_info *elf,
 		return;
 	}
 
+	name = label_name + strlen(prefix);
+	sym = find_tosym_with_name(elf, taddr, sym, name);
+	if (!sym) {
+		error("%s: could not find the the export symbol '%s'\n",
+		      mod->name, name);
+		return;
+	}
+
 	if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL &&
 	    ELF_ST_BIND(sym->st_info) != STB_WEAK) {
 		error("%s: local symbol '%s' was exported\n", mod->name,
@@ -1103,13 +1123,6 @@ static void check_export_symbol(struct module *mod, struct elf_info *elf,
 		return;
 	}
 
-	name = sym_name(elf, sym);
-	if (strcmp(label_name + strlen(prefix), name)) {
-		error("%s: .export_symbol section references '%s', but it does not seem to be an export symbol\n",
-		      mod->name, name);
-		return;
-	}
-
 	data = sym_get_data(elf, label);	/* license */
 	if (!strcmp(data, "GPL")) {
 		is_gpl = true;
@@ -1156,7 +1169,7 @@ static void check_section_mismatch(struct module *mod, struct elf_info *elf,
 	const struct sectioncheck *mismatch;
 
 	if (module_enabled && elf->export_symbol_secndx == fsecndx) {
-		check_export_symbol(mod, elf, faddr, tosec, sym);
+		check_export_symbol(mod, elf, faddr, tosec, sym, taddr);
 		return;
 	}
 
-- 
2.40.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ