* [PATCH v2] livepatch: clear internal flags at init
@ 2026-11-23 2:40 Yafang Shao
2026-11-23 12:53 ` Miroslav Benes
2026-11-24 13:35 ` Petr Mladek
0 siblings, 2 replies; 3+ messages in thread
From: Yafang Shao @ 2026-11-23 2:40 UTC (permalink / raw)
To: jpoimboe, mbenes, pmladek, joe.lawrence, song
Cc: live-patching, linux-kernel, Yafang Shao
func->nop and obj->dynamic are internal flags. However, a patch module can
set them in its static initializer and nothing validates that. The release
path uses them to decide whether kfree() has to be called, so with such a
patch the kernel ends up calling kfree() on memory it does not own.
Explicitly clear these flags during init to avoid that.
Suggested-by: Miroslav Benes <mbenes@suse.cz>
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
kernel/livepatch/core.c | 2 ++
1 file changed, 2 insertions(+)
---
v1->v2: clear these flag at init and simply the commit log (Miroslav)
v1: https://lore.kernel.org/live-patching/20261116130402.76743-1-laoar.shao@gmail.com/
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index 517fe427ff92..98a81ec203dc 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -952,6 +952,7 @@ static void klp_init_func_early(struct klp_object *obj,
kobject_get(&obj->kobj);
list_add_tail(&func->node, &obj->func_list);
func->obj = obj;
+ func->nop = false;
}
static void klp_init_object_early(struct klp_patch *patch,
@@ -962,6 +963,7 @@ static void klp_init_object_early(struct klp_patch *patch,
kobject_get(&patch->kobj);
list_add_tail(&obj->node, &patch->obj_list);
obj->patch = patch;
+ obj->dynamic = false;
}
static void klp_init_patch_early(struct klp_patch *patch)
--
2.52.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] livepatch: clear internal flags at init
2026-11-23 2:40 [PATCH v2] livepatch: clear internal flags at init Yafang Shao
@ 2026-11-23 12:53 ` Miroslav Benes
2026-11-24 13:35 ` Petr Mladek
1 sibling, 0 replies; 3+ messages in thread
From: Miroslav Benes @ 2026-11-23 12:53 UTC (permalink / raw)
To: Yafang Shao
Cc: jpoimboe, pmladek, joe.lawrence, song, live-patching, linux-kernel
On Mon, 23 Nov 2026, Yafang Shao wrote:
> func->nop and obj->dynamic are internal flags. However, a patch module can
> set them in its static initializer and nothing validates that. The release
> path uses them to decide whether kfree() has to be called, so with such a
> patch the kernel ends up calling kfree() on memory it does not own.
>
> Explicitly clear these flags during init to avoid that.
>
> Suggested-by: Miroslav Benes <mbenes@suse.cz>
> Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Reviewed-by: Miroslav Benes <mbenes@suse.cz>
Thank you
M
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] livepatch: clear internal flags at init
2026-11-23 2:40 [PATCH v2] livepatch: clear internal flags at init Yafang Shao
2026-11-23 12:53 ` Miroslav Benes
@ 2026-11-24 13:35 ` Petr Mladek
1 sibling, 0 replies; 3+ messages in thread
From: Petr Mladek @ 2026-11-24 13:35 UTC (permalink / raw)
To: Yafang Shao
Cc: jpoimboe, mbenes, joe.lawrence, song, live-patching, linux-kernel
On Mon 2026-11-23 10:40:00, Yafang Shao wrote:
> func->nop and obj->dynamic are internal flags. However, a patch module can
> set them in its static initializer and nothing validates that. The release
> path uses them to decide whether kfree() has to be called, so with such a
> patch the kernel ends up calling kfree() on memory it does not own.
>
> Explicitly clear these flags during init to avoid that.
>
> Suggested-by: Miroslav Benes <mbenes@suse.cz>
> Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
It looks a bit ad-hoc to initialize these two internal flags and
not the others, e.g. obj->patched. But maybe the other flags
just get assigned a value later.
I could live with this:
Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
I am going to wait few more days for a possible feedback.
I will commit this patch by the end of this week unless
anyone complains.
Best Regards,
Petr
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-24 13:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23 2:40 [PATCH v2] livepatch: clear internal flags at init Yafang Shao
2026-11-23 12:53 ` Miroslav Benes
2026-11-24 13:35 ` Petr Mladek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®