module_put() is currently never called in klp_complete_transition() when klp_force is set. As a result, we might keep the reference count even when klp_enable_patch() fails and klp_cancel_transition() is called. This might give the impression that a module might get blocked in some strange init state. Fortunately, it is not the case. The reference count is ignored when mod->init fails and erroneous modules are always removed. Anyway, this might be confusing. Instead, this patch moves the global klp_forced flag into struct klp_patch. As a result, we block only modules that might still be in use after a forced transition. Newly loaded livepatches might be eventually completely removed later. It is not a big deal. But the code is at least consistent with the reality. Signed-off-by: Petr Mladek <pmladek@suse.com> Acked-by: Joe Lawrence <joe.lawrence@redhat.com> Acked-by: Miroslav Benes <mbenes@suse.cz> Acked-by: Josh Poimboeuf <jpoimboe@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
49 lines
1.0 KiB
C
49 lines
1.0 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _LIVEPATCH_CORE_H
|
|
#define _LIVEPATCH_CORE_H
|
|
|
|
#include <linux/livepatch.h>
|
|
|
|
extern struct mutex klp_mutex;
|
|
extern struct list_head klp_patches;
|
|
|
|
static inline bool klp_is_object_loaded(struct klp_object *obj)
|
|
{
|
|
return !obj->name || obj->mod;
|
|
}
|
|
|
|
static inline int klp_pre_patch_callback(struct klp_object *obj)
|
|
{
|
|
int ret = 0;
|
|
|
|
if (obj->callbacks.pre_patch)
|
|
ret = (*obj->callbacks.pre_patch)(obj);
|
|
|
|
obj->callbacks.post_unpatch_enabled = !ret;
|
|
|
|
return ret;
|
|
}
|
|
|
|
static inline void klp_post_patch_callback(struct klp_object *obj)
|
|
{
|
|
if (obj->callbacks.post_patch)
|
|
(*obj->callbacks.post_patch)(obj);
|
|
}
|
|
|
|
static inline void klp_pre_unpatch_callback(struct klp_object *obj)
|
|
{
|
|
if (obj->callbacks.pre_unpatch)
|
|
(*obj->callbacks.pre_unpatch)(obj);
|
|
}
|
|
|
|
static inline void klp_post_unpatch_callback(struct klp_object *obj)
|
|
{
|
|
if (obj->callbacks.post_unpatch_enabled &&
|
|
obj->callbacks.post_unpatch)
|
|
(*obj->callbacks.post_unpatch)(obj);
|
|
|
|
obj->callbacks.post_unpatch_enabled = false;
|
|
}
|
|
|
|
#endif /* _LIVEPATCH_CORE_H */
|