[tip: objtool/urgent] klp-build: Fix wrong index in funcs cleanup error path
From: tip-bot2 for Yafang Shao
Date: Tue Sep 08 2026 - 03:51:32 EST
The following commit has been merged into the objtool/urgent branch of tip:
Commit-ID: 4825ef699cda4c6f2f0586b17a5e225560481da6
Gitweb: https://git.kernel.org/tip/4825ef699cda4c6f2f0586b17a5e225560481da6
Author: Yafang Shao <laoar.shao@xxxxxxxxx>
AuthorDate: Sun, 16 Aug 2026 17:04:41 +08:00
Committer: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
CommitterDate: Mon, 31 Aug 2026 17:50:06 -07:00
klp-build: Fix wrong index in funcs cleanup error path
In the object allocation loop, when kzalloc() for funcs fails, the
cleanup loop uses `objs[i].funcs` instead of `objs[j].funcs`. Since
`objs[i].funcs` is still NULL at that point, it repeatedly calls
kfree(NULL) and leaks all previously allocated funcs arrays.
Fixes: 59adee07b568 ("livepatch/klp-build: Add stub init code for livepatch modules")
Signed-off-by: Yafang Shao <laoar.shao@xxxxxxxxx>
Acked-by: Song Liu <song@xxxxxxxxxx>
Reviewed-by: Petr Mladek <pmladek@xxxxxxxx>
Acked-by: Miroslav Benes <mbenes@xxxxxxx>
Link: https://patch.msgid.link/20260816090442.18128-2-laoar.shao@xxxxxxxxx
Signed-off-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
---
scripts/livepatch/init.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/livepatch/init.c b/scripts/livepatch/init.c
index f14d8c8..16aff8f 100644
--- a/scripts/livepatch/init.c
+++ b/scripts/livepatch/init.c
@@ -51,7 +51,7 @@ static int __init livepatch_mod_init(void)
if (!funcs) {
ret = -ENOMEM;
for (int j = 0; j < i; j++)
- kfree(objs[i].funcs);
+ kfree(objs[j].funcs);
goto err_free_objs;
}