Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752483AbbKKQ3x (ORCPT ); Wed, 11 Nov 2015 11:29:53 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:34854 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751253AbbKKQ3t (ORCPT ); Wed, 11 Nov 2015 11:29:49 -0500 From: Chris J Arges To: live-patching@vger.kernel.org Cc: jeyu@redhat.com, Chris J Arges , Josh Poimboeuf , Seth Jennings , Jiri Kosina , Vojtech Pavlik , linux-kernel@vger.kernel.org Subject: [PATCH 2/3 v4] livepatch: add old_sympos as disambiguator field to klp_reloc Date: Wed, 11 Nov 2015 10:29:00 -0600 Message-Id: <1447259366-7055-3-git-send-email-chris.j.arges@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1447259366-7055-1-git-send-email-chris.j.arges@canonical.com> References: <20151103200608.GQ27488@treble.redhat.com> <1447259366-7055-1-git-send-email-chris.j.arges@canonical.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4587 Lines: 148 In cases of duplicate symbols, sympos will be used to disambiguate instead of val. By default old_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 will be used for patching if it is valid. Signed-off-by: Chris J Arges --- include/linux/livepatch.h | 5 ++-- kernel/livepatch/core.c | 74 ++++++++++------------------------------------- 2 files changed, 18 insertions(+), 61 deletions(-) diff --git a/include/linux/livepatch.h b/include/linux/livepatch.h index df7b752..fb968a2 100644 --- a/include/linux/livepatch.h +++ b/include/linux/livepatch.h @@ -68,8 +68,8 @@ struct klp_func { /** * struct klp_reloc - relocation structure for live patching * @loc: address where the relocation will be written - * @val: address of the referenced symbol (optional, - * vmlinux patches only) + * @val: address of the referenced symbol + * @sympos: position in kallsyms to disambiguate symbols (optional) * @type: ELF relocation type * @name: name of the referenced symbol (for lookup/verification) * @addend: offset from the referenced symbol @@ -78,6 +78,7 @@ struct klp_func { struct klp_reloc { unsigned long loc; unsigned long val; + unsigned long sympos; unsigned long type; const char *name; int addend; diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c index 26f9778..4eb8691 100644 --- a/kernel/livepatch/core.c +++ b/kernel/livepatch/core.c @@ -207,45 +207,6 @@ static int klp_find_object_symbol(const char *objname, const char *name, 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; -} - static int klp_find_verify_func_addr(struct klp_object *obj, struct klp_func *func) { @@ -261,7 +222,7 @@ static int klp_find_verify_func_addr(struct klp_object *obj, * object is either vmlinux or the kmod being patched). */ static int klp_find_external_symbol(struct module *pmod, const char *name, - unsigned long *addr) + unsigned long *addr, unsigned long sympos) { const struct kernel_symbol *sym; @@ -276,7 +237,7 @@ static int klp_find_external_symbol(struct module *pmod, const char *name, preempt_enable(); /* otherwise check if it's in another .o within the patch module */ - return klp_find_object_symbol(pmod->name, name, addr, 0); + return klp_find_object_symbol(pmod->name, name, addr, sympos); } static int klp_write_object_relocations(struct module *pmod, @@ -292,24 +253,19 @@ static int klp_write_object_relocations(struct module *pmod, return -EINVAL; for (reloc = obj->relocs; reloc->name; reloc++) { - if (!klp_is_module(obj)) { - ret = klp_verify_vmlinux_symbol(reloc->name, - reloc->val); - if (ret) - return ret; - } else { - /* module, reloc->val needs to be discovered */ - if (reloc->external) - ret = klp_find_external_symbol(pmod, - reloc->name, - &reloc->val); - else - ret = klp_find_object_symbol(obj->mod->name, - reloc->name, - &reloc->val, 0); - if (ret) - return ret; - } + /* reloc->val needs to be discovered */ + if (reloc->external) + ret = klp_find_external_symbol(pmod, + reloc->name, + &reloc->val, + reloc->sympos); + else + ret = klp_find_object_symbol(obj->mod->name, + reloc->name, + &reloc->val, + reloc->sympos); + if (ret) + return ret; ret = klp_write_module_reloc(pmod, reloc->type, reloc->loc, reloc->val + reloc->addend); if (ret) { -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/