All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pawel Wieczorkiewicz <wipawel@amazon.de>
To: <xen-devel@lists.xenproject.org>
Cc: Pawel Wieczorkiewicz <wipawel@amazon.de>,
	Ross Lagerwall <ross.lagerwall@citrix.com>,
	mpohlack@amazon.com,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Subject: [Xen-devel] [PATCH v5 09/12] livepatch: Add support for modules .modinfo section metadata
Date: Thu, 14 Nov 2019 13:06:50 +0000	[thread overview]
Message-ID: <20191114130653.51185-10-wipawel@amazon.de> (raw)
In-Reply-To: <20191114130653.51185-1-wipawel@amazon.de>

Having detailed livepatch metadata helps to properly identify module's
origin and version. It also allows to keep track of the history of
livepatch loads in the system (at least within dmesg buffer size
limits).

The livepatch metadata are embedded in a form of .modinfo section.
Each such section contains data of the following format:
key=value\0key=value\0...key=value\0

The .modinfo section may be generated and appended to the resulting
livepatch ELF file optionally as an extra step of a higher level
livepatch build system.

The metadata section pointer and the section length is stored in the
livepatch payload structure and is used to display the content upon
livepatch apply operation.

Signed-off-by: Pawel Wieczorkiewicz <wipawel@amazon.de>
Reviewed-by: Andra-Irina Paraschiv <andraprs@amazon.com>
Reviewed-by: Bjoern Doebel <doebel@amazon.de>
Reviewed-by: Leonard Foerster <foersleo@amazon.de>
Reviewed-by: Martin Pohlack <mpohlack@amazon.de>
Reviewed-by: Norbert Manthey <nmanthey@amazon.de>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Ross Lagerwall <ross.lagerwall@citrix.com>
---
Changed since v2:
  * Added .modinfo tests (Konrad)
---
 xen/common/livepatch.c              | 34 ++++++++++++++++++++++++++++++++++
 xen/include/xen/livepatch_payload.h |  6 ++++++
 xen/test/livepatch/Makefile         | 10 +++++++++-
 3 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c
index 1c3c446220..48abf678c0 100644
--- a/xen/common/livepatch.c
+++ b/xen/common/livepatch.c
@@ -853,6 +853,23 @@ static int prepare_payload(struct payload *payload,
 #endif
     }
 
+    sec = livepatch_elf_sec_by_name(elf, ".modinfo");
+    if ( sec )
+    {
+        if ( !section_ok(elf, sec, sizeof(*payload->metadata.data)) )
+            return -EINVAL;
+
+        payload->metadata.data = sec->load_addr;
+        payload->metadata.len = sec->sec->sh_size;
+
+        /* The metadata is required to consists of null terminated strings. */
+        if ( payload->metadata.data[payload->metadata.len - 1] != '\0' )
+        {
+            printk(XENLOG_ERR LIVEPATCH "%s: Incorrect metadata format detected\n", payload->name);
+            return -EINVAL;
+        }
+    }
+
     return 0;
 }
 
@@ -1201,6 +1218,19 @@ static int livepatch_list(struct xen_sysctl_livepatch_list *list)
  * for XEN_SYSCTL_LIVEPATCH_ACTION operation (see livepatch_action).
  */
 
+static inline void livepatch_display_metadata(const struct livepatch_metadata *metadata)
+{
+    const char *str;
+
+    if ( metadata && metadata->data && metadata->len > 0 )
+    {
+        printk(XENLOG_INFO LIVEPATCH "module metadata:\n");
+        for ( str = metadata->data; str < (metadata->data + metadata->len); str += (strlen(str) + 1) )
+            printk(XENLOG_INFO LIVEPATCH "  %s\n", str);
+    }
+
+}
+
 static int apply_payload(struct payload *data)
 {
     unsigned int i;
@@ -1233,6 +1263,8 @@ static int apply_payload(struct payload *data)
 
     arch_livepatch_revive();
 
+    livepatch_display_metadata(&data->metadata);
+
     return 0;
 }
 
@@ -2011,6 +2043,8 @@ static void livepatch_printall(unsigned char key)
                data->name, state2str(data->state), data->state, data->text_addr,
                data->rw_addr, data->ro_addr, data->pages);
 
+        livepatch_display_metadata(&data->metadata);
+
         for ( i = 0; i < data->nfuncs; i++ )
         {
             struct livepatch_func *f = &(data->funcs[i]);
diff --git a/xen/include/xen/livepatch_payload.h b/xen/include/xen/livepatch_payload.h
index ff16af0dd6..9f5f064205 100644
--- a/xen/include/xen/livepatch_payload.h
+++ b/xen/include/xen/livepatch_payload.h
@@ -33,6 +33,11 @@ struct livepatch_hooks {
     } apply, revert;
 };
 
+struct livepatch_metadata {
+    const char *data; /* Ptr to .modinfo section with ASCII data. */
+    uint32_t len;     /* Length of the metadata section. */
+};
+
 struct payload {
     uint32_t state;                      /* One of the LIVEPATCH_STATE_*. */
     int32_t rc;                          /* 0 or -XEN_EXX. */
@@ -63,6 +68,7 @@ struct payload {
     unsigned int n_load_funcs;           /* Nr of the funcs to load and execute. */
     unsigned int n_unload_funcs;         /* Nr of funcs to call durung unload. */
     char name[XEN_LIVEPATCH_NAME_SIZE];  /* Name of it. */
+    struct livepatch_metadata metadata;  /* Module meta data record */
 };
 
 /*
diff --git a/xen/test/livepatch/Makefile b/xen/test/livepatch/Makefile
index cebd3eb49c..ebb343c314 100644
--- a/xen/test/livepatch/Makefile
+++ b/xen/test/livepatch/Makefile
@@ -79,9 +79,17 @@ config.h: xen_hello_world_func.o
 xen_hello_world.o: config.h
 
 .PHONY: $(LIVEPATCH)
-$(LIVEPATCH): xen_hello_world_func.o xen_hello_world.o note.o xen_note.o
+$(LIVEPATCH): xen_hello_world_func.o xen_hello_world.o note.o xen_note.o modinfo.o
 	$(LD) $(LDFLAGS) $(build_id_linker) -r -o $(LIVEPATCH) $^
 
+.PHONY: modinfo.o
+modinfo.o:
+	(set -e; \
+	 printf "LIVEPATCH_RULEZ\0") > $@.bin
+	$(OBJCOPY) $(OBJCOPY_MAGIC) \
+		   --rename-section=.data=.modinfo,alloc,load,readonly,data,contents -S $@.bin $@
+	#rm -f $@.bin
+
 #
 # This target is only accessible if CONFIG_LIVEPATCH is defined, which
 # depends on $(build_id_linker) being available. Hence we do not
-- 
2.16.5




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Ralf Herbrich
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2019-11-14 13:08 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-14 13:06 [Xen-devel] [PATCH v5 00/12] livepatch: new features and fixes Pawel Wieczorkiewicz
2019-11-14 13:06 ` [Xen-devel] [PATCH v5 01/12] livepatch: Always check hypervisor build ID upon livepatch upload Pawel Wieczorkiewicz
2019-11-14 13:06 ` [Xen-devel] [PATCH v5 02/12] livepatch: Allow to override inter-modules buildid dependency Pawel Wieczorkiewicz
2019-11-14 13:06 ` [Xen-devel] [PATCH v5 03/12] livepatch: Export payload structure via livepatch_payload.h Pawel Wieczorkiewicz
2019-11-14 13:06 ` [Xen-devel] [PATCH v5 04/12] livepatch: Implement pre-|post- apply|revert hooks Pawel Wieczorkiewicz
2019-11-14 13:06 ` [Xen-devel] [PATCH v5 05/12] livepatch: Add support for apply|revert action replacement hooks Pawel Wieczorkiewicz
2019-11-14 13:06 ` [Xen-devel] [PATCH v5 06/12] livepatch: Do not enforce ELF_LIVEPATCH_FUNC section presence Pawel Wieczorkiewicz
2019-11-14 13:06 ` [Xen-devel] [PATCH v5 07/12] livepatch: Add per-function applied/reverted state tracking marker Pawel Wieczorkiewicz
2019-11-14 13:06 ` [Xen-devel] [PATCH v5 08/12] livepatch: Add support for inline asm livepatching expectations Pawel Wieczorkiewicz
2019-11-14 13:06 ` Pawel Wieczorkiewicz [this message]
2019-11-14 13:06 ` [Xen-devel] [PATCH v5 10/12] livepatch: Handle arbitrary size names with the list operation Pawel Wieczorkiewicz
2019-11-19 16:45   ` Ross Lagerwall
2019-11-14 13:06 ` [Xen-devel] [PATCH v5 11/12] livepatch: Add metadata runtime retrieval mechanism Pawel Wieczorkiewicz
2019-11-19 17:11   ` Ross Lagerwall
2019-11-14 13:06 ` [Xen-devel] [PATCH v5 12/12] livepatch: Add python bindings for livepatch operations Pawel Wieczorkiewicz
2019-11-19 17:23   ` Ross Lagerwall
2019-11-20  2:25 ` [Xen-devel] [PATCH v5 00/12] livepatch: new features and fixes Konrad Rzeszutek Wilk
2019-11-20 10:05   ` Wieczorkiewicz, Pawel
2019-11-21  1:09     ` Konrad Rzeszutek Wilk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191114130653.51185-10-wipawel@amazon.de \
    --to=wipawel@amazon.de \
    --cc=konrad.wilk@oracle.com \
    --cc=mpohlack@amazon.com \
    --cc=ross.lagerwall@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.