* [PATCH v2] modpost: prevent leak when early return no suffix .o in read_symbols()
@ 2026-06-24 4:47 Robertus Diawan Chris
0 siblings, 0 replies; only message in thread
From: Robertus Diawan Chris @ 2026-06-24 4:47 UTC (permalink / raw)
To: nathan, nsc; +Cc: linux-kbuild, linux-kernel, linux-kernel-mentees, skhan, me
The allocation for elf info symsearch and hdr from parse_elf() haven't
been released when return because of modname didn't have suffix ".o".
And it seems like the suffix ".o" check did not depends on parse_elf()
to succeed first. So, move the suffix ".o" check before checking
parse_elf() result to prevent resource leak when the modname didn't have
suffix ".o" and return early.
This is reported by Coverity Scan as "Resource leak".
Fixes: 8c9ce89c5b63 ("modpost: simplify mod->name allocation")
Signed-off-by: Robertus Diawan Chris <robertusdchris@gmail.com>
---
v1 -> v2:
- Move the suffix ".o" check before parse_elf() instead of adding
parse_elf_finish() in the suffix ".o" check because the suffix ".o"
check did not depends on parse_elf() and to minimize overhead handling
the check (suggested by Nathan Chancellor).
- To make the subject title represents the new change better, change the
subject title from "modpost: release allocation when early return no
suffix .o in read_symbols()" to "modpost: prevent leak when early
return no suffix .o in read_symbols()".
v1:
https://lore.kernel.org/all/20260610052550.187006-1-robertusdchris@gmail.com/
scripts/mod/modpost.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index abbcd3fc1394..6eb2714521a7 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -1580,14 +1580,14 @@ static void read_symbols(const char *modname)
struct elf_info info = { };
Elf_Sym *sym;
- if (!parse_elf(&info, modname))
- return;
-
if (!strends(modname, ".o")) {
error("%s: filename must be suffixed with .o\n", modname);
return;
}
+ if (!parse_elf(&info, modname))
+ return;
+
/* strip trailing .o */
mod = new_module(modname, strlen(modname) - strlen(".o"));
base-commit: 8cd9520d35a6c38db6567e97dd93b1f11f185dc6
--
2.54.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-06-24 4:47 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-24 4:47 [PATCH v2] modpost: prevent leak when early return no suffix .o in read_symbols() Robertus Diawan Chris
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox