mirror of
https://github.com/dynup/kpatch
synced 2025-03-07 03:07:49 +00:00
If atomic replacement is used for the old-style patches (the patches that depend on kpatch.ko), the kernel might crash if the new patch changes a smaller set of functions than the patch being replaced. kpatch_apply_patch() does check if the functions from the patch to be replaced are currently running. However, the functions are removed from 'kpatch_func_hash' in kpatch_register() only after stop_machine() and kpatch_apply_patch() have finished: ret = stop_machine(kpatch_apply_patch, kpmod, NULL); /* * For the replace case, remove any obsolete funcs from the hash and * the ftrace filter, and disable the owning patch module so that it * can be removed. */ if (!ret && replace) { struct kpatch_module *kpmod2, *safe; hash_for_each_rcu(kpatch_func_hash, i, func, node) { if (func->op != KPATCH_OP_UNPATCH) continue; if (func->force) force = 1; hash_del_rcu(&func->node); WARN_ON(kpatch_ftrace_remove_func(func->old_addr)); } <...> As a result, the kernel may end up with an inconsistent set of patched functions. Some of the functions from the replaced patch could still be running, while some would be already reverted to the original ones. I observed kernel crashes in such situations when I was trying to replace a patch with a new one without a faulty fix. Let us remove the replaced patched functions from 'kpatch_func_hash' in kpatch_apply_patch() to avoid such issues. Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com> |
||
---|---|---|
.. | ||
core.c | ||
kpatch.h | ||
Makefile | ||
shadow.c |