Skip to content

Commit bcf5d54

Browse files
author
Jiri Kosina
committed
Merge branch 'for-4.1/core-noarch' into for-linus
2 parents 8cb2c2d + 2e3ac94 commit bcf5d54

File tree

3 files changed

+23
-58
lines changed

3 files changed

+23
-58
lines changed

arch/x86/include/asm/livepatch.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ static inline int klp_check_compiler_support(void)
3232
#endif
3333
return 0;
3434
}
35-
extern int klp_write_module_reloc(struct module *mod, unsigned long type,
36-
unsigned long loc, unsigned long value);
35+
int klp_write_module_reloc(struct module *mod, unsigned long type,
36+
unsigned long loc, unsigned long value);
3737

3838
static inline void klp_arch_set_pc(struct pt_regs *regs, unsigned long ip)
3939
{

include/linux/livepatch.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ struct klp_patch {
123123
enum klp_state state;
124124
};
125125

126-
extern int klp_register_patch(struct klp_patch *);
127-
extern int klp_unregister_patch(struct klp_patch *);
128-
extern int klp_enable_patch(struct klp_patch *);
129-
extern int klp_disable_patch(struct klp_patch *);
126+
int klp_register_patch(struct klp_patch *);
127+
int klp_unregister_patch(struct klp_patch *);
128+
int klp_enable_patch(struct klp_patch *);
129+
int klp_disable_patch(struct klp_patch *);
130130

131131
#endif /* CONFIG_LIVEPATCH */
132132

kernel/livepatch/core.c

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -335,32 +335,20 @@ static void notrace klp_ftrace_handler(unsigned long ip,
335335
rcu_read_unlock();
336336
}
337337

338-
static int klp_disable_func(struct klp_func *func)
338+
static void klp_disable_func(struct klp_func *func)
339339
{
340340
struct klp_ops *ops;
341-
int ret;
342-
343-
if (WARN_ON(func->state != KLP_ENABLED))
344-
return -EINVAL;
345341

346-
if (WARN_ON(!func->old_addr))
347-
return -EINVAL;
342+
WARN_ON(func->state != KLP_ENABLED);
343+
WARN_ON(!func->old_addr);
348344

349345
ops = klp_find_ops(func->old_addr);
350346
if (WARN_ON(!ops))
351-
return -EINVAL;
347+
return;
352348

353349
if (list_is_singular(&ops->func_stack)) {
354-
ret = unregister_ftrace_function(&ops->fops);
355-
if (ret) {
356-
pr_err("failed to unregister ftrace handler for function '%s' (%d)\n",
357-
func->old_name, ret);
358-
return ret;
359-
}
360-
361-
ret = ftrace_set_filter_ip(&ops->fops, func->old_addr, 1, 0);
362-
if (ret)
363-
pr_warn("function unregister succeeded but failed to clear the filter\n");
350+
WARN_ON(unregister_ftrace_function(&ops->fops));
351+
WARN_ON(ftrace_set_filter_ip(&ops->fops, func->old_addr, 1, 0));
364352

365353
list_del_rcu(&func->stack_node);
366354
list_del(&ops->node);
@@ -370,8 +358,6 @@ static int klp_disable_func(struct klp_func *func)
370358
}
371359

372360
func->state = KLP_DISABLED;
373-
374-
return 0;
375361
}
376362

377363
static int klp_enable_func(struct klp_func *func)
@@ -432,23 +418,15 @@ static int klp_enable_func(struct klp_func *func)
432418
return ret;
433419
}
434420

435-
static int klp_disable_object(struct klp_object *obj)
421+
static void klp_disable_object(struct klp_object *obj)
436422
{
437423
struct klp_func *func;
438-
int ret;
439424

440-
for (func = obj->funcs; func->old_name; func++) {
441-
if (func->state != KLP_ENABLED)
442-
continue;
443-
444-
ret = klp_disable_func(func);
445-
if (ret)
446-
return ret;
447-
}
425+
for (func = obj->funcs; func->old_name; func++)
426+
if (func->state == KLP_ENABLED)
427+
klp_disable_func(func);
448428

449429
obj->state = KLP_DISABLED;
450-
451-
return 0;
452430
}
453431

454432
static int klp_enable_object(struct klp_object *obj)
@@ -464,22 +442,19 @@ static int klp_enable_object(struct klp_object *obj)
464442

465443
for (func = obj->funcs; func->old_name; func++) {
466444
ret = klp_enable_func(func);
467-
if (ret)
468-
goto unregister;
445+
if (ret) {
446+
klp_disable_object(obj);
447+
return ret;
448+
}
469449
}
470450
obj->state = KLP_ENABLED;
471451

472452
return 0;
473-
474-
unregister:
475-
WARN_ON(klp_disable_object(obj));
476-
return ret;
477453
}
478454

479455
static int __klp_disable_patch(struct klp_patch *patch)
480456
{
481457
struct klp_object *obj;
482-
int ret;
483458

484459
/* enforce stacking: only the last enabled patch can be disabled */
485460
if (!list_is_last(&patch->list, &klp_patches) &&
@@ -489,12 +464,8 @@ static int __klp_disable_patch(struct klp_patch *patch)
489464
pr_notice("disabling patch '%s'\n", patch->mod->name);
490465

491466
for (obj = patch->objs; obj->funcs; obj++) {
492-
if (obj->state != KLP_ENABLED)
493-
continue;
494-
495-
ret = klp_disable_object(obj);
496-
if (ret)
497-
return ret;
467+
if (obj->state == KLP_ENABLED)
468+
klp_disable_object(obj);
498469
}
499470

500471
patch->state = KLP_DISABLED;
@@ -553,8 +524,6 @@ static int __klp_enable_patch(struct klp_patch *patch)
553524
pr_notice("enabling patch '%s'\n", patch->mod->name);
554525

555526
for (obj = patch->objs; obj->funcs; obj++) {
556-
klp_find_object_module(obj);
557-
558527
if (!klp_is_object_loaded(obj))
559528
continue;
560529

@@ -945,18 +914,14 @@ static void klp_module_notify_going(struct klp_patch *patch,
945914
{
946915
struct module *pmod = patch->mod;
947916
struct module *mod = obj->mod;
948-
int ret;
949917

950918
if (patch->state == KLP_DISABLED)
951919
goto disabled;
952920

953921
pr_notice("reverting patch '%s' on unloading module '%s'\n",
954922
pmod->name, mod->name);
955923

956-
ret = klp_disable_object(obj);
957-
if (ret)
958-
pr_warn("failed to revert patch '%s' on module '%s' (%d)\n",
959-
pmod->name, mod->name, ret);
924+
klp_disable_object(obj);
960925

961926
disabled:
962927
klp_free_object_loaded(obj);

0 commit comments

Comments
 (0)