xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/4] livepatch: minor bug fixes and improvements
@ 2024-04-24  8:19 Roger Pau Monne
  2024-04-24  8:19 ` [PATCH v4 1/4] xen-livepatch: fix parameter name parsing Roger Pau Monne
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Roger Pau Monne @ 2024-04-24  8:19 UTC (permalink / raw)
  To: xen-devel
  Cc: Roger Pau Monne, Ross Lagerwall, Anthony PERARD, Juergen Gross,
	Andrew Cooper, George Dunlap, Jan Beulich, Julien Grall,
	Stefano Stabellini

Hello,

Following series contain some minor bugfixes and improvements for
livepatch logic, both inside the hypervisor and on the command line
tool.

Thanks, Roger.

Roger Pau Monne (4):
  xen-livepatch: fix parameter name parsing
  livepatch: introduce --force option
  livepatch: refuse to resolve symbols that belong to init sections
  x86/livepatch: perform sanity checks on the payload exception table
    contents

 tools/include/xenctrl.h            |  3 ++-
 tools/libs/ctrl/xc_misc.c          |  7 +++----
 tools/misc/xen-livepatch.c         | 25 +++++++++++++++++++++----
 xen/arch/x86/extable.c             | 18 ++++++++++++++++++
 xen/arch/x86/include/asm/uaccess.h |  3 +++
 xen/common/livepatch.c             | 25 +++++++++++++++++++------
 xen/common/livepatch_elf.c         | 22 +++++++++++++++++++++-
 xen/include/public/sysctl.h        |  4 +++-
 xen/include/xen/livepatch_elf.h    |  2 +-
 9 files changed, 91 insertions(+), 18 deletions(-)

-- 
2.44.0



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v4 1/4] xen-livepatch: fix parameter name parsing
  2024-04-24  8:19 [PATCH v4 0/4] livepatch: minor bug fixes and improvements Roger Pau Monne
@ 2024-04-24  8:19 ` Roger Pau Monne
  2024-04-24 15:29   ` Anthony PERARD
  2024-04-25 14:33   ` Ross Lagerwall
  2024-04-24  8:19 ` [PATCH v4 2/4] livepatch: introduce --force option Roger Pau Monne
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 10+ messages in thread
From: Roger Pau Monne @ 2024-04-24  8:19 UTC (permalink / raw)
  To: xen-devel; +Cc: Roger Pau Monne, Ross Lagerwall, Anthony PERARD

It's incorrect to restrict strncmp to the length of the command line input
parameter, as then a user passing a rune like:

% xen-livepatch up foo.livepatch

Would match against the "upload" command, because the string comparison has
been truncated to the length of the input argument.  Use strcmp instead which
doesn't truncate.  Otherwise in order to keep using strncmp we would need to
also check strings are of the same length before doing the comparison.

Fixes: 05bb8afedede ('xen-xsplice: Tool to manipulate xsplice payloads')
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Changes since v3:
 - Use strcmp.

Changes since v2:
 - New in this version.
---
 tools/misc/xen-livepatch.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/misc/xen-livepatch.c b/tools/misc/xen-livepatch.c
index 5bf9d9a32b65..2c4f69e596fa 100644
--- a/tools/misc/xen-livepatch.c
+++ b/tools/misc/xen-livepatch.c
@@ -572,13 +572,13 @@ int main(int argc, char *argv[])
         return 0;
     }
     for ( i = 0; i < ARRAY_SIZE(main_options); i++ )
-        if (!strncmp(main_options[i].name, argv[1], strlen(argv[1])))
+        if (!strcmp(main_options[i].name, argv[1]))
             break;
 
     if ( i == ARRAY_SIZE(main_options) )
     {
         for ( j = 0; j < ARRAY_SIZE(action_options); j++ )
-            if (!strncmp(action_options[j].name, argv[1], strlen(argv[1])))
+            if (!strcmp(action_options[j].name, argv[1]))
                 break;
 
         if ( j == ARRAY_SIZE(action_options) )
-- 
2.44.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v4 2/4] livepatch: introduce --force option
  2024-04-24  8:19 [PATCH v4 0/4] livepatch: minor bug fixes and improvements Roger Pau Monne
  2024-04-24  8:19 ` [PATCH v4 1/4] xen-livepatch: fix parameter name parsing Roger Pau Monne
@ 2024-04-24  8:19 ` Roger Pau Monne
  2024-04-26  6:41   ` Jan Beulich
  2024-04-24  8:19 ` [PATCH v4 3/4] livepatch: refuse to resolve symbols that belong to init sections Roger Pau Monne
  2024-04-24  8:19 ` [PATCH v4 4/4] x86/livepatch: perform sanity checks on the payload exception table contents Roger Pau Monne
  3 siblings, 1 reply; 10+ messages in thread
From: Roger Pau Monne @ 2024-04-24  8:19 UTC (permalink / raw)
  To: xen-devel
  Cc: Roger Pau Monne, Anthony PERARD, Juergen Gross, Andrew Cooper,
	George Dunlap, Jan Beulich, Julien Grall, Stefano Stabellini,
	Ross Lagerwall

Introduce a xen-livepatch tool --force option, that's propagated into the
hyerpvisor for livepatch operations.  The intention is for the option to be
used to bypass some checks that would otherwise prevent the patch from being
loaded.

Re purpose the pad field in xen_sysctl_livepatch_op to be a flags field that
applies to all livepatch operations.  The flag is currently only set by the
hypercall wrappers for the XEN_SYSCTL_LIVEPATCH_UPLOAD operation, as that's so
far the only one where it will be used initially.  Other uses can be added as
required.

Note that helpers would set the .pad field to 0, that's been removed since the
structure is already zero initialized at definition.

No functional usages of the new flag introduced in this patch.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Anthony PERARD <anthony.perard@citrix.com>
---
Changes since v3:
 - Use strcmp instead of strncmp.

Changes since v2:
 - New in this version.
---
 tools/include/xenctrl.h     |  3 ++-
 tools/libs/ctrl/xc_misc.c   |  7 +++----
 tools/misc/xen-livepatch.c  | 21 +++++++++++++++++++--
 xen/common/livepatch.c      |  3 ++-
 xen/include/public/sysctl.h |  4 +++-
 5 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h
index 2ef8b4e05422..499685594427 100644
--- a/tools/include/xenctrl.h
+++ b/tools/include/xenctrl.h
@@ -2555,7 +2555,8 @@ int xc_psr_get_hw_info(xc_interface *xch, uint32_t socket,
 #endif
 
 int xc_livepatch_upload(xc_interface *xch,
-                        char *name, unsigned char *payload, uint32_t size);
+                        char *name, unsigned char *payload, uint32_t size,
+                        bool force);
 
 int xc_livepatch_get(xc_interface *xch,
                      char *name,
diff --git a/tools/libs/ctrl/xc_misc.c b/tools/libs/ctrl/xc_misc.c
index 5ecdfa2c7934..50282fd60dcc 100644
--- a/tools/libs/ctrl/xc_misc.c
+++ b/tools/libs/ctrl/xc_misc.c
@@ -576,7 +576,8 @@ int xc_getcpuinfo(xc_interface *xch, int max_cpus,
 int xc_livepatch_upload(xc_interface *xch,
                         char *name,
                         unsigned char *payload,
-                        uint32_t size)
+                        uint32_t size,
+                        bool force)
 {
     int rc;
     struct xen_sysctl sysctl = {};
@@ -612,7 +613,7 @@ int xc_livepatch_upload(xc_interface *xch,
 
     sysctl.cmd = XEN_SYSCTL_livepatch_op;
     sysctl.u.livepatch.cmd = XEN_SYSCTL_LIVEPATCH_UPLOAD;
-    sysctl.u.livepatch.pad = 0;
+    sysctl.u.livepatch.flags = force ? LIVEPATCH_FLAG_FORCE : 0;
     sysctl.u.livepatch.u.upload.size = size;
     set_xen_guest_handle(sysctl.u.livepatch.u.upload.payload, local);
 
@@ -656,7 +657,6 @@ int xc_livepatch_get(xc_interface *xch,
 
     sysctl.cmd = XEN_SYSCTL_livepatch_op;
     sysctl.u.livepatch.cmd = XEN_SYSCTL_LIVEPATCH_GET;
-    sysctl.u.livepatch.pad = 0;
 
     sysctl.u.livepatch.u.get.status.state = 0;
     sysctl.u.livepatch.u.get.status.rc = 0;
@@ -985,7 +985,6 @@ static int _xc_livepatch_action(xc_interface *xch,
 
     sysctl.cmd = XEN_SYSCTL_livepatch_op;
     sysctl.u.livepatch.cmd = XEN_SYSCTL_LIVEPATCH_ACTION;
-    sysctl.u.livepatch.pad = 0;
     sysctl.u.livepatch.u.action.cmd = action;
     sysctl.u.livepatch.u.action.timeout = timeout;
     sysctl.u.livepatch.u.action.flags = flags;
diff --git a/tools/misc/xen-livepatch.c b/tools/misc/xen-livepatch.c
index 2c4f69e596fa..c16fb6862d6c 100644
--- a/tools/misc/xen-livepatch.c
+++ b/tools/misc/xen-livepatch.c
@@ -19,11 +19,15 @@
 
 static xc_interface *xch;
 
+/* Global option to disable checks. */
+static bool force;
+
 void show_help(void)
 {
     fprintf(stderr,
             "xen-livepatch: live patching tool\n"
-            "Usage: xen-livepatch <command> [args] [command-flags]\n"
+            "Usage: xen-livepatch [--force] <command> [args] [command-flags]\n"
+            " Use --force option to bypass some checks.\n"
             " <name> An unique name of payload. Up to %d characters.\n"
             "Commands:\n"
             "  help                   display this help\n"
@@ -240,7 +244,7 @@ static int upload_func(int argc, char *argv[])
         return saved_errno;
     }
     printf("Uploading %s... ", filename);
-    rc = xc_livepatch_upload(xch, name, fbuf, len);
+    rc = xc_livepatch_upload(xch, name, fbuf, len, force);
     if ( rc )
     {
         rc = errno;
@@ -571,6 +575,19 @@ int main(int argc, char *argv[])
         show_help();
         return 0;
     }
+
+    if ( strcmp("--force", argv[1]) )
+    {
+        if ( argc <= 2 )
+        {
+            show_help();
+            return EXIT_FAILURE;
+        }
+        force = true;
+        argv++;
+        argc--;
+    }
+
     for ( i = 0; i < ARRAY_SIZE(main_options); i++ )
         if (!strcmp(main_options[i].name, argv[1]))
             break;
diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c
index 351a3e0b9a60..502e264bc6fe 100644
--- a/xen/common/livepatch.c
+++ b/xen/common/livepatch.c
@@ -2125,7 +2125,8 @@ int livepatch_op(struct xen_sysctl_livepatch_op *livepatch)
 {
     int rc;
 
-    if ( livepatch->pad )
+    if ( (livepatch->flags & ~LIVEPATCH_FLAGS_MASK) &&
+         !(livepatch->flags & LIVEPATCH_FLAG_FORCE) )
         return -EINVAL;
 
     switch ( livepatch->cmd )
diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h
index 9b19679caeb1..febaa4b16ab7 100644
--- a/xen/include/public/sysctl.h
+++ b/xen/include/public/sysctl.h
@@ -1139,7 +1139,9 @@ struct xen_sysctl_livepatch_action {
 
 struct xen_sysctl_livepatch_op {
     uint32_t cmd;                           /* IN: XEN_SYSCTL_LIVEPATCH_*. */
-    uint32_t pad;                           /* IN: Always zero. */
+    uint32_t flags;                         /* IN, flags. */
+#define LIVEPATCH_FLAG_FORCE      (1u << 0) /* Skip some checks. */
+#define LIVEPATCH_FLAGS_MASK      LIVEPATCH_FLAG_FORCE
     union {
         struct xen_sysctl_livepatch_upload upload;
         struct xen_sysctl_livepatch_list list;
-- 
2.44.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v4 3/4] livepatch: refuse to resolve symbols that belong to init sections
  2024-04-24  8:19 [PATCH v4 0/4] livepatch: minor bug fixes and improvements Roger Pau Monne
  2024-04-24  8:19 ` [PATCH v4 1/4] xen-livepatch: fix parameter name parsing Roger Pau Monne
  2024-04-24  8:19 ` [PATCH v4 2/4] livepatch: introduce --force option Roger Pau Monne
@ 2024-04-24  8:19 ` Roger Pau Monne
  2024-04-25 11:46   ` Roger Pau Monné
  2024-04-24  8:19 ` [PATCH v4 4/4] x86/livepatch: perform sanity checks on the payload exception table contents Roger Pau Monne
  3 siblings, 1 reply; 10+ messages in thread
From: Roger Pau Monne @ 2024-04-24  8:19 UTC (permalink / raw)
  To: xen-devel; +Cc: Roger Pau Monne, Ross Lagerwall

Livepatch payloads containing symbols that belong to init sections can only
lead to page faults later on, as by the time the livepatch is loaded init
sections have already been freed.

Refuse to resolve such symbols and return an error instead.

Note such resolutions are only relevant for symbols that point to undefined
sections (SHN_UNDEF), as that implies the symbol is not in the current payload
and hence must either be a Xen or a different livepatch payload symbol.

Do not allow to resolve symbols that point to __init_begin, as that address is
also unmapped.  On the other hand, __init_end is not unmapped, and hence allow
resolutions against it.

Since __init_begin can alias other symbols (like _erodata for example)
allow the force flag to override the check and resolve the symbol anyway.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Changes since v3:
 - Print warning message even when using the force option.

Changes since v2:
 - Allow bypassing added check with the force flag.

Changes since v1:
 - Fix off-by-one in range checking.
---
 xen/common/livepatch.c          | 13 ++++++++-----
 xen/common/livepatch_elf.c      | 22 +++++++++++++++++++++-
 xen/include/xen/livepatch_elf.h |  2 +-
 3 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c
index 502e264bc6fe..1afde0281402 100644
--- a/xen/common/livepatch.c
+++ b/xen/common/livepatch.c
@@ -1080,7 +1080,8 @@ static void free_payload(struct payload *data)
     xfree(data);
 }
 
-static int load_payload_data(struct payload *payload, void *raw, size_t len)
+static int load_payload_data(struct payload *payload, void *raw, size_t len,
+                             bool force)
 {
     struct livepatch_elf elf = { .name = payload->name, .len = len };
     int rc = 0;
@@ -1093,7 +1094,7 @@ static int load_payload_data(struct payload *payload, void *raw, size_t len)
     if ( rc )
         goto out;
 
-    rc = livepatch_elf_resolve_symbols(&elf);
+    rc = livepatch_elf_resolve_symbols(&elf, force);
     if ( rc )
         goto out;
 
@@ -1133,7 +1134,8 @@ static int load_payload_data(struct payload *payload, void *raw, size_t len)
     return rc;
 }
 
-static int livepatch_upload(struct xen_sysctl_livepatch_upload *upload)
+static int livepatch_upload(struct xen_sysctl_livepatch_upload *upload,
+                            bool force)
 {
     struct payload *data, *found;
     char n[XEN_LIVEPATCH_NAME_SIZE];
@@ -1162,7 +1164,7 @@ static int livepatch_upload(struct xen_sysctl_livepatch_upload *upload)
     {
         memcpy(data->name, n, strlen(n));
 
-        rc = load_payload_data(data, raw_data, upload->size);
+        rc = load_payload_data(data, raw_data, upload->size, force);
         if ( rc )
             goto out;
 
@@ -2132,7 +2134,8 @@ int livepatch_op(struct xen_sysctl_livepatch_op *livepatch)
     switch ( livepatch->cmd )
     {
     case XEN_SYSCTL_LIVEPATCH_UPLOAD:
-        rc = livepatch_upload(&livepatch->u.upload);
+        rc = livepatch_upload(&livepatch->u.upload,
+                              livepatch->flags & LIVEPATCH_FLAG_FORCE);
         break;
 
     case XEN_SYSCTL_LIVEPATCH_GET:
diff --git a/xen/common/livepatch_elf.c b/xen/common/livepatch_elf.c
index 45d73912a3cd..1d0ed8f99bcc 100644
--- a/xen/common/livepatch_elf.c
+++ b/xen/common/livepatch_elf.c
@@ -4,6 +4,7 @@
 
 #include <xen/errno.h>
 #include <xen/lib.h>
+#include <xen/sections.h>
 #include <xen/symbols.h>
 #include <xen/livepatch_elf.h>
 #include <xen/livepatch.h>
@@ -276,7 +277,7 @@ static int elf_get_sym(struct livepatch_elf *elf, const void *data)
     return 0;
 }
 
-int livepatch_elf_resolve_symbols(struct livepatch_elf *elf)
+int livepatch_elf_resolve_symbols(struct livepatch_elf *elf, bool force)
 {
     unsigned int i;
     int rc = 0;
@@ -310,6 +311,25 @@ int livepatch_elf_resolve_symbols(struct livepatch_elf *elf)
                     break;
                 }
             }
+
+            /*
+             * Ensure not an init symbol.  Only applicable to Xen symbols, as
+             * livepatch payloads don't have init sections or equivalent.
+             */
+            else if ( st_value >= (uintptr_t)&__init_begin &&
+                      st_value <  (uintptr_t)&__init_end )
+            {
+                printk("%s" LIVEPATCH "%s: symbol %s is in init section%s\n",
+                       force ? XENLOG_WARNING : XENLOG_ERR,
+                       elf->name, elf->sym[i].name,
+                       force ? "" : ", not resolving");
+                if ( !force )
+                {
+                    rc = -ENXIO;
+                    break;
+                }
+            }
+
             dprintk(XENLOG_DEBUG, LIVEPATCH "%s: Undefined symbol resolved: %s => %#"PRIxElfAddr"\n",
                     elf->name, elf->sym[i].name, st_value);
             break;
diff --git a/xen/include/xen/livepatch_elf.h b/xen/include/xen/livepatch_elf.h
index 7116deaddc28..84e9c5eb7be5 100644
--- a/xen/include/xen/livepatch_elf.h
+++ b/xen/include/xen/livepatch_elf.h
@@ -44,7 +44,7 @@ livepatch_elf_sec_by_name(const struct livepatch_elf *elf,
 int livepatch_elf_load(struct livepatch_elf *elf, const void *data);
 void livepatch_elf_free(struct livepatch_elf *elf);
 
-int livepatch_elf_resolve_symbols(struct livepatch_elf *elf);
+int livepatch_elf_resolve_symbols(struct livepatch_elf *elf, bool force);
 int livepatch_elf_perform_relocs(struct livepatch_elf *elf);
 
 static inline bool livepatch_elf_ignore_section(const Elf_Shdr *sec)
-- 
2.44.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v4 4/4] x86/livepatch: perform sanity checks on the payload exception table contents
  2024-04-24  8:19 [PATCH v4 0/4] livepatch: minor bug fixes and improvements Roger Pau Monne
                   ` (2 preceding siblings ...)
  2024-04-24  8:19 ` [PATCH v4 3/4] livepatch: refuse to resolve symbols that belong to init sections Roger Pau Monne
@ 2024-04-24  8:19 ` Roger Pau Monne
  3 siblings, 0 replies; 10+ messages in thread
From: Roger Pau Monne @ 2024-04-24  8:19 UTC (permalink / raw)
  To: xen-devel; +Cc: Roger Pau Monne, Jan Beulich, Andrew Cooper, Ross Lagerwall

Ensure the entries of a payload exception table only apply to text regions in
the payload itself.  Since the payload exception table needs to be loaded and
active even before a patch is applied (because hooks might already rely on it),
make sure the exception table (if any) only contains fixups for the payload
text section.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
Changes since v3:
 - Rename to extable_in_bounds().
 - Use _p() instead of casting to void *.

Changes since v2:
 - New in this version.
---
 xen/arch/x86/extable.c             | 18 ++++++++++++++++++
 xen/arch/x86/include/asm/uaccess.h |  3 +++
 xen/common/livepatch.c             |  9 +++++++++
 3 files changed, 30 insertions(+)

diff --git a/xen/arch/x86/extable.c b/xen/arch/x86/extable.c
index 8415cd1fa249..2be090b92df8 100644
--- a/xen/arch/x86/extable.c
+++ b/xen/arch/x86/extable.c
@@ -228,3 +228,21 @@ unsigned long asmlinkage search_pre_exception_table(struct cpu_user_regs *regs)
     }
     return fixup;
 }
+
+#ifdef CONFIG_LIVEPATCH
+bool extable_in_bounds(const struct exception_table_entry *ex_start,
+                       const struct exception_table_entry *ex_end,
+                       const void *start, const void *end)
+{
+    for ( ; ex_start < ex_end; ex_start++ )
+    {
+        const void *addr = _p(ex_addr(ex_start));
+        const void *cont = _p(ex_cont(ex_start));
+
+        if ( addr < start || addr >= end || cont < start || cont >= end )
+            return false;
+    }
+
+    return true;
+}
+#endif
diff --git a/xen/arch/x86/include/asm/uaccess.h b/xen/arch/x86/include/asm/uaccess.h
index 48b684c19d44..4995edfdd8db 100644
--- a/xen/arch/x86/include/asm/uaccess.h
+++ b/xen/arch/x86/include/asm/uaccess.h
@@ -426,5 +426,8 @@ extern unsigned long search_exception_table(const struct cpu_user_regs *regs,
 extern void sort_exception_tables(void);
 extern void sort_exception_table(struct exception_table_entry *start,
                                  const struct exception_table_entry *stop);
+extern bool extable_in_bounds(const struct exception_table_entry *ex_start,
+                              const struct exception_table_entry *ex_end,
+                              const void *start, const void *end);
 
 #endif /* __X86_UACCESS_H__ */
diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c
index 1afde0281402..4702c06902a9 100644
--- a/xen/common/livepatch.c
+++ b/xen/common/livepatch.c
@@ -912,6 +912,15 @@ static int prepare_payload(struct payload *payload,
         s = sec->load_addr;
         e = sec->load_addr + sec->sec->sh_size;
 
+        if ( !extable_in_bounds(s, e, payload->text_addr,
+                                payload->text_addr + payload->text_size) )
+        {
+            printk(XENLOG_ERR LIVEPATCH
+                   "%s: Invalid exception table with out of bounds entries\n",
+                   elf->name);
+            return -EINVAL;
+        }
+
         sort_exception_table(s ,e);
 
         region->ex = s;
-- 
2.44.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 1/4] xen-livepatch: fix parameter name parsing
  2024-04-24  8:19 ` [PATCH v4 1/4] xen-livepatch: fix parameter name parsing Roger Pau Monne
@ 2024-04-24 15:29   ` Anthony PERARD
  2024-04-25 14:33   ` Ross Lagerwall
  1 sibling, 0 replies; 10+ messages in thread
From: Anthony PERARD @ 2024-04-24 15:29 UTC (permalink / raw)
  To: Roger Pau Monne; +Cc: xen-devel, Ross Lagerwall

On Wed, Apr 24, 2024 at 10:19:54AM +0200, Roger Pau Monne wrote:
> It's incorrect to restrict strncmp to the length of the command line input
> parameter, as then a user passing a rune like:
> 
> % xen-livepatch up foo.livepatch
> 
> Would match against the "upload" command, because the string comparison has
> been truncated to the length of the input argument.  Use strcmp instead which
> doesn't truncate.  Otherwise in order to keep using strncmp we would need to
> also check strings are of the same length before doing the comparison.
> 
> Fixes: 05bb8afedede ('xen-xsplice: Tool to manipulate xsplice payloads')
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>

Acked-by: Anthony PERARD <anthony.perard@citrix.com>

Thanks,

-- 
Anthony PERARD


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 3/4] livepatch: refuse to resolve symbols that belong to init sections
  2024-04-24  8:19 ` [PATCH v4 3/4] livepatch: refuse to resolve symbols that belong to init sections Roger Pau Monne
@ 2024-04-25 11:46   ` Roger Pau Monné
  0 siblings, 0 replies; 10+ messages in thread
From: Roger Pau Monné @ 2024-04-25 11:46 UTC (permalink / raw)
  To: xen-devel; +Cc: Ross Lagerwall

On Wed, Apr 24, 2024 at 10:19:56AM +0200, Roger Pau Monne wrote:
> Livepatch payloads containing symbols that belong to init sections can only
> lead to page faults later on, as by the time the livepatch is loaded init
> sections have already been freed.
> 
> Refuse to resolve such symbols and return an error instead.
> 
> Note such resolutions are only relevant for symbols that point to undefined
> sections (SHN_UNDEF), as that implies the symbol is not in the current payload
> and hence must either be a Xen or a different livepatch payload symbol.
> 
> Do not allow to resolve symbols that point to __init_begin, as that address is
> also unmapped.  On the other hand, __init_end is not unmapped, and hence allow
> resolutions against it.
> 
> Since __init_begin can alias other symbols (like _erodata for example)
> allow the force flag to override the check and resolve the symbol anyway.

I've been thinking more about this, and it has further corner cases,
for example with this patch applied attempting to livepatch a function
that contains a rune like:

if ( system_state < SYS_STATE_active )
    call_init_function();

Will now fail as Xen will refuse to resolve the call_init_function
symbol.

I however don't have any better ideas about how to solve this.  Maybe
it's fine to require such patches to use the --force option, as
refusing to resolve init symbols adds a bit more safety to
livepatches.

Thanks, Roger.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 1/4] xen-livepatch: fix parameter name parsing
  2024-04-24  8:19 ` [PATCH v4 1/4] xen-livepatch: fix parameter name parsing Roger Pau Monne
  2024-04-24 15:29   ` Anthony PERARD
@ 2024-04-25 14:33   ` Ross Lagerwall
  1 sibling, 0 replies; 10+ messages in thread
From: Ross Lagerwall @ 2024-04-25 14:33 UTC (permalink / raw)
  To: Roger Pau Monne; +Cc: xen-devel, Anthony PERARD

On Wed, Apr 24, 2024 at 9:20 AM Roger Pau Monne <roger.pau@citrix.com> wrote:
>
> It's incorrect to restrict strncmp to the length of the command line input
> parameter, as then a user passing a rune like:
>
> % xen-livepatch up foo.livepatch
>
> Would match against the "upload" command, because the string comparison has
> been truncated to the length of the input argument.  Use strcmp instead which
> doesn't truncate.  Otherwise in order to keep using strncmp we would need to
> also check strings are of the same length before doing the comparison.
>

I had previously assumed that this was intentional as a way of allowing
abbreviated syntax. Regardless of the original intent, I'm OK with this
change.

Reviewed-by: Ross Lagerwall <ross.lagerwall@citrix.com>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 2/4] livepatch: introduce --force option
  2024-04-24  8:19 ` [PATCH v4 2/4] livepatch: introduce --force option Roger Pau Monne
@ 2024-04-26  6:41   ` Jan Beulich
  2024-04-26  7:15     ` Roger Pau Monné
  0 siblings, 1 reply; 10+ messages in thread
From: Jan Beulich @ 2024-04-26  6:41 UTC (permalink / raw)
  To: Roger Pau Monne
  Cc: Anthony PERARD, Juergen Gross, Andrew Cooper, George Dunlap,
	Julien Grall, Stefano Stabellini, Ross Lagerwall, xen-devel

On 24.04.2024 10:19, Roger Pau Monne wrote:
> @@ -571,6 +575,19 @@ int main(int argc, char *argv[])
>          show_help();
>          return 0;
>      }
> +
> +    if ( strcmp("--force", argv[1]) )

I guess this missing ! or "== 0" is the reason for osstest reporting a
livepatch-run failure.

Jan

> +    {
> +        if ( argc <= 2 )
> +        {
> +            show_help();
> +            return EXIT_FAILURE;
> +        }
> +        force = true;
> +        argv++;
> +        argc--;
> +    }
> +
>      for ( i = 0; i < ARRAY_SIZE(main_options); i++ )
>          if (!strcmp(main_options[i].name, argv[1]))
>              break;



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v4 2/4] livepatch: introduce --force option
  2024-04-26  6:41   ` Jan Beulich
@ 2024-04-26  7:15     ` Roger Pau Monné
  0 siblings, 0 replies; 10+ messages in thread
From: Roger Pau Monné @ 2024-04-26  7:15 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Anthony PERARD, Juergen Gross, Andrew Cooper, George Dunlap,
	Julien Grall, Stefano Stabellini, Ross Lagerwall, xen-devel

On Fri, Apr 26, 2024 at 08:41:48AM +0200, Jan Beulich wrote:
> On 24.04.2024 10:19, Roger Pau Monne wrote:
> > @@ -571,6 +575,19 @@ int main(int argc, char *argv[])
> >          show_help();
> >          return 0;
> >      }
> > +
> > +    if ( strcmp("--force", argv[1]) )
> 
> I guess this missing ! or "== 0" is the reason for osstest reporting a
> livepatch-run failure.

Bah, seems like I dropped it when changing from strncmp to strcmp, as
it's present in v3.

Will send a fix ASAP.

Thanks, Roger.


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-04-26  7:15 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-24  8:19 [PATCH v4 0/4] livepatch: minor bug fixes and improvements Roger Pau Monne
2024-04-24  8:19 ` [PATCH v4 1/4] xen-livepatch: fix parameter name parsing Roger Pau Monne
2024-04-24 15:29   ` Anthony PERARD
2024-04-25 14:33   ` Ross Lagerwall
2024-04-24  8:19 ` [PATCH v4 2/4] livepatch: introduce --force option Roger Pau Monne
2024-04-26  6:41   ` Jan Beulich
2024-04-26  7:15     ` Roger Pau Monné
2024-04-24  8:19 ` [PATCH v4 3/4] livepatch: refuse to resolve symbols that belong to init sections Roger Pau Monne
2024-04-25 11:46   ` Roger Pau Monné
2024-04-24  8:19 ` [PATCH v4 4/4] x86/livepatch: perform sanity checks on the payload exception table contents Roger Pau Monne

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).