[PATCH v3 1/3] module/kallsyms: include empty names in is_ignored_kernel_symbol()

From: Stanislaw Gruszka

Date: Wed Nov 18 2026 - 09:51:44 EST


Both modpost and find_kallsyms_symbol() reject empty symbol names.
Handle them in the shared helper to avoid duplicating this check.

This also lets is_core_symbol() reject empty names referenced by a
nonzero st_name. The reserved ELF null symbol at index 0 is preserved
before calling the helper.

Signed-off-by: Stanislaw Gruszka <stf_xl@xxxxx>
---
include/linux/module_symbol.h | 6 ++++--
kernel/module/kallsyms.c | 7 +------
scripts/mod/modpost.h | 2 +-
3 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/include/linux/module_symbol.h b/include/linux/module_symbol.h
index 698d3db2b37e..b93ef616a3f1 100644
--- a/include/linux/module_symbol.h
+++ b/include/linux/module_symbol.h
@@ -8,11 +8,13 @@ enum ksym_flags {
};

/*
- * Ignore local labels (.L*, L0*) and mapping symbols ($*). These symbols are
- * not useful for the kernel, for example, they should not appear in kallsyms.
+ * Ignore empty names, local labels (.L*, L0*) and mapping symbols ($*).
+ * These symbols are not useful for the kernel and should not appear in kallsyms.
*/
static inline bool is_ignored_kernel_symbol(const char *str)
{
+ if (!str[0])
+ return true;
if (str[0] == '.' && str[1] == 'L')
return true;
if (str[0] == 'L' && str[1] == '0')
diff --git a/kernel/module/kallsyms.c b/kernel/module/kallsyms.c
index 1ff8ce857d92..5dae0832714a 100644
--- a/kernel/module/kallsyms.c
+++ b/kernel/module/kallsyms.c
@@ -292,12 +292,7 @@ static const char *find_kallsyms_symbol(struct module *mod,
if (sym->st_shndx == SHN_UNDEF)
continue;

- /*
- * We ignore unnamed symbols: they're uninformative
- * and inserted at a whim.
- */
- if (*kallsyms_symbol_name(kallsyms, i) == '\0' ||
- is_ignored_kernel_symbol(kallsyms_symbol_name(kallsyms, i)))
+ if (is_ignored_kernel_symbol(kallsyms_symbol_name(kallsyms, i)))
continue;

if (thisval <= addr && thisval > bestval) {
diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
index 666beca685e4..eb01108702be 100644
--- a/scripts/mod/modpost.h
+++ b/scripts/mod/modpost.h
@@ -196,7 +196,7 @@ static inline bool is_valid_name(struct elf_info *elf, Elf_Sym *sym)
{
const char *name = elf->strtab + sym->st_name;

- if (!name || !strlen(name))
+ if (!name)
return false;
return !is_ignored_kernel_symbol(name);
}
--
2.52.0