diff mbox

[v3,09/18] livepatch/arm/x86: Check payload for for unwelcomed symbols.

Message ID 1473626125-13683-10-git-send-email-konrad.wilk@oracle.com (mailing list archive)
State New, archived
Headers show

Commit Message

Konrad Rzeszutek Wilk Sept. 11, 2016, 8:35 p.m. UTC
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@oracle.com>
---
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Ross Lagerwall <ross.lagerwall@citrix.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Julien Grall <julien.grall@arm.com
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>

v3: New submission.
    Use &sym[i] instead of sym (as that will always be NULL).
---
 xen/arch/arm/livepatch.c    | 14 ++++++++++++++
 xen/arch/x86/livepatch.c    |  7 +++++++
 xen/common/livepatch_elf.c  |  9 +++++++++
 xen/include/xen/livepatch.h |  2 ++
 4 files changed, 32 insertions(+)

Comments

Jan Beulich Sept. 12, 2016, 3:55 p.m. UTC | #1
>>> On 11.09.16 at 22:35, <konrad.wilk@oracle.com> wrote:
> --- a/xen/arch/arm/livepatch.c
> +++ b/xen/arch/arm/livepatch.c
> @@ -117,6 +117,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)

Perhaps also better to return bool here?

> @@ -255,6 +256,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. */

If you really mean to have such an arch-specific comment in common
code, may I recommend to use "e.g." or something similar?

Jan
diff mbox

Patch

diff --git a/xen/arch/arm/livepatch.c b/xen/arch/arm/livepatch.c
index d2ae128..dd94c94 100644
--- a/xen/arch/arm/livepatch.c
+++ b/xen/arch/arm/livepatch.c
@@ -117,6 +117,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 == '$' && sym->name[1] == 't' )
+        return -EINVAL;
+#endif
+    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/arch/x86/livepatch.c b/xen/arch/x86/livepatch.c
index bbcb5fe..27d4aac 100644
--- a/xen/arch/x86/livepatch.c
+++ b/xen/arch/x86/livepatch.c
@@ -125,6 +125,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 e2264ad..9e2aa31 100644
--- a/xen/common/livepatch_elf.c
+++ b/xen/common/livepatch_elf.c
@@ -243,6 +243,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. */
@@ -255,6 +256,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[i]);
+        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 c67b02c..edd905f 100644
--- a/xen/include/xen/livepatch.h
+++ b/xen/include/xen/livepatch.h
@@ -48,6 +48,8 @@  bool_t is_patch(const void *addr);
 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);