From 1a38fd13c31ed8e7c7b598cc975ecc0f41fca468 Mon Sep 17 00:00:00 2001 From: Yafang Shao Date: Sun, 28 Jun 2026 19:46:35 +0800 Subject: livepatch: Fix NULL pointer dereference in klp_find_func() A NULL old_name in a newly loaded livepatch's function entry causes a NULL pointer dereference in strcmp(): klp_init_patch() klp_add_nops() klp_find_func() strcmp(old_func->old_name, func->old_name) Add klp_check_patch() at the beginning of klp_enable_patch() to reject patches with NULL old_name before they reach this code path. Reported-by: sashiko-bot Closes: https://lore.kernel.org/live-patching/20260529040130.95A9C1F00893@smtp.kernel.org/ Suggested-by: Petr Mladek Suggested-by: Miroslav Benes Signed-off-by: Yafang Shao Acked-by: Miroslav Benes Reviewed-by: Petr Mladek Tested-by: Petr Mladek Link: https://patch.msgid.link/20260628114635.33572-1-laoar.shao@gmail.com Signed-off-by: Petr Mladek --- kernel/livepatch/core.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c index 28d15ba58a26..a240d1144e89 100644 --- a/kernel/livepatch/core.c +++ b/kernel/livepatch/core.c @@ -799,9 +799,6 @@ void klp_free_replaced_patches_async(struct klp_patch *new_patch) static int klp_init_func(struct klp_object *obj, struct klp_func *func) { - if (!func->old_name) - return -EINVAL; - /* * NOPs get the address later. The patched module must be loaded, * see klp_init_object_loaded(). @@ -1092,6 +1089,25 @@ err: return ret; } +static int klp_check_patch(struct klp_patch *patch) +{ + struct klp_object *obj; + struct klp_func *func; + + if (!patch || !patch->mod || !patch->objs) + return -EINVAL; + + klp_for_each_object_static(patch, obj) { + if (!obj->funcs) + return -EINVAL; + klp_for_each_func_static(obj, func) { + if (!func->old_name) + return -EINVAL; + } + } + return 0; +} + /** * klp_enable_patch() - enable the livepatch * @patch: patch to be enabled @@ -1108,16 +1124,10 @@ err: int klp_enable_patch(struct klp_patch *patch) { int ret; - struct klp_object *obj; - - if (!patch || !patch->mod || !patch->objs) - return -EINVAL; - - klp_for_each_object_static(patch, obj) { - if (!obj->funcs) - return -EINVAL; - } + ret = klp_check_patch(patch); + if (ret) + return ret; if (!is_livepatch_module(patch->mod)) { pr_err("module %s is not marked as a livepatch module\n", -- cgit v1.2.3 From e77f165d26f72c280654cff248f5106cb9a53951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Fri, 3 Jul 2026 08:04:08 +0200 Subject: kbuild: unset sub_make_done before calling kselftest build system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The kselftest build system may recourse back into kbuild when building test modules. In that case kbuild needs to parse the new flags passed from the command line, instead of using the ones inherited from the kbuild invocation. Force that command line reevaluation. The same was done for scripts/install.sh in commit 14ccc638b02f9ec ("kbuild: cancel sub_make_done for the install target to fix DKMS") Reported-by: Zelin Deng Closes: https://lore.kernel.org/all/20260525083721.27857-1-zelin.deng@linux.alibaba.com/ Fixes: c9bb03ac2c66 ("kbuild: reduce output spam when building out of tree") Signed-off-by: Thomas Weißschuh Acked-by: Miroslav Benes Acked-by: Petr Mladek Tested-by: Zelin Deng Reviewed-by: Nicolas Schier Link: https://patch.msgid.link/20260703-makefile-unset-submake-done-v1-1-6899248f3d6a@linutronix.de Signed-off-by: Petr Mladek --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index d1c595db55c9..9dac90e563a2 100644 --- a/Makefile +++ b/Makefile @@ -1570,10 +1570,10 @@ tools/%: FORCE PHONY += kselftest kselftest: headers - $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests run_tests + $(Q)unset sub_make_done; $(MAKE) -C $(srctree)/tools/testing/selftests run_tests kselftest-%: headers FORCE - $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests $* + $(Q)unset sub_make_done; $(MAKE) -C $(srctree)/tools/testing/selftests $* PHONY += kselftest-merge kselftest-merge: -- cgit v1.2.3