diff mbox

[v10,23/24] xsplice: Prevent duplicate payloads from being loaded.

Message ID 1461785241-4481-24-git-send-email-konrad.wilk@oracle.com (mailing list archive)
State New, archived
Headers show

Commit Message

Konrad Rzeszutek Wilk April 27, 2016, 7:27 p.m. UTC
From: Ross Lagerwall <ross.lagerwall@citrix.com>

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>

---
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Keir Fraser <keir@xen.org>
Cc: Tim Deegan <tim@xen.org>

v6: Drop recursive lock - also now the caller is holding the lock
    Move the code up in the code above.
v7: Add Andrew's Reviewed-by
v9: Add const on struct payload.
    Check data->id.len != payload->id.len in the loop
v10:
    Check data->id.len == payload->id.len && in the loop
    Add Jan's Reviewed-by
---
---
 xen/common/xsplice.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
diff mbox

Patch

diff --git a/xen/common/xsplice.c b/xen/common/xsplice.c
index 581f48b..76ecfc3 100644
--- a/xen/common/xsplice.c
+++ b/xen/common/xsplice.c
@@ -521,6 +521,8 @@  static int prepare_payload(struct payload *payload,
     sec = xsplice_elf_sec_by_name(elf, ELF_BUILD_ID_NOTE);
     if ( sec )
     {
+        const struct payload *data;
+
         n = sec->load_addr;
 
         if ( sec->sec->sh_size <= sizeof(*n) )
@@ -532,6 +534,20 @@  static int prepare_payload(struct payload *payload,
 
         if ( !payload->id.len || !payload->id.p )
             return -EINVAL;
+
+        /* Make sure it is not a duplicate. */
+        list_for_each_entry ( data, &payload_list, list )
+        {
+            /* No way _this_ payload is on the list. */
+            ASSERT(data != payload);
+            if ( data->id.len == payload->id.len &&
+                 !memcmp(data->id.p, payload->id.p, data->id.len) )
+            {
+                dprintk(XENLOG_DEBUG, XSPLICE "%s: Already loaded as %s!\n",
+                        elf->name, data->name);
+                return -EEXIST;
+            }
+        }
     }
 
     sec = xsplice_elf_sec_by_name(elf, ELF_XSPLICE_DEPENDS);