[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH v2 14/20] livepatch: ARM 32|64: Ignore mapping symbols: $[d, a, x, t]



.snip..
> > diff --git a/xen/arch/arm/livepatch.c b/xen/arch/arm/livepatch.c
> > index f49e347..c290602 100644
> > --- a/xen/arch/arm/livepatch.c
> > +++ b/xen/arch/arm/livepatch.c
> > @@ -82,6 +82,38 @@ void arch_livepatch_unmask(void)
> >      local_abort_enable();
> >  }
> > 
> > +int arch_is_payload_symbol(const struct livepatch_elf *elf,
> > +                           const struct livepatch_elf_sym *sym)
> 
> I think this function should return bool (or bool_t) as the return will be
> used by is_payload_symbol as bool.

I also took the liberty of changing the name. It is now:

bool_t arch_livepatch_symbol_ok(const struct livepatch_elf *elf,
                                const struct livepatch_elf_sym *sym)

As that sounds much more understanding I think.

> > +#ifdef CONFIG_ARM_32
> > +                 p == 'a' || p == 't'
> 
> Note that Xen is not using Thumb instructions which have variable length, so
> we shouldn't expect to see $t. symbols.

/me nods.

Let me spin off a seperate patch that will check for arch specific symbols.
And if found within the payload will abort loading of it.

Something like this (compile tested on x86 for right now):

From e513d9d2e689870ab5b381a7a6d7d3ad24a517e5 Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
Date: Tue, 6 Sep 2016 14:52:21 -0400
Subject: [PATCH] livepatch/arm/x86: Check payload for for unwelcomed symbols.

Certain platforms, such as ARM [32|64] add extra mapping symbols
such as $x (for ARM64 instructions), or more interesting to
this patch: $t (for Thumb instructions). These symbols are suppose
to help the final linker to make any adjustments (such as
add an veneer). But more importantly - we do not compile Xen
with any Thumb instructions (which are variable length) - and
if we find these mapping symbols we should disallow such payload.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
---
Cc: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
Cc: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>
Cc: Julien Grall <julien.grall@xxxxxxx
Cc: Jan Beulich <jbeulich@xxxxxxxx>
Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>

v3: New submission.
---
 xen/arch/arm/livepatch.c    | 15 ++++++++++++++-
 xen/arch/x86/livepatch.c    |  7 +++++++
 xen/common/livepatch_elf.c  |  9 +++++++++
 xen/include/xen/livepatch.h |  2 ++
 4 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/xen/arch/arm/livepatch.c b/xen/arch/arm/livepatch.c
index 95a538b..6a9502b 100644
--- a/xen/arch/arm/livepatch.c
+++ b/xen/arch/arm/livepatch.c
@@ -114,7 +114,20 @@ bool_t arch_livepatch_symbol_ok(const struct livepatch_elf 
*elf,
     }
     return true;
 }
-
+int arch_livepatch_symbol_check(const struct livepatch_elf *elf,
+                                const struct livepatch_elf_sym *sym)
+{
+#ifdef CONFIG_ARM_32
+    /*
+     * Xen does not use Thumb instructions - and we should not see any of
+     * them. If we do, abort.
+     */
+    if ( *sym->name == '$' && sym->name[1] == 't' )
+        return -EINVAL;
+#else
+    return 0;
+#endif
+}
 int arch_livepatch_perform_rel(struct livepatch_elf *elf,
                                const struct livepatch_elf_sec *base,
                                const struct livepatch_elf_sec *rela)
diff --git a/xen/arch/x86/livepatch.c b/xen/arch/x86/livepatch.c
index b3581ff..781dab9 100644
--- a/xen/arch/x86/livepatch.c
+++ b/xen/arch/x86/livepatch.c
@@ -137,6 +137,13 @@ bool_t arch_livepatch_symbol_ok(const struct livepatch_elf 
*elf,
     return true;
 }
 
+int arch_livepatch_symbol_check(const struct livepatch_elf *elf,
+                                const struct livepatch_elf_sym *sym)
+{
+    /* No special checks on x86. */
+    return 0;
+}
+
 int arch_livepatch_perform_rel(struct livepatch_elf *elf,
                                const struct livepatch_elf_sec *base,
                                const struct livepatch_elf_sec *rela)
diff --git a/xen/common/livepatch_elf.c b/xen/common/livepatch_elf.c
index ee6fef4..26c8df7 100644
--- a/xen/common/livepatch_elf.c
+++ b/xen/common/livepatch_elf.c
@@ -244,6 +244,7 @@ static int elf_get_sym(struct livepatch_elf *elf, const 
void *data)
     for ( i = 1; i < nsym; i++ )
     {
         const Elf_Sym *s = symtab_sec->data + symtab_sec->sec->sh_entsize * i;
+        int rc;
 
         delta = s->st_name;
         /* Boundary check within the .strtab. */
@@ -256,6 +257,14 @@ static int elf_get_sym(struct livepatch_elf *elf, const 
void *data)
 
         sym[i].sym = s;
         sym[i].name = strtab_sec->data + delta;
+        /* On ARM we should NEVER see $t* symbols. */
+        rc = arch_livepatch_symbol_check(elf, sym);
+        if ( rc )
+        {
+            dprintk(XENLOG_ERR, LIVEPATCH "%s: Symbol '%s' should not be in 
payload!\n",
+                    elf->name, sym[i].name);
+            return rc;
+        }
     }
     elf->nsym = nsym;
 
diff --git a/xen/include/xen/livepatch.h b/xen/include/xen/livepatch.h
index c47f43d..6a0ad7f 100644
--- a/xen/include/xen/livepatch.h
+++ b/xen/include/xen/livepatch.h
@@ -48,6 +48,8 @@ int arch_verify_insn_length(unsigned long len);
 int arch_livepatch_verify_elf(const struct livepatch_elf *elf);
 bool_t arch_livepatch_symbol_ok(const struct livepatch_elf *elf,
                                 const struct livepatch_elf_sym *sym);
+int arch_livepatch_symbol_check(const struct livepatch_elf *elf,
+                                const struct livepatch_elf_sym *sym);
 int arch_livepatch_perform_rel(struct livepatch_elf *elf,
                                const struct livepatch_elf_sec *base,
                                const struct livepatch_elf_sec *rela);
-- 
2.4.11


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.