]> xenbits.xensource.com Git - xen.git/commitdiff
livepatch: Bubble up sanity checks on Elf relocs
authorKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Fri, 12 Aug 2016 20:03:18 +0000 (16:03 -0400)
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Fri, 9 Sep 2016 15:48:21 +0000 (11:48 -0400)
The checks for SHT_REL[,A] ELF sanity checks does not need to
be in the platform specific file and can be bubbled up
in the platform agnostic file.

This makes the ARM 32/64 implementation easier as the
duplicate checks don't have to be in the platform specific files.

Acked-by: Jan Beulich <jbeulich@suse.com> [x86 part]
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
xen/arch/x86/livepatch.c
xen/common/livepatch_elf.c

index 1023fab8c975031a8bf86a1cdf8215b427ff7abe..39620f99678feddb0361587e4f77846af855da35 100644 (file)
@@ -122,18 +122,6 @@ int arch_livepatch_perform_rela(struct livepatch_elf *elf,
     uint64_t val;
     uint8_t *dest;
 
-    /* Nothing to do. */
-    if ( !rela->sec->sh_size )
-        return 0;
-
-    if ( rela->sec->sh_entsize < sizeof(Elf_RelA) ||
-         rela->sec->sh_size % rela->sec->sh_entsize )
-    {
-        dprintk(XENLOG_ERR, LIVEPATCH "%s: Section relative header is corrupted!\n",
-                elf->name);
-        return -EINVAL;
-    }
-
     for ( i = 0; i < (rela->sec->sh_size / rela->sec->sh_entsize); i++ )
     {
         r = rela->data + i * rela->sec->sh_entsize;
index 789e8fc0af1c2e3f7df9155dec792669cbae83c7..cda9b2730eeb7289c4bb1d4a7e9fb4d229dfcb6d 100644 (file)
@@ -335,6 +335,7 @@ int livepatch_elf_perform_relocs(struct livepatch_elf *elf)
     struct livepatch_elf_sec *r, *base;
     unsigned int i;
     int rc = 0;
+    size_t sz;
 
     ASSERT(elf->sym);
 
@@ -364,6 +365,22 @@ int livepatch_elf_perform_relocs(struct livepatch_elf *elf)
             break;
         }
 
+        if ( r->sec->sh_type == SHT_RELA )
+            sz = sizeof(Elf_RelA);
+        else
+            sz = sizeof(Elf_Rel);
+
+        if ( !r->sec->sh_size )
+            continue;
+
+        if ( r->sec->sh_entsize < sz || r->sec->sh_size % r->sec->sh_entsize )
+        {
+            dprintk(XENLOG_ERR, LIVEPATCH "%s: Section relative header is corrupted!\n",
+                    elf->name);
+            rc = -EINVAL;
+            break;
+        }
+
         if ( r->sec->sh_type == SHT_RELA )
             rc = arch_livepatch_perform_rela(elf, base, r);
         else /* SHT_REL */