2015-11-12 17:00:17

by Chris J Arges

[permalink] [raw]
Subject: [PATCH 2/4 v5] livepatch: Simplify code for relocated external symbols

From: Petr Mladek <[email protected]>

The livepatch module might be linked from several .o files.
All symbols that need to be shared between these .o files
should be exported. This is a normal programming practice.
I do not see any reason to access static symbols between
these .o files.

This patch removes the search for the static symbols within
the livepatch module. It makes it easier to understand
the meaning of the external flag and klp_find_external_symbol()
function.

Signed-off-by: Petr Mladek <[email protected]>
Signed-off-by: Chris J Arges <[email protected]>
---
include/linux/livepatch.h | 3 ++-
kernel/livepatch/core.c | 12 +++++-------
2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/include/linux/livepatch.h b/include/linux/livepatch.h
index 3d18dff..9808dd4 100644
--- a/include/linux/livepatch.h
+++ b/include/linux/livepatch.h
@@ -73,7 +73,8 @@ struct klp_func {
* @type: ELF relocation type
* @name: name of the referenced symbol (for lookup/verification)
* @addend: offset from the referenced symbol
- * @external: symbol is either exported or within the live patch module itself
+ * @external: set for external symbols that are accessed from this object
+ * but defined outside; they must be exported
*/
struct klp_reloc {
unsigned long loc;
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index 479d75e..4cd079c 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -242,26 +242,24 @@ static int klp_verify_vmlinux_symbol(const char *name, unsigned long addr)
}

/*
- * external symbols are located outside the parent object (where the parent
- * object is either vmlinux or the kmod being patched).
+ * External symbols are exported symbols that are defined outside both
+ * the patched object and the patch.
*/
static int klp_find_external_symbol(struct module *pmod, const char *name,
unsigned long *addr)
{
const struct kernel_symbol *sym;
+ int ret = -EINVAL;

- /* first, check if it's an exported symbol */
preempt_disable();
sym = find_symbol(name, NULL, NULL, true, true);
if (sym) {
*addr = sym->value;
- preempt_enable();
- return 0;
+ ret = 0;
}
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 ret;
}

static int klp_write_object_relocations(struct module *pmod,
--
1.9.1


2015-11-13 10:24:52

by Miroslav Benes

[permalink] [raw]
Subject: Re: [PATCH 2/4 v5] livepatch: Simplify code for relocated external symbols

On Thu, 12 Nov 2015, Chris J Arges wrote:

> From: Petr Mladek <[email protected]>
>
> The livepatch module might be linked from several .o files.
> All symbols that need to be shared between these .o files
> should be exported. This is a normal programming practice.
> I do not see any reason to access static symbols between
> these .o files.
>
> This patch removes the search for the static symbols within
> the livepatch module. It makes it easier to understand
> the meaning of the external flag and klp_find_external_symbol()
> function.
>
> Signed-off-by: Petr Mladek <[email protected]>
> Signed-off-by: Chris J Arges <[email protected]>

I'd remove this patch from the patch set, because

1. Josh needs to confirm that it is possible for kpatch to live without
external or that we can modify it. This could postpone this patch set as a
whole.

2. I think the issue is quite independent of the problem this patch set
solves.

3. I can even imagine that we could get rid of 'external' in klp_func and
its special handling completely if kpatch allows.

So let's solve it separately. Does anyone have a different opinion?

Miroslav

2015-11-13 13:55:56

by Petr Mladek

[permalink] [raw]
Subject: Re: [PATCH 2/4 v5] livepatch: Simplify code for relocated external symbols

On Fri 2015-11-13 11:24:33, Miroslav Benes wrote:
> On Thu, 12 Nov 2015, Chris J Arges wrote:
>
> > From: Petr Mladek <[email protected]>
> >
> > The livepatch module might be linked from several .o files.
> > All symbols that need to be shared between these .o files
> > should be exported. This is a normal programming practice.
> > I do not see any reason to access static symbols between
> > these .o files.
> >
> > This patch removes the search for the static symbols within
> > the livepatch module. It makes it easier to understand
> > the meaning of the external flag and klp_find_external_symbol()
> > function.
> >
> > Signed-off-by: Petr Mladek <[email protected]>
> > Signed-off-by: Chris J Arges <[email protected]>
>
> I'd remove this patch from the patch set, because
>
> 1. Josh needs to confirm that it is possible for kpatch to live without
> external or that we can modify it. This could postpone this patch set as a
> whole.
>
> 2. I think the issue is quite independent of the problem this patch set
> solves.
>
> 3. I can even imagine that we could get rid of 'external' in klp_func and
> its special handling completely if kpatch allows.
>
> So let's solve it separately. Does anyone have a different opinion?

I agree. Let's solve this separately and leave it out for now.

Best Regards,
Petr