Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure each symbol address doesn't start with a jump instruction #384

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions kmod/core/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,30 +706,41 @@ static int kpatch_link_object(struct kpatch_module *kpmod,
object->mod = mod;
}

ret = kpatch_write_relocations(kpmod, object);
if (ret)
goto err_unlink;

list_for_each_entry(func, &object->funcs, list) {

/* calculate actual old location */
if (vmlinux) {
ret = kpatch_verify_symbol_match(func->name,
func->old_addr);
if (ret)
goto err_unlink;
goto err_verify;
} else {
unsigned long old_addr;
old_addr = kpatch_find_module_symbol(mod, func->name);
if (!old_addr) {
pr_err("unable to find symbol '%s' in module '%s\n",
func->name, mod->name);
ret = -EINVAL;
goto err_unlink;
goto err_verify;
}
func->old_addr = old_addr;
}

/* does this function start with OP_JMP_REL32? */
if (*(u8 *)func->old_addr == 0xe9) {
pr_err("symbol '%s' at address 0x%lx starts with a OP_JMP_REL32\n", func->name, func->old_addr);
ret = -EINVAL;
goto err_verify;
}

}

ret = kpatch_write_relocations(kpmod, object);
if (ret)
goto err_unlink;

list_for_each_entry(func, &object->funcs, list) {

/* add to ftrace filter and register handler if needed */
ret = kpatch_ftrace_add_func(func->old_addr);
if (ret)
Expand All @@ -741,6 +752,7 @@ static int kpatch_link_object(struct kpatch_module *kpmod,

err_unlink:
kpatch_unlink_object(object);
err_verify:
return ret;
}

Expand Down