Lines Matching full:patch

25 #include "patch.h"
70 * Note that the patch might still be needed before klp_module_going() in klp_find_object_module()
101 static struct klp_object *klp_find_object(struct klp_patch *patch, in klp_find_object() argument
106 klp_for_each_object(patch, obj) { in klp_find_object()
323 * /sys/kernel/livepatch/<patch>
324 * /sys/kernel/livepatch/<patch>/enabled
325 * /sys/kernel/livepatch/<patch>/transition
326 * /sys/kernel/livepatch/<patch>/force
327 * /sys/kernel/livepatch/<patch>/<object>
328 * /sys/kernel/livepatch/<patch>/<object>/patched
329 * /sys/kernel/livepatch/<patch>/<object>/<function,sympos>
331 static int __klp_disable_patch(struct klp_patch *patch);
336 struct klp_patch *patch; in enabled_store() local
344 patch = container_of(kobj, struct klp_patch, kobj); in enabled_store()
348 if (patch->enabled == enabled) { in enabled_store()
359 * Do not allow to re-enable a disabled patch. in enabled_store()
361 if (patch == klp_transition_patch) in enabled_store()
364 ret = __klp_disable_patch(patch); in enabled_store()
379 struct klp_patch *patch; in enabled_show() local
381 patch = container_of(kobj, struct klp_patch, kobj); in enabled_show()
382 return snprintf(buf, PAGE_SIZE-1, "%d\n", patch->enabled); in enabled_show()
388 struct klp_patch *patch; in transition_show() local
390 patch = container_of(kobj, struct klp_patch, kobj); in transition_show()
392 patch == klp_transition_patch); in transition_show()
398 struct klp_patch *patch; in force_store() local
411 patch = container_of(kobj, struct klp_patch, kobj); in force_store()
412 if (patch != klp_transition_patch) { in force_store()
459 static void klp_init_object_early(struct klp_patch *patch,
463 struct klp_patch *patch) in klp_alloc_object_dynamic() argument
479 klp_init_object_early(patch, obj); in klp_alloc_object_dynamic()
519 static int klp_add_object_nops(struct klp_patch *patch, in klp_add_object_nops() argument
525 obj = klp_find_object(patch, old_obj); in klp_add_object_nops()
528 obj = klp_alloc_object_dynamic(old_obj->name, patch); in klp_add_object_nops()
549 * patch to facilitate a 'replace' mode.
551 static int klp_add_nops(struct klp_patch *patch) in klp_add_nops() argument
560 err = klp_add_object_nops(patch, old_obj); in klp_add_nops()
571 struct klp_patch *patch; in klp_kobj_release_patch() local
573 patch = container_of(kobj, struct klp_patch, kobj); in klp_kobj_release_patch()
574 complete(&patch->finish); in klp_kobj_release_patch()
642 static void __klp_free_objects(struct klp_patch *patch, bool nops_only) in __klp_free_objects() argument
646 klp_for_each_object_safe(patch, obj, tmp_obj) { in __klp_free_objects()
657 static void klp_free_objects(struct klp_patch *patch) in klp_free_objects() argument
659 __klp_free_objects(patch, false); in klp_free_objects()
662 static void klp_free_objects_dynamic(struct klp_patch *patch) in klp_free_objects_dynamic() argument
664 __klp_free_objects(patch, true); in klp_free_objects_dynamic()
674 static void klp_free_patch_start(struct klp_patch *patch) in klp_free_patch_start() argument
676 if (!list_empty(&patch->list)) in klp_free_patch_start()
677 list_del(&patch->list); in klp_free_patch_start()
679 klp_free_objects(patch); in klp_free_patch_start()
687 * the last function accessing the livepatch structures when the patch
690 static void klp_free_patch_finish(struct klp_patch *patch) in klp_free_patch_finish() argument
695 * this is called when the patch gets disabled and it in klp_free_patch_finish()
698 kobject_put(&patch->kobj); in klp_free_patch_finish()
699 wait_for_completion(&patch->finish); in klp_free_patch_finish()
702 if (!patch->forced) in klp_free_patch_finish()
703 module_put(patch->mod); in klp_free_patch_finish()
707 * The livepatch might be freed from sysfs interface created by the patch.
713 struct klp_patch *patch = in klp_free_patch_work_fn() local
716 klp_free_patch_finish(patch); in klp_free_patch_work_fn()
719 void klp_free_patch_async(struct klp_patch *patch) in klp_free_patch_async() argument
721 klp_free_patch_start(patch); in klp_free_patch_async()
722 schedule_work(&patch->free_work); in klp_free_patch_async()
765 static int klp_apply_object_relocs(struct klp_patch *patch, in klp_apply_object_relocs() argument
769 struct klp_modinfo *info = patch->mod->klp_info; in klp_apply_object_relocs()
777 ret = klp_apply_section_relocs(patch->mod, info->sechdrs, in klp_apply_object_relocs()
779 patch->mod->core_kallsyms.strtab, in klp_apply_object_relocs()
789 static int klp_init_object_loaded(struct klp_patch *patch, in klp_init_object_loaded() argument
802 ret = klp_apply_object_relocs(patch, obj); in klp_init_object_loaded()
837 static int klp_init_object(struct klp_patch *patch, struct klp_object *obj) in klp_init_object() argument
852 ret = kobject_add(&obj->kobj, &patch->kobj, "%s", name); in klp_init_object()
863 ret = klp_init_object_loaded(patch, obj); in klp_init_object()
875 static void klp_init_object_early(struct klp_patch *patch, in klp_init_object_early() argument
880 list_add_tail(&obj->node, &patch->obj_list); in klp_init_object_early()
883 static void klp_init_patch_early(struct klp_patch *patch) in klp_init_patch_early() argument
888 INIT_LIST_HEAD(&patch->list); in klp_init_patch_early()
889 INIT_LIST_HEAD(&patch->obj_list); in klp_init_patch_early()
890 kobject_init(&patch->kobj, &klp_ktype_patch); in klp_init_patch_early()
891 patch->enabled = false; in klp_init_patch_early()
892 patch->forced = false; in klp_init_patch_early()
893 INIT_WORK(&patch->free_work, klp_free_patch_work_fn); in klp_init_patch_early()
894 init_completion(&patch->finish); in klp_init_patch_early()
896 klp_for_each_object_static(patch, obj) { in klp_init_patch_early()
897 klp_init_object_early(patch, obj); in klp_init_patch_early()
905 static int klp_init_patch(struct klp_patch *patch) in klp_init_patch() argument
910 ret = kobject_add(&patch->kobj, klp_root_kobj, "%s", patch->mod->name); in klp_init_patch()
914 if (patch->replace) { in klp_init_patch()
915 ret = klp_add_nops(patch); in klp_init_patch()
920 klp_for_each_object(patch, obj) { in klp_init_patch()
921 ret = klp_init_object(patch, obj); in klp_init_patch()
926 list_add_tail(&patch->list, &klp_patches); in klp_init_patch()
931 static int __klp_disable_patch(struct klp_patch *patch) in __klp_disable_patch() argument
935 if (WARN_ON(!patch->enabled)) in __klp_disable_patch()
941 klp_init_transition(patch, KLP_UNPATCHED); in __klp_disable_patch()
943 klp_for_each_object(patch, obj) in __klp_disable_patch()
957 patch->enabled = false; in __klp_disable_patch()
963 static int __klp_enable_patch(struct klp_patch *patch) in __klp_enable_patch() argument
971 if (WARN_ON(patch->enabled)) in __klp_enable_patch()
974 pr_notice("enabling patch '%s'\n", patch->mod->name); in __klp_enable_patch()
976 klp_init_transition(patch, KLP_PATCHED); in __klp_enable_patch()
987 klp_for_each_object(patch, obj) { in __klp_enable_patch()
993 pr_warn("pre-patch callback failed for object '%s'\n", in __klp_enable_patch()
1000 pr_warn("failed to patch object '%s'\n", in __klp_enable_patch()
1007 patch->enabled = true; in __klp_enable_patch()
1012 pr_warn("failed to enable patch '%s'\n", patch->mod->name); in __klp_enable_patch()
1020 * @patch: patch to be enabled
1022 * Initializes the data structure associated with the patch, creates the sysfs
1031 int klp_enable_patch(struct klp_patch *patch) in klp_enable_patch() argument
1036 if (!patch || !patch->mod || !patch->objs) in klp_enable_patch()
1039 klp_for_each_object_static(patch, obj) { in klp_enable_patch()
1045 if (!is_livepatch_module(patch->mod)) { in klp_enable_patch()
1047 patch->mod->name); in klp_enable_patch()
1061 if (!klp_is_patch_compatible(patch)) { in klp_enable_patch()
1062 pr_err("Livepatch patch (%s) is not compatible with the already installed livepatches.\n", in klp_enable_patch()
1063 patch->mod->name); in klp_enable_patch()
1068 if (!try_module_get(patch->mod)) { in klp_enable_patch()
1073 klp_init_patch_early(patch); in klp_enable_patch()
1075 ret = klp_init_patch(patch); in klp_enable_patch()
1079 ret = __klp_enable_patch(patch); in klp_enable_patch()
1088 klp_free_patch_start(patch); in klp_enable_patch()
1092 klp_free_patch_finish(patch); in klp_enable_patch()
1108 * klp_ftrace_handler() might still see the replaced patch on the stack.
1111 * this is handled transparently by patch->module_put.
1156 struct klp_patch *patch; in klp_cleanup_module_patches_limited() local
1159 klp_for_each_patch(patch) { in klp_cleanup_module_patches_limited()
1160 if (patch == limit) in klp_cleanup_module_patches_limited()
1163 klp_for_each_object(patch, obj) { in klp_cleanup_module_patches_limited()
1167 if (patch != klp_transition_patch) in klp_cleanup_module_patches_limited()
1170 pr_notice("reverting patch '%s' on unloading module '%s'\n", in klp_cleanup_module_patches_limited()
1171 patch->mod->name, obj->mod->name); in klp_cleanup_module_patches_limited()
1185 struct klp_patch *patch; in klp_module_coming() local
1200 * get patched by a new patch. in klp_module_coming()
1204 klp_for_each_patch(patch) { in klp_module_coming()
1205 klp_for_each_object(patch, obj) { in klp_module_coming()
1211 ret = klp_init_object_loaded(patch, obj); in klp_module_coming()
1213 pr_warn("failed to initialize patch '%s' for module '%s' (%d)\n", in klp_module_coming()
1214 patch->mod->name, obj->mod->name, ret); in klp_module_coming()
1218 pr_notice("applying patch '%s' to loading module '%s'\n", in klp_module_coming()
1219 patch->mod->name, obj->mod->name); in klp_module_coming()
1223 pr_warn("pre-patch callback failed for object '%s'\n", in klp_module_coming()
1230 pr_warn("failed to apply patch '%s' to module '%s' (%d)\n", in klp_module_coming()
1231 patch->mod->name, obj->mod->name, ret); in klp_module_coming()
1237 if (patch != klp_transition_patch) in klp_module_coming()
1250 * If a patch is unsuccessfully applied, return in klp_module_coming()
1253 pr_warn("patch '%s' failed for module '%s', refusing to load module '%s'\n", in klp_module_coming()
1254 patch->mod->name, obj->mod->name, obj->mod->name); in klp_module_coming()
1257 klp_cleanup_module_patches_limited(mod, patch); in klp_module_coming()
1273 * get patched by a new patch. in klp_module_going()