From db91da8f05185706f492841d96864ad78893dd62 Mon Sep 17 00:00:00 2001 From: Tiezhu Yang Date: Thu, 20 Aug 2026 20:50:05 +0800 Subject: module/kallsyms: Rename is_mapping_symbol() to is_ignored_kernel_symbol() The helper function is_mapping_symbol() historically checks for both local labels prefixed with ".L" or "L0" and mapping symbols prefixed with "$". Rename it to is_ignored_kernel_symbol() to better reflect this actual behavior and scope, preventing conceptual confusion. While at it, update the related non-module files, no functional changes. Suggested-by: Petr Pavlu Signed-off-by: Tiezhu Yang Reviewed-by: Huacai Chen Reviewed-by: Petr Pavlu Signed-off-by: Petr Pavlu --- kernel/module/kallsyms.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'kernel/module') diff --git a/kernel/module/kallsyms.c b/kernel/module/kallsyms.c index f23126d804b2..a52942fd0e07 100644 --- a/kernel/module/kallsyms.c +++ b/kernel/module/kallsyms.c @@ -294,7 +294,7 @@ static const char *find_kallsyms_symbol(struct module *mod, * and inserted at a whim. */ if (*kallsyms_symbol_name(kallsyms, i) == '\0' || - is_mapping_symbol(kallsyms_symbol_name(kallsyms, i))) + is_ignored_kernel_symbol(kallsyms_symbol_name(kallsyms, i))) continue; if (thisval <= addr && thisval > bestval) { -- cgit v1.2.3 From 67059a02f5e26e4c5c890792d720bbff235bb1d5 Mon Sep 17 00:00:00 2001 From: Tiezhu Yang Date: Thu, 20 Aug 2026 20:50:06 +0800 Subject: module/kallsyms: Refactor current symbol filtering into is_core_symbol() Currently, the loops in layout_symtab() and add_kallsyms() duplicate the exact same checks (i == 0 || is_livepatch_module() || is_core_symbol()) to determine whether a symbol should be preserved in the module's core symbol table. Move the entire checking logic inside is_core_symbol(), including the special handlers for the first symbol and livepatch modules. No functional changes. Suggested-by: Petr Pavlu Signed-off-by: Tiezhu Yang Reviewed-by: Huacai Chen Reviewed-by: Petr Pavlu Signed-off-by: Petr Pavlu --- kernel/module/kallsyms.c | 54 ++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'kernel/module') diff --git a/kernel/module/kallsyms.c b/kernel/module/kallsyms.c index a52942fd0e07..d75c9f60d360 100644 --- a/kernel/module/kallsyms.c +++ b/kernel/module/kallsyms.c @@ -75,23 +75,26 @@ static char elf_type(const Elf_Sym *sym, const struct load_info *info) return '?'; } -static bool is_core_symbol(const Elf_Sym *src, const Elf_Shdr *sechdrs, - unsigned int shnum, unsigned int pcpundx) +static bool is_core_symbol(struct module *mod, const struct load_info *info, + unsigned int symnum, const Elf_Sym *src) { const Elf_Shdr *sec; enum mod_mem_type type; + if (symnum == 0 || is_livepatch_module(mod)) + return true; + if (src->st_shndx == SHN_UNDEF || - src->st_shndx >= shnum || + src->st_shndx >= info->hdr->e_shnum || !src->st_name) return false; #ifdef CONFIG_KALLSYMS_ALL - if (src->st_shndx == pcpundx) + if (src->st_shndx == info->index.pcpu) return true; #endif - sec = sechdrs + src->st_shndx; + sec = info->sechdrs + src->st_shndx; type = sec->sh_entsize >> SH_ENTSIZE_TYPE_SHIFT; if (!(sec->sh_flags & SHF_ALLOC) #ifndef CONFIG_KALLSYMS_ALL @@ -130,12 +133,11 @@ void layout_symtab(struct module *mod, struct load_info *info) /* Compute total space required for the core symbols' strtab. */ for (ndst = i = 0; i < nsrc; i++) { - if (i == 0 || is_livepatch_module(mod) || - is_core_symbol(src + i, info->sechdrs, info->hdr->e_shnum, - info->index.pcpu)) { - strtab_size += strlen(&info->strtab[src[i].st_name]) + 1; - ndst++; - } + if (!is_core_symbol(mod, info, i, src + i)) + continue; + + strtab_size += strlen(&info->strtab[src[i].st_name]) + 1; + ndst++; } /* Append room for core symbols at end of core part. */ @@ -197,23 +199,21 @@ void add_kallsyms(struct module *mod, const struct load_info *info) strtab_size = info->core_typeoffs - info->stroffs; src = kallsyms->symtab; for (ndst = i = 0; i < kallsyms->num_symtab; i++) { + ssize_t ret; + kallsyms->typetab[i] = elf_type(src + i, info); - if (i == 0 || is_livepatch_module(mod) || - is_core_symbol(src + i, info->sechdrs, info->hdr->e_shnum, - info->index.pcpu)) { - ssize_t ret; - - mod->core_kallsyms.typetab[ndst] = - kallsyms->typetab[i]; - dst[ndst] = src[i]; - dst[ndst++].st_name = s - mod->core_kallsyms.strtab; - ret = strscpy(s, &kallsyms->strtab[src[i].st_name], - strtab_size); - if (ret < 0) - break; - s += ret + 1; - strtab_size -= ret + 1; - } + + if (!is_core_symbol(mod, info, i, src + i)) + continue; + + mod->core_kallsyms.typetab[ndst] = kallsyms->typetab[i]; + dst[ndst] = src[i]; + dst[ndst++].st_name = s - mod->core_kallsyms.strtab; + ret = strscpy(s, &kallsyms->strtab[src[i].st_name], strtab_size); + if (ret < 0) + break; + s += ret + 1; + strtab_size -= ret + 1; } /* Set up to point into init section. */ -- cgit v1.2.3 From a22f1497700e1b4b1d6285b7884cc1da3ffbba43 Mon Sep 17 00:00:00 2001 From: Tiezhu Yang Date: Thu, 20 Aug 2026 20:50:07 +0800 Subject: module/kallsyms: Ignore local labels and mapping symbols during module load The compiler toolchains may generate local labels and mapping symbols on certain architectures like LoongArch for optimizations and relocations. While these local labels and mapping symbols are already ignored during runtime lookups via find_kallsyms_symbol(), they still leak into kallsyms for loaded modules because layout_symtab() and add_kallsyms() don't ignore them during load time. Consequently, tracing tools like bpftrace (which do not perform internal filtering, unlike perf) resolve identical addresses into confusing local labels instead of actual clear C function names. Fix this by integrating the is_ignored_kernel_symbol() check directly into is_core_symbol(). This ensures these unneeded symbols are stripped during module load time, keeping /proc/kallsyms clean and resulting in accurate call stacks. Signed-off-by: Tiezhu Yang Reviewed-by: Huacai Chen Reviewed-by: Petr Pavlu Signed-off-by: Petr Pavlu --- kernel/module/kallsyms.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'kernel/module') diff --git a/kernel/module/kallsyms.c b/kernel/module/kallsyms.c index d75c9f60d360..1ff8ce857d92 100644 --- a/kernel/module/kallsyms.c +++ b/kernel/module/kallsyms.c @@ -89,6 +89,9 @@ static bool is_core_symbol(struct module *mod, const struct load_info *info, !src->st_name) return false; + if (is_ignored_kernel_symbol(&info->strtab[src->st_name])) + return false; + #ifdef CONFIG_KALLSYMS_ALL if (src->st_shndx == info->index.pcpu) return true; -- cgit v1.2.3 From 37002f9eb9bc4132022d6c0b3548f132299b87c0 Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Thu, 17 Sep 2026 14:12:30 -0700 Subject: modules/kmod: Allocate argv with kmalloc_array() In preparation for converting the kmalloc family of allocators to the type-aware kmalloc_obj family, we need to make sure that the returned type from the allocation matches the type of the variable being assigned. (The kmalloc family returns "void *", which can be implicitly cast to any pointer type.) argv holds 5 pointers, but the size was taken from the array type "char *[5]", which would make the allocation type a pointer to that array rather than the "char **" being assigned. Allocate 5 entries of the target's type instead. The resulting allocation size is the same. Build tested ARCH=x86_64 allmodconfig with GCC 16.2.0: kernel/module/kmod.o Assisted-by: LLM coccinelle Signed-off-by: Kees Cook Signed-off-by: Petr Pavlu --- kernel/module/kmod.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'kernel/module') diff --git a/kernel/module/kmod.c b/kernel/module/kmod.c index a25dccdf7aa7..c19b14c68de5 100644 --- a/kernel/module/kmod.c +++ b/kernel/module/kmod.c @@ -81,7 +81,7 @@ static int call_modprobe(char *orig_module_name, int wait) char *module_name; int ret; - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL); + char **argv = kmalloc_array(5, sizeof(*argv), GFP_KERNEL); if (!argv) goto out; -- cgit v1.2.3 From 1d7f1e329bac41d017aaf40037346bf89f5c245e Mon Sep 17 00:00:00 2001 From: Petr Pavlu Date: Fri, 11 Sep 2026 14:46:14 +0000 Subject: umh, treewide: Explicitly include linux/umh.h where needed The usermode helper declarations were previously provided by linux/kmod.h but commit c1f3fa2a4fde ("kmod: split off umh headers into its own file") moved them to linux/umh.h in 2017. Add explicit includes of linux/umh.h to files that use usermode helpers and remove linux/kmod.h where it is no longer needed. Acked-by: Alex Elder # for greybus Signed-off-by: Petr Pavlu --- arch/x86/kernel/cpu/mce/dev-mcelog.c | 2 +- drivers/block/drbd/drbd_nl.c | 1 + drivers/greybus/svc_watchdog.c | 1 + drivers/macintosh/windfarm_core.c | 1 + drivers/pnp/pnpbios/core.c | 2 +- drivers/video/fbdev/uvesafb.c | 1 + fs/coredump.c | 2 +- fs/nfs/cache_lib.c | 2 +- fs/nfsd/nfs4layouts.c | 2 +- fs/nfsd/nfs4recover.c | 1 + fs/ocfs2/stackglue.c | 1 + kernel/cgroup/cgroup-v1.c | 2 +- kernel/module/kmod.c | 1 + kernel/power/process.c | 2 +- kernel/reboot.c | 2 +- kernel/umh.c | 2 +- lib/kobject_uevent.c | 2 +- net/bridge/br_stp_if.c | 2 +- security/keys/request_key.c | 2 +- security/tomoyo/common.h | 2 +- 20 files changed, 20 insertions(+), 13 deletions(-) (limited to 'kernel/module') diff --git a/arch/x86/kernel/cpu/mce/dev-mcelog.c b/arch/x86/kernel/cpu/mce/dev-mcelog.c index 053555206d81..af4e76babe7a 100644 --- a/arch/x86/kernel/cpu/mce/dev-mcelog.c +++ b/arch/x86/kernel/cpu/mce/dev-mcelog.c @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include "internal.h" diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c index b77f901fc3ef..6f5d059394b3 100644 --- a/drivers/block/drbd/drbd_nl.c +++ b/drivers/block/drbd/drbd_nl.c @@ -14,6 +14,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include +#include #include #include #include diff --git a/drivers/greybus/svc_watchdog.c b/drivers/greybus/svc_watchdog.c index 16e6de5e9eff..b318eb34bcca 100644 --- a/drivers/greybus/svc_watchdog.c +++ b/drivers/greybus/svc_watchdog.c @@ -7,6 +7,7 @@ #include #include +#include #include #include diff --git a/drivers/macintosh/windfarm_core.c b/drivers/macintosh/windfarm_core.c index 5307b1e34261..e66de11c69a3 100644 --- a/drivers/macintosh/windfarm_core.c +++ b/drivers/macintosh/windfarm_core.c @@ -34,6 +34,7 @@ #include #include #include +#include #include "windfarm.h" diff --git a/drivers/pnp/pnpbios/core.c b/drivers/pnp/pnpbios/core.c index f7e86ae9f72f..46af1f549337 100644 --- a/drivers/pnp/pnpbios/core.c +++ b/drivers/pnp/pnpbios/core.c @@ -47,7 +47,7 @@ #include #include #include -#include +#include #include #include diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c index ccc9dbc25813..a13dff332aef 100644 --- a/drivers/video/fbdev/uvesafb.c +++ b/drivers/video/fbdev/uvesafb.c @@ -23,6 +23,7 @@ #include #include #include +#include #include