Commit 064c89df authored by Chris J Arges's avatar Chris J Arges Committed by Jiri Kosina

livepatch: add sympos as disambiguator field to klp_reloc

In cases of duplicate symbols, sympos will be used to disambiguate instead
of val. By default sympos will be 0, and patching will only succeed if
the symbol is unique. Specifying a positive value will ensure that
occurrence of the symbol in kallsyms for the patched object will be used
for patching if it is valid. For external relocations sympos is not
supported.

Remove klp_verify_callback, klp_verify_args and klp_verify_vmlinux_symbol
as they are no longer used.

From the klp_reloc structure remove val, as it can be refactored as a
local variable in klp_write_object_relocations.
Signed-off-by: default avatarChris J Arges <chris.j.arges@canonical.com>
Reviewed-by: default avatarPetr Mladek <pmladek@suse.com>
Acked-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent b2b018ef
...@@ -67,8 +67,7 @@ struct klp_func { ...@@ -67,8 +67,7 @@ struct klp_func {
/** /**
* struct klp_reloc - relocation structure for live patching * struct klp_reloc - relocation structure for live patching
* @loc: address where the relocation will be written * @loc: address where the relocation will be written
* @val: address of the referenced symbol (optional, * @sympos: position in kallsyms to disambiguate symbols (optional)
* vmlinux patches only)
* @type: ELF relocation type * @type: ELF relocation type
* @name: name of the referenced symbol (for lookup/verification) * @name: name of the referenced symbol (for lookup/verification)
* @addend: offset from the referenced symbol * @addend: offset from the referenced symbol
...@@ -76,7 +75,7 @@ struct klp_func { ...@@ -76,7 +75,7 @@ struct klp_func {
*/ */
struct klp_reloc { struct klp_reloc {
unsigned long loc; unsigned long loc;
unsigned long val; unsigned long sympos;
unsigned long type; unsigned long type;
const char *name; const char *name;
int addend; int addend;
......
...@@ -203,45 +203,6 @@ static int klp_find_object_symbol(const char *objname, const char *name, ...@@ -203,45 +203,6 @@ static int klp_find_object_symbol(const char *objname, const char *name,
return -EINVAL; return -EINVAL;
} }
struct klp_verify_args {
const char *name;
const unsigned long addr;
};
static int klp_verify_callback(void *data, const char *name,
struct module *mod, unsigned long addr)
{
struct klp_verify_args *args = data;
if (!mod &&
!strcmp(args->name, name) &&
args->addr == addr)
return 1;
return 0;
}
static int klp_verify_vmlinux_symbol(const char *name, unsigned long addr)
{
struct klp_verify_args args = {
.name = name,
.addr = addr,
};
int ret;
mutex_lock(&module_mutex);
ret = kallsyms_on_each_symbol(klp_verify_callback, &args);
mutex_unlock(&module_mutex);
if (!ret) {
pr_err("symbol '%s' not found at specified address 0x%016lx, kernel mismatch?\n",
name, addr);
return -EINVAL;
}
return 0;
}
/* /*
* external symbols are located outside the parent object (where the parent * external symbols are located outside the parent object (where the parent
* object is either vmlinux or the kmod being patched). * object is either vmlinux or the kmod being patched).
...@@ -272,6 +233,7 @@ static int klp_write_object_relocations(struct module *pmod, ...@@ -272,6 +233,7 @@ static int klp_write_object_relocations(struct module *pmod,
struct klp_object *obj) struct klp_object *obj)
{ {
int ret; int ret;
unsigned long val;
struct klp_reloc *reloc; struct klp_reloc *reloc;
if (WARN_ON(!klp_is_object_loaded(obj))) if (WARN_ON(!klp_is_object_loaded(obj)))
...@@ -281,35 +243,27 @@ static int klp_write_object_relocations(struct module *pmod, ...@@ -281,35 +243,27 @@ static int klp_write_object_relocations(struct module *pmod,
return -EINVAL; return -EINVAL;
for (reloc = obj->relocs; reloc->name; reloc++) { for (reloc = obj->relocs; reloc->name; reloc++) {
if (!klp_is_module(obj)) { /* discover the address of the referenced symbol */
if (reloc->external) {
#if defined(CONFIG_RANDOMIZE_BASE) if (reloc->sympos > 0) {
/* If KASLR has been enabled, adjust old value accordingly */ pr_err("non-zero sympos for external reloc symbol '%s' is not supported\n",
if (kaslr_enabled()) reloc->name);
reloc->val += kaslr_offset(); return -EINVAL;
#endif }
ret = klp_verify_vmlinux_symbol(reloc->name, ret = klp_find_external_symbol(pmod, reloc->name, &val);
reloc->val); } else
if (ret) ret = klp_find_object_symbol(obj->name,
return ret; reloc->name,
} else { reloc->sympos,
/* module, reloc->val needs to be discovered */ &val);
if (reloc->external) if (ret)
ret = klp_find_external_symbol(pmod, return ret;
reloc->name,
&reloc->val);
else
ret = klp_find_object_symbol(obj->mod->name,
reloc->name,
0, &reloc->val);
if (ret)
return ret;
}
ret = klp_write_module_reloc(pmod, reloc->type, reloc->loc, ret = klp_write_module_reloc(pmod, reloc->type, reloc->loc,
reloc->val + reloc->addend); val + reloc->addend);
if (ret) { if (ret) {
pr_err("relocation failed for symbol '%s' at 0x%016lx (%d)\n", pr_err("relocation failed for symbol '%s' at 0x%016lx (%d)\n",
reloc->name, reloc->val, ret); reloc->name, val, ret);
return ret; return ret;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment