Skip to contentSkip to conversation

livepatch: clear internal flags at init

PATCH In review Yafang Shao 3 participants 4 messages Nov 23 – Dec 1 Live patching

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 livepatch: clear internal flags at init

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.

---
 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/[email protected]/

kernel/livepatch/core.c +2 -0
index 517fe427ff92..98a81ec203dc 100644
@@ -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)
Signature · 1 line
2.52.0
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines · 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.

Thank you
M

maintainer Reviewed-by on v2 1/1
#2 lore raw
In reply to Yafang Shao
Quoted 9 lines · 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.

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:

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

maintainer
#3 lore raw
In reply to Yafang Shao
Quoted 9 lines · 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.

JFYI, the patch has been committed into livepatching.git, branch for-7.5/trivial.

Best Regards,
Petr