Skip to content

Commit f09d908

Browse files
mirabJiri Kosina
authored andcommitted
livepatch: make object/func-walking helpers more robust
Current object-walking helper checks the presence of obj->funcs to determine the end of objs array in klp_object structure. This is somewhat fragile because one can easily forget about funcs definition during livepatch creation. In such a case the livepatch module is successfully loaded and all objects after the incorrect one are omitted. This is very confusing. Let's make the helper more robust and check also for the other external member, name. Thus the helper correctly stops on an empty item of the array. We need to have a check for obj->funcs in klp_init_object() to make it work. The same applies to a func-walking helper. As a benefit we'll check for new_func member definition during the livepatch initialization. There is no such check anywhere in the code now. [[email protected]: fix shortlog] Signed-off-by: Miroslav Benes <[email protected]> Acked-by: Josh Poimboeuf <[email protected]> Acked-by: Jessica Yu <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 0f49fc9 commit f09d908

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

include/linux/livepatch.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,12 @@ struct klp_patch {
124124
};
125125

126126
#define klp_for_each_object(patch, obj) \
127-
for (obj = patch->objs; obj->funcs; obj++)
127+
for (obj = patch->objs; obj->funcs || obj->name; obj++)
128128

129129
#define klp_for_each_func(obj, func) \
130-
for (func = obj->funcs; func->old_name; func++)
130+
for (func = obj->funcs; \
131+
func->old_name || func->new_func || func->old_sympos; \
132+
func++)
131133

132134
int klp_register_patch(struct klp_patch *);
133135
int klp_unregister_patch(struct klp_patch *);

kernel/livepatch/core.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,9 @@ static void klp_free_patch(struct klp_patch *patch)
683683

684684
static int klp_init_func(struct klp_object *obj, struct klp_func *func)
685685
{
686+
if (!func->old_name || !func->new_func)
687+
return -EINVAL;
688+
686689
INIT_LIST_HEAD(&func->stack_node);
687690
func->state = KLP_DISABLED;
688691

0 commit comments

Comments
 (0)