From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752161AbbKKR5h (ORCPT ); Wed, 11 Nov 2015 12:57:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58582 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751152AbbKKR5e (ORCPT ); Wed, 11 Nov 2015 12:57:34 -0500 Date: Wed, 11 Nov 2015 11:57:31 -0600 From: Josh Poimboeuf To: Chris J Arges Cc: live-patching@vger.kernel.org, jeyu@redhat.com, Seth Jennings , Jiri Kosina , Vojtech Pavlik , linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/3 v4] livepatch: add old_sympos as disambiguator field to klp_reloc Message-ID: <20151111175731.GF5331@treble.redhat.com> References: <20151103200608.GQ27488@treble.redhat.com> <1447259366-7055-1-git-send-email-chris.j.arges@canonical.com> <1447259366-7055-3-git-send-email-chris.j.arges@canonical.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1447259366-7055-3-git-send-email-chris.j.arges@canonical.com> User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 11, 2015 at 10:29:00AM -0600, Chris J Arges wrote: > 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; I think 'val' can be removed from this struct, since it's now basically just a private variable of klp_write_object_relocations(). > 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; > For "external" symbols, the object isn't specified by the user, and since sympos is per-object, the value of sympos is undefined. Instead I think it should always pass 0 to klp_find_object_symbol() below. In line with that, since reloc->external and reloc->sympos don't mix, maybe klp_write_object_relocations() should return -EINVAL if external is set and sympos is non-zero. > @@ -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 -- Josh