Skip to contentSkip to conversation

Fixes for livepatching

PATCH In review Andrew Cooper 6 participants 22 messages Jun 22, 2017 – Jun 26, 2017

lore
Share & tools
lore
#0 lore raw

v3 cover Fixes for livepatching

Andrew Cooper (3):
xen/livepatch: Clean up arch relocation handling xen/livepatch: Use zeroed memory allocations for arrays xen/livepatch: Don't crash on encountering STN_UNDEF relocations

 xen/arch/arm/arm32/livepatch.c | 41 +++++++++++++++++++++++++----------------
 xen/arch/arm/arm64/livepatch.c | 33 ++++++++++++++++++++-------------
 xen/arch/x86/livepatch.c       | 27 ++++++++++++++++++---------
 xen/common/livepatch.c         |  4 ++--
 xen/common/livepatch_elf.c     |  4 ++--
 5 files changed, 67 insertions(+), 42 deletions(-)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

PATCH v3 1/3 xen/livepatch: Clean up arch relocation handling

* Reduce symbol scope and initalisation as much as possible
* Annotate a fallthrough case in arm64
* Fix switch statement style in arm32

No functional change.

---
 xen/arch/arm/arm32/livepatch.c | 27 ++++++++++++---------------
 xen/arch/arm/arm64/livepatch.c | 19 +++++++------------
 xen/arch/x86/livepatch.c       | 13 +++++--------
 3 files changed, 24 insertions(+), 35 deletions(-)
xen/arch/arm/arm32/livepatch.c +12 -15
index a7fd5e2..a328179 100644
@@ -224,21 +224,21 @@ int arch_livepatch_perform(struct livepatch_elf *elf,
                            const struct livepatch_elf_sec *rela,
                            bool use_rela)
 {
-    const Elf_RelA *r_a;
-    const Elf_Rel *r;
-    unsigned int symndx, i;
-    uint32_t val;
-    void *dest;
+    unsigned int i;
     int rc = 0;
 
     for ( i = 0; i < (rela->sec->sh_size / rela->sec->sh_entsize); i++ )
     {
+        unsigned int symndx;
+        uint32_t val;
+        void *dest;
         unsigned char type;
-        s32 addend = 0;
+        s32 addend;
 
         if ( use_rela )
         {
-            r_a = rela->data + i * rela->sec->sh_entsize;
+            const Elf_RelA *r_a = rela->data + i * rela->sec->sh_entsize;
+
             symndx = ELF32_R_SYM(r_a->r_info);
             type = ELF32_R_TYPE(r_a->r_info);
             dest = base->load_addr + r_a->r_offset; /* P */
@@ -246,10 +246,12 @@ int arch_livepatch_perform(struct livepatch_elf *elf,
         }
         else
         {
-            r = rela->data + i * rela->sec->sh_entsize;
+            const Elf_Rel *r = rela->data + i * rela->sec->sh_entsize;
+
             symndx = ELF32_R_SYM(r->r_info);
             type = ELF32_R_TYPE(r->r_info);
             dest = base->load_addr + r->r_offset; /* P */
+            addend = get_addend(type, dest);
         }
 
         if ( symndx > elf->nsym )
@@ -259,13 +261,11 @@ int arch_livepatch_perform(struct livepatch_elf *elf,
             return -EINVAL;
         }
 
-        if ( !use_rela )
-            addend = get_addend(type, dest);
-
         val = elf->sym[symndx].sym->st_value; /* S */
 
         rc = perform_rel(type, dest, val, addend);
-        switch ( rc ) {
+        switch ( rc )
+        {
         case -EOVERFLOW:
             dprintk(XENLOG_ERR, LIVEPATCH "%s: Overflow in relocation %u in %s for %s!\n",
                     elf->name, i, rela->name, base->name);
@@ -275,9 +275,6 @@ int arch_livepatch_perform(struct livepatch_elf *elf,
             dprintk(XENLOG_ERR, LIVEPATCH "%s: Unhandled relocation #%x\n",
                     elf->name, type);
             break;
-
-        default:
-            break;
         }
 
         if ( rc )
xen/arch/arm/arm64/livepatch.c +7 -12
index dae64f5..63929b1 100644
@@ -241,19 +241,16 @@ int arch_livepatch_perform_rela(struct livepatch_elf *elf,
                                 const struct livepatch_elf_sec *base,
                                 const struct livepatch_elf_sec *rela)
 {
-    const Elf_RelA *r;
-    unsigned int symndx, i;
-    uint64_t val;
-    void *dest;
-    bool_t overflow_check;
+    unsigned int i;
 
     for ( i = 0; i < (rela->sec->sh_size / rela->sec->sh_entsize); i++ )
     {
+        const Elf_RelA *r = rela->data + i * rela->sec->sh_entsize;
+        unsigned int symndx = ELF64_R_SYM(r->r_info);
+        void *dest = base->load_addr + r->r_offset; /* P */
+        bool overflow_check = true;
         int ovf = 0;
-
-        r = rela->data + i * rela->sec->sh_entsize;
-
-        symndx = ELF64_R_SYM(r->r_info);
+        uint64_t val;
 
         if ( symndx > elf->nsym )
         {
@@ -262,11 +259,8 @@ int arch_livepatch_perform_rela(struct livepatch_elf *elf,
             return -EINVAL;
         }
 
-        dest = base->load_addr + r->r_offset; /* P */
         val = elf->sym[symndx].sym->st_value +  r->r_addend; /* S+A */
 
-        overflow_check = true;
-
         /* ARM64 operations at minimum are always 32-bit. */
         if ( r->r_offset >= base->sec->sh_size ||
             (r->r_offset + sizeof(uint32_t)) > base->sec->sh_size )
@@ -403,6 +397,7 @@ int arch_livepatch_perform_rela(struct livepatch_elf *elf,
 
         case R_AARCH64_ADR_PREL_PG_HI21_NC:
             overflow_check = false;
+            /* Fallthrough. */
         case R_AARCH64_ADR_PREL_PG_HI21:
             ovf = reloc_insn_imm(RELOC_OP_PAGE, dest, val, 12, 21,
                                  AARCH64_INSN_IMM_ADR);
xen/arch/x86/livepatch.c +5 -8
index dd50dd1..7917610 100644
@@ -161,16 +161,14 @@ int arch_livepatch_perform_rela(struct livepatch_elf *elf,
                                 const struct livepatch_elf_sec *base,
                                 const struct livepatch_elf_sec *rela)
 {
-    const Elf_RelA *r;
-    unsigned int symndx, i;
-    uint64_t val;
-    uint8_t *dest;
+    unsigned int i;
 
     for ( i = 0; i < (rela->sec->sh_size / rela->sec->sh_entsize); i++ )
     {
-        r = rela->data + i * rela->sec->sh_entsize;
-
-        symndx = ELF64_R_SYM(r->r_info);
+        const Elf_RelA *r = rela->data + i * rela->sec->sh_entsize;
+        unsigned int symndx = ELF64_R_SYM(r->r_info);
+        uint8_t *dest = base->load_addr + r->r_offset;
+        uint64_t val;
 
         if ( symndx > elf->nsym )
         {
@@ -179,7 +177,6 @@ int arch_livepatch_perform_rela(struct livepatch_elf *elf,
             return -EINVAL;
         }
 
-        dest = base->load_addr + r->r_offset;
         val = r->r_addend + elf->sym[symndx].sym->st_value;
 
         switch ( ELF64_R_TYPE(r->r_info) )
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#2 lore raw

PATCH v3 2/3 xen/livepatch: Use zeroed memory allocations for arrays

In reply to Andrew Cooper

Each of these arrays is sparse. Use zeroed allocations to cause uninitialised array elements to contain deterministic values, most importantly for the embedded pointers.

---
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Ross Lagerwall <[email protected]>

* new in v3

---
 xen/common/livepatch.c     | 4 ++--
 xen/common/livepatch_elf.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
xen/common/livepatch.c +2 -2
index df67a1a..66d532d 100644
@@ -771,8 +771,8 @@ static int build_symbol_table(struct payload *payload,
         }
     }
 
-    symtab = xmalloc_array(struct livepatch_symbol, nsyms);
-    strtab = xmalloc_array(char, strtab_len);
+    symtab = xzalloc_array(struct livepatch_symbol, nsyms);
+    strtab = xzalloc_array(char, strtab_len);
 
     if ( !strtab || !symtab )
     {
xen/common/livepatch_elf.c +2 -2
index c4a9633..b69e271 100644
@@ -52,7 +52,7 @@ static int elf_resolve_sections(struct livepatch_elf *elf, const void *data)
     int rc;
 
     /* livepatch_elf_load sanity checked e_shnum. */
-    sec = xmalloc_array(struct livepatch_elf_sec, elf->hdr->e_shnum);
+    sec = xzalloc_array(struct livepatch_elf_sec, elf->hdr->e_shnum);
     if ( !sec )
     {
         dprintk(XENLOG_ERR, LIVEPATCH"%s: Could not allocate memory for section table!\n",
@@ -225,7 +225,7 @@ static int elf_get_sym(struct livepatch_elf *elf, const void *data)
     /* No need to check values as elf_resolve_sections did it. */
     nsym = symtab_sec->sec->sh_size / symtab_sec->sec->sh_entsize;
 
-    sym = xmalloc_array(struct livepatch_elf_sym, nsym);
+    sym = xzalloc_array(struct livepatch_elf_sym, nsym);
     if ( !sym )
     {
         dprintk(XENLOG_ERR, LIVEPATCH "%s: Could not allocate memory for symbols\n",
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by Tested-by on v3 2/3
#3 lore raw

Re: [PATCH for-4.9 v3 2/3] xen/livepatch: Use zeroed memory allocations for arrays

Quoted 7 lines · Andrew Cooper

Each of these arrays is sparse. Use zeroed allocations to cause uninitialised array elements to contain deterministic values, most importantly for the embedded pointers.

---
CC: Konrad Rzeszutek Wilk <[email protected]>

Quoted 48 lines
CC Ross Lagerwall <[email protected]>

* new in v3

---
 xen/common/livepatch.c     | 4 ++--
 xen/common/livepatch_elf.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
xen/common/livepatch.c +2 -2
index df67a1a..66d532d 100644
@@ -771,8 +771,8 @@ static int build_symbol_table(struct payload *payload,
         }
     }
 
-    symtab = xmalloc_array(struct livepatch_symbol, nsyms);
-    strtab = xmalloc_array(char, strtab_len);
+    symtab = xzalloc_array(struct livepatch_symbol, nsyms);
+    strtab = xzalloc_array(char, strtab_len);
 
     if ( !strtab || !symtab )
     {
xen/common/livepatch_elf.c +2 -2
index c4a9633..b69e271 100644
@@ -52,7 +52,7 @@ static int elf_resolve_sections(struct livepatch_elf *elf, const void *data)
     int rc;
 
     /* livepatch_elf_load sanity checked e_shnum. */
-    sec = xmalloc_array(struct livepatch_elf_sec, elf->hdr->e_shnum);
+    sec = xzalloc_array(struct livepatch_elf_sec, elf->hdr->e_shnum);
     if ( !sec )
     {
         dprintk(XENLOG_ERR, LIVEPATCH"%s: Could not allocate memory for section table!\n",
@@ -225,7 +225,7 @@ static int elf_get_sym(struct livepatch_elf *elf, const void *data)
     /* No need to check values as elf_resolve_sections did it. */
     nsym = symtab_sec->sec->sh_size / symtab_sec->sec->sh_entsize;
 
-    sym = xmalloc_array(struct livepatch_elf_sym, nsym);
+    sym = xzalloc_array(struct livepatch_elf_sym, nsym);
     if ( !sym )
     {
         dprintk(XENLOG_ERR, LIVEPATCH "%s: Could not allocate memory for symbols\n",
Signature · 1 line
2.1.4

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v3 2/3
#4 lore raw

Re: [PATCH for-4.9 v3 2/3] xen/livepatch: Use zeroed memory allocations for arrays

In reply to Andrew Cooper
Quoted 5 lines · Andrew Cooper

Each of these arrays is sparse. Use zeroed allocations to cause uninitialised array elements to contain deterministic values, most importantly for the embedded pointers.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw

PATCH v3 3/3 xen/livepatch: Don't crash on encountering STN_UNDEF relocations

In reply to Andrew Cooper

A symndx of STN_UNDEF is special, and means a symbol value of 0. While legitimate in the ELF standard, its existance in a livepatch is questionable at best. Until a plausible usecase presents itself, reject such a relocation with -EOPNOTSUPP.

Additionally, fix an off-by-one error while range checking symndx, and perform a safety check on elf->sym[symndx].sym before derefencing it, to avoid tripping over a NULL pointer when calculating val.

---
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Ross Lagerwall <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

v3:
* Fix off-by-one error
v2:
* Reject STN_UNDEF with -EOPNOTSUPP

---
 xen/arch/arm/arm32/livepatch.c | 14 +++++++++++++-
 xen/arch/arm/arm64/livepatch.c | 14 +++++++++++++-
 xen/arch/x86/livepatch.c       | 14 +++++++++++++-
 3 files changed, 39 insertions(+), 3 deletions(-)
xen/arch/arm/arm32/livepatch.c +13 -1
index a328179..41378a5 100644
@@ -254,12 +254,24 @@ int arch_livepatch_perform(struct livepatch_elf *elf,
             addend = get_addend(type, dest);
         }
 
-        if ( symndx > elf->nsym )
+        if ( symndx == STN_UNDEF )
+        {
+            dprintk(XENLOG_ERR, LIVEPATCH "%s: Encountered STN_UNDEF\n",
+                    elf->name);
+            return -EOPNOTSUPP;
+        }
+        else if ( symndx >= elf->nsym )
         {
             dprintk(XENLOG_ERR, LIVEPATCH "%s: Relative symbol wants symbol@%u which is past end!\n",
                     elf->name, symndx);
             return -EINVAL;
         }
+        else if ( !elf->sym[symndx].sym )
+        {
+            dprintk(XENLOG_ERR, LIVEPATCH "%s: No relative symbol@%u\n",
+                    elf->name, symndx);
+            return -EINVAL;
+        }
 
         val = elf->sym[symndx].sym->st_value; /* S */
 
xen/arch/arm/arm64/livepatch.c +13 -1
index 63929b1..2247b92 100644
@@ -252,12 +252,24 @@ int arch_livepatch_perform_rela(struct livepatch_elf *elf,
         int ovf = 0;
         uint64_t val;
 
-        if ( symndx > elf->nsym )
+        if ( symndx == STN_UNDEF )
+        {
+            dprintk(XENLOG_ERR, LIVEPATCH "%s: Encountered STN_UNDEF\n",
+                    elf->name);
+            return -EOPNOTSUPP;
+        }
+        else if ( symndx >= elf->nsym )
         {
             dprintk(XENLOG_ERR, LIVEPATCH "%s: Relative relocation wants symbol@%u which is past end!\n",
                     elf->name, symndx);
             return -EINVAL;
         }
+        else if ( !elf->sym[symndx].sym )
+        {
+            dprintk(XENLOG_ERR, LIVEPATCH "%s: No relative symbol@%u\n",
+                    elf->name, symndx);
+            return -EINVAL;
+        }
 
         val = elf->sym[symndx].sym->st_value +  r->r_addend; /* S+A */
 
xen/arch/x86/livepatch.c +13 -1
index 7917610..406eb91 100644
@@ -170,12 +170,24 @@ int arch_livepatch_perform_rela(struct livepatch_elf *elf,
         uint8_t *dest = base->load_addr + r->r_offset;
         uint64_t val;
 
-        if ( symndx > elf->nsym )
+        if ( symndx == STN_UNDEF )
+        {
+            dprintk(XENLOG_ERR, LIVEPATCH "%s: Encountered STN_UNDEF\n",
+                    elf->name);
+            return -EOPNOTSUPP;
+        }
+        else if ( symndx >= elf->nsym )
         {
             dprintk(XENLOG_ERR, LIVEPATCH "%s: Relative relocation wants symbol@%u which is past end!\n",
                     elf->name, symndx);
             return -EINVAL;
         }
+        else if ( !elf->sym[symndx].sym )
+        {
+            dprintk(XENLOG_ERR, LIVEPATCH "%s: No symbol@%u\n",
+                    elf->name, symndx);
+            return -EINVAL;
+        }
 
         val = r->r_addend + elf->sym[symndx].sym->st_value;
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v3 3/3
#6 lore raw

Re: [PATCH for-4.9 v3 3/3] xen/livepatch: Don't crash on encountering STN_UNDEF relocations

Quoted 17 lines · Andrew Cooper

A symndx of STN_UNDEF is special, and means a symbol value of 0. While legitimate in the ELF standard, its existance in a livepatch is questionable at best. Until a plausible usecase presents itself, reject such a relocation with -EOPNOTSUPP.

Additionally, fix an off-by-one error while range checking symndx, and perform a safety check on elf->sym[symndx].sym before derefencing it, to avoid tripping over a NULL pointer when calculating val.

---
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Ross Lagerwall <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

Quoted 4 lines

v3:
* Fix off-by-one error
v2:
* Reject STN_UNDEF with -EOPNOTSUPP

Quoted 99 lines
---
 xen/arch/arm/arm32/livepatch.c | 14 +++++++++++++-
 xen/arch/arm/arm64/livepatch.c | 14 +++++++++++++-
 xen/arch/x86/livepatch.c       | 14 +++++++++++++-
 3 files changed, 39 insertions(+), 3 deletions(-)
xen/arch/arm/arm32/livepatch.c +13 -1
index a328179..41378a5 100644
@@ -254,12 +254,24 @@ int arch_livepatch_perform(struct livepatch_elf *elf,
             addend = get_addend(type, dest);
         }
 
-        if ( symndx > elf->nsym )
+        if ( symndx == STN_UNDEF )
+        {
+            dprintk(XENLOG_ERR, LIVEPATCH "%s: Encountered STN_UNDEF\n",
+                    elf->name);
+            return -EOPNOTSUPP;
+        }
+        else if ( symndx >= elf->nsym )
         {
             dprintk(XENLOG_ERR, LIVEPATCH "%s: Relative symbol wants symbol@%u which is past end!\n",
                     elf->name, symndx);
             return -EINVAL;
         }
+        else if ( !elf->sym[symndx].sym )
+        {
+            dprintk(XENLOG_ERR, LIVEPATCH "%s: No relative symbol@%u\n",
+                    elf->name, symndx);
+            return -EINVAL;
+        }
 
         val = elf->sym[symndx].sym->st_value; /* S */
 
xen/arch/arm/arm64/livepatch.c +13 -1
index 63929b1..2247b92 100644
@@ -252,12 +252,24 @@ int arch_livepatch_perform_rela(struct livepatch_elf *elf,
         int ovf = 0;
         uint64_t val;
 
-        if ( symndx > elf->nsym )
+        if ( symndx == STN_UNDEF )
+        {
+            dprintk(XENLOG_ERR, LIVEPATCH "%s: Encountered STN_UNDEF\n",
+                    elf->name);
+            return -EOPNOTSUPP;
+        }
+        else if ( symndx >= elf->nsym )
         {
             dprintk(XENLOG_ERR, LIVEPATCH "%s: Relative relocation wants symbol@%u which is past end!\n",
                     elf->name, symndx);
             return -EINVAL;
         }
+        else if ( !elf->sym[symndx].sym )
+        {
+            dprintk(XENLOG_ERR, LIVEPATCH "%s: No relative symbol@%u\n",
+                    elf->name, symndx);
+            return -EINVAL;
+        }
 
         val = elf->sym[symndx].sym->st_value +  r->r_addend; /* S+A */
 
xen/arch/x86/livepatch.c +13 -1
index 7917610..406eb91 100644
@@ -170,12 +170,24 @@ int arch_livepatch_perform_rela(struct livepatch_elf *elf,
         uint8_t *dest = base->load_addr + r->r_offset;
         uint64_t val;
 
-        if ( symndx > elf->nsym )
+        if ( symndx == STN_UNDEF )
+        {
+            dprintk(XENLOG_ERR, LIVEPATCH "%s: Encountered STN_UNDEF\n",
+                    elf->name);
+            return -EOPNOTSUPP;
+        }
+        else if ( symndx >= elf->nsym )
         {
             dprintk(XENLOG_ERR, LIVEPATCH "%s: Relative relocation wants symbol@%u which is past end!\n",
                     elf->name, symndx);
             return -EINVAL;
         }
+        else if ( !elf->sym[symndx].sym )
+        {
+            dprintk(XENLOG_ERR, LIVEPATCH "%s: No symbol@%u\n",
+                    elf->name, symndx);
+            return -EINVAL;
+        }
 
         val = r->r_addend + elf->sym[symndx].sym->st_value;
 
Signature · 1 line
2.1.4

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by Tested-by on v3 3/3
#7 lore raw

Re: [PATCH for-4.9 v3 3/3] xen/livepatch: Don't crash on encountering STN_UNDEF relocations

In reply to Andrew Cooper
Quoted 5 lines · Andrew Cooper

A symndx of STN_UNDEF is special, and means a symbol value of 0. While legitimate in the ELF standard, its existance in a livepatch is questionable at best. Until a plausible usecase presents itself, reject such a relocation with -EOPNOTSUPP.

Quoted 7 lines

Additionally, fix an off-by-one error while range checking symndx, and perform a safety check on elf->sym[symndx].sym before derefencing it, to avoid tripping over a NULL pointer when calculating val.

---
CC: Konrad Rzeszutek Wilk <[email protected]>

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v3 3/3
#8 lore raw

Re: [PATCH for-4.9 v3 3/3] xen/livepatch: Don't crash on encountering STN_UNDEF relocations

In reply to Andrew Cooper
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 22.06.17 at 20:15, <[email protected]> wrote:

A symndx of STN_UNDEF is special, and means a symbol value of 0. While legitimate in the ELF standard, its existance in a livepatch is questionable at best. Until a plausible usecase presents itself, reject such a relocation with -EOPNOTSUPP.

Additionally, fix an off-by-one error while range checking symndx, and perform a safety check on elf->sym[symndx].sym before derefencing it, to avoid tripping over a NULL pointer when calculating val.

with two remarks:

Quoted 10 lines
xen/arch/x86/livepatch.c +3 -1
@@ -170,12 +170,24 @@ int arch_livepatch_perform_rela(struct livepatch_elf *elf,
         uint8_t *dest = base->load_addr + r->r_offset;
         uint64_t val;
 
-        if ( symndx > elf->nsym )
+        if ( symndx == STN_UNDEF )
+        {
+            dprintk(XENLOG_ERR, LIVEPATCH "%s: Encountered STN_UNDEF\n",

xen/arch/x86/livepatch.c int arch_livepatch_perform_rela(struct livepatch_elf *elf, · line 185

Quoted 10 lines
xen/arch/x86/livepatch.c +5 -0
+                    elf->name);
+            return -EOPNOTSUPP;
+        }
+        else if ( symndx >= elf->nsym )
         {
             dprintk(XENLOG_ERR, LIVEPATCH "%s: Relative relocation wants symbol@%u which is past end!\n",
                     elf->name, symndx);
             return -EINVAL;
         }
+        else if ( !elf->sym[symndx].sym )

Neither of the two "else" is really necessary, and elsewhere we've been telling people to avoid such.

xen/arch/x86/livepatch.c int arch_livepatch_perform_rela(struct livepatch_elf *elf, · line 187

Quoted 2 lines
xen/arch/x86/livepatch.c +2 -0
+        {
+            dprintk(XENLOG_ERR, LIVEPATCH "%s: No symbol@%u\n",

Symbol tables can grow large, and for large numbers I generally find hex representation preferable of dec. Otoh the other (pre-existing) message uses dec too ...

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#9 lore raw

Re: [PATCH for-4.9 v3 3/3] xen/livepatch: Don't crash on encountering STN_UNDEF relocations

Quoted 20 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 22.06.17 at 20:15, <[email protected]> wrote:

A symndx of STN_UNDEF is special, and means a symbol value of 0. While legitimate in the ELF standard, its existance in a livepatch is questionable at best. Until a plausible usecase presents itself, reject such a relocation with -EOPNOTSUPP.

Additionally, fix an off-by-one error while range checking symndx, and perform a safety check on elf->sym[symndx].sym before derefencing it, to avoid tripping over a NULL pointer when calculating val.

with two remarks:

Quoted 6 lines
xen/arch/x86/livepatch.c +0 -0
@@ -170,12 +170,24 @@ int arch_livepatch_perform_rela(struct livepatch_elf *elf,
         uint8_t *dest = base->load_addr + r->r_offset;
         uint64_t val;
 
Quoted 16 lines
Quoted 4 lines
xen/arch/x86/livepatch.c +3 -1
-        if ( symndx > elf->nsym )
+        if ( symndx == STN_UNDEF )
+        {
+            dprintk(XENLOG_ERR, LIVEPATCH "%s: Encountered STN_UNDEF\n",

xen/arch/x86/livepatch.c int arch_livepatch_perform_rela(struct livepatch_elf *elf, · line 185

Quoted 10 lines
xen/arch/x86/livepatch.c +5 -0
+                    elf->name);
+            return -EOPNOTSUPP;
+        }
+        else if ( symndx >= elf->nsym )
         {
             dprintk(XENLOG_ERR, LIVEPATCH "%s: Relative relocation wants symbol@%u which is past end!\n",
                     elf->name, symndx);
             return -EINVAL;
         }
+        else if ( !elf->sym[symndx].sym )

Neither of the two "else" is really necessary, and elsewhere we've been telling people to avoid such.

I see two logically different scenarios.

Per the style, if I were to use fully separate if() statements, I'd need a newline between each. This expands the code, and separates a chain of logically-related checks.

IMO, its better to keep logically related checks more obviously together, while I would definitely agree that unrelated chains (which could in principle be if/else like this) should be separated.

Quoted 6 lines

xen/arch/x86/livepatch.c int arch_livepatch_perform_rela(struct livepatch_elf *elf, · line 187

Quoted 3 lines
xen/arch/x86/livepatch.c +2 -0
+        {
+            dprintk(XENLOG_ERR, LIVEPATCH "%s: No symbol@%u\n",

Symbol tables can grow large, and for large numbers I generally find hex representation preferable of dec. Otoh the other (pre-existing) message uses dec too ...

I'll stay consistent with everything else.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v3 3/3
#10 lore raw

Re: [PATCH for-4.9 v3 3/3] xen/livepatch: Don't crash on encountering STN_UNDEF relocations

In reply to Andrew Cooper
Quoted 10 lines · Andrew Cooper

A symndx of STN_UNDEF is special, and means a symbol value of 0. While legitimate in the ELF standard, its existance in a livepatch is questionable at best. Until a plausible usecase presents itself, reject such a relocation with -EOPNOTSUPP.

Additionally, fix an off-by-one error while range checking symndx, and perform a safety check on elf->sym[symndx].sym before derefencing it, to avoid tripping over a NULL pointer when calculating val.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#11 lore raw

Re: [PATCH for-4.9 v3 3/3] xen/livepatch: Don't crash on encountering STN_UNDEF relocations

In reply to Andrew Cooper

Hi Andrew,

I am a bit confused, the title says "PATCH for-4.9 v3 3/3". I haven't been CCed on the first two patches. Does it mean you are only looking at this patch to be in 4.9?

Cheers,

Quoted 118 lines · Andrew Cooper

A symndx of STN_UNDEF is special, and means a symbol value of 0. While legitimate in the ELF standard, its existance in a livepatch is questionable at best. Until a plausible usecase presents itself, reject such a relocation with -EOPNOTSUPP.

Additionally, fix an off-by-one error while range checking symndx, and perform a safety check on elf->sym[symndx].sym before derefencing it, to avoid tripping over a NULL pointer when calculating val.

---
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Ross Lagerwall <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

v3:
* Fix off-by-one error
v2:
* Reject STN_UNDEF with -EOPNOTSUPP

---
 xen/arch/arm/arm32/livepatch.c | 14 +++++++++++++-
 xen/arch/arm/arm64/livepatch.c | 14 +++++++++++++-
 xen/arch/x86/livepatch.c       | 14 +++++++++++++-
 3 files changed, 39 insertions(+), 3 deletions(-)
xen/arch/arm/arm32/livepatch.c +13 -1
index a328179..41378a5 100644
@@ -254,12 +254,24 @@ int arch_livepatch_perform(struct livepatch_elf *elf,
             addend = get_addend(type, dest);
         }
 
-        if ( symndx > elf->nsym )
+        if ( symndx == STN_UNDEF )
+        {
+            dprintk(XENLOG_ERR, LIVEPATCH "%s: Encountered STN_UNDEF\n",
+                    elf->name);
+            return -EOPNOTSUPP;
+        }
+        else if ( symndx >= elf->nsym )
         {
             dprintk(XENLOG_ERR, LIVEPATCH "%s: Relative symbol wants symbol@%u which is past end!\n",
                     elf->name, symndx);
             return -EINVAL;
         }
+        else if ( !elf->sym[symndx].sym )
+        {
+            dprintk(XENLOG_ERR, LIVEPATCH "%s: No relative symbol@%u\n",
+                    elf->name, symndx);
+            return -EINVAL;
+        }
 
         val = elf->sym[symndx].sym->st_value; /* S */
 
xen/arch/arm/arm64/livepatch.c +13 -1
index 63929b1..2247b92 100644
@@ -252,12 +252,24 @@ int arch_livepatch_perform_rela(struct livepatch_elf *elf,
         int ovf = 0;
         uint64_t val;
 
-        if ( symndx > elf->nsym )
+        if ( symndx == STN_UNDEF )
+        {
+            dprintk(XENLOG_ERR, LIVEPATCH "%s: Encountered STN_UNDEF\n",
+                    elf->name);
+            return -EOPNOTSUPP;
+        }
+        else if ( symndx >= elf->nsym )
         {
             dprintk(XENLOG_ERR, LIVEPATCH "%s: Relative relocation wants symbol@%u which is past end!\n",
                     elf->name, symndx);
             return -EINVAL;
         }
+        else if ( !elf->sym[symndx].sym )
+        {
+            dprintk(XENLOG_ERR, LIVEPATCH "%s: No relative symbol@%u\n",
+                    elf->name, symndx);
+            return -EINVAL;
+        }
 
         val = elf->sym[symndx].sym->st_value +  r->r_addend; /* S+A */
 
xen/arch/x86/livepatch.c +13 -1
index 7917610..406eb91 100644
@@ -170,12 +170,24 @@ int arch_livepatch_perform_rela(struct livepatch_elf *elf,
         uint8_t *dest = base->load_addr + r->r_offset;
         uint64_t val;
 
-        if ( symndx > elf->nsym )
+        if ( symndx == STN_UNDEF )
+        {
+            dprintk(XENLOG_ERR, LIVEPATCH "%s: Encountered STN_UNDEF\n",
+                    elf->name);
+            return -EOPNOTSUPP;
+        }
+        else if ( symndx >= elf->nsym )
         {
             dprintk(XENLOG_ERR, LIVEPATCH "%s: Relative relocation wants symbol@%u which is past end!\n",
                     elf->name, symndx);
             return -EINVAL;
         }
+        else if ( !elf->sym[symndx].sym )
+        {
+            dprintk(XENLOG_ERR, LIVEPATCH "%s: No symbol@%u\n",
+                    elf->name, symndx);
+            return -EINVAL;
+        }
 
         val = r->r_addend + elf->sym[symndx].sym->st_value;
 
Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#12 lore raw

Re: [PATCH for-4.9 v3 3/3] xen/livepatch: Don't crash on encountering STN_UNDEF relocations

Quoted 5 lines · Julien Grall

Hi Andrew,

I am a bit confused, the title says "PATCH for-4.9 v3 3/3". I haven't been CCed on the first two patches. Does it mean you are only looking at this patch to be in 4.9?

Sorry - I messed up the CC lists. The correctness of this patch does depend on the previous two, so all 3 are looking for inclusion.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#13 lore raw

Re: [PATCH for-4.9 v3 3/3] xen/livepatch: Don't crash on encountering STN_UNDEF relocations

Hi,

Quoted 9 lines · Andrew Cooper
Quoted 5 lines · Julien Grall

Hi Andrew,

I am a bit confused, the title says "PATCH for-4.9 v3 3/3". I haven't been CCed on the first two patches. Does it mean you are only looking at this patch to be in 4.9?

Sorry - I messed up the CC lists. The correctness of this patch does depend on the previous two, so all 3 are looking for inclusion.

Given that we don't have livepatch testing in osstest how much test have we done on those 3 patches?

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#14 lore raw

Re: [PATCH for-4.9 v3 3/3] xen/livepatch: Don't crash on encountering STN_UNDEF relocations

Quoted 10 lines · Julien Grall

Hi,

Quoted 7 lines · Andrew Cooper
Quoted 5 lines · Julien Grall

Hi Andrew,

I am a bit confused, the title says "PATCH for-4.9 v3 3/3". I haven't been CCed on the first two patches. Does it mean you are only looking at this patch to be in 4.9?

Quoted 5 lines
Quoted 2 lines

Sorry - I messed up the CC lists. The correctness of this patch does depend on the previous two, so all 3 are looking for inclusion.

Given that we don't have livepatch testing in osstest how much test have we done on those 3 patches?

There is testing in OSSTest.

I've manually run each of the scenarios, including with my livepatch which has a STN_UNDEF relocation.

I don't know what testing Konrad has done.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#15 lore raw

Re: [PATCH for-4.9 v3 3/3] xen/livepatch: Don't crash on encountering STN_UNDEF relocations

Quoted 11 lines · Andrew Cooper
Quoted 10 lines · Julien Grall

Hi,

Quoted 7 lines · Andrew Cooper
Quoted 5 lines · Julien Grall

Hi Andrew,

I am a bit confused, the title says "PATCH for-4.9 v3 3/3". I haven't been CCed on the first two patches. Does it mean you are only looking at this patch to be in 4.9?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Sorry - I messed up the CC lists. The correctness of this patch does depend on the previous two, so all 3 are looking for inclusion.

Given that we don't have livepatch testing in osstest how much test have we done on those 3 patches?

There is testing in OSSTest.

Oh yes sorry. But only for amd64 and i386. No arm32 nor arm64 test.

Quoted 5 lines

I've manually run each of the scenarios, including with my livepatch which has a STN_UNDEF relocation.

I don't know what testing Konrad has done.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#16 lore raw

Re: [PATCH for-4.9 v3 3/3] xen/livepatch: Don't crash on encountering STN_UNDEF relocations

In reply to Andrew Cooper
Quoted 11 lines · Andrew Cooper
Quoted 10 lines · Julien Grall

Hi,

Quoted 7 lines · Andrew Cooper
Quoted 5 lines · Julien Grall

Hi Andrew,

I am a bit confused, the title says "PATCH for-4.9 v3 3/3". I haven't been CCed on the first two patches. Does it mean you are only looking at this patch to be in 4.9?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Sorry - I messed up the CC lists. The correctness of this patch does depend on the previous two, so all 3 are looking for inclusion.

Given that we don't have livepatch testing in osstest how much test have we done on those 3 patches?

There is testing in OSSTest.

Hurray hurray hurray!

Quoted 5 lines

I've manually run each of the scenarios, including with my livepatch which has a STN_UNDEF relocation.

I don't know what testing Konrad has done.

I run a version of the same tests that are in OSSTest (basically an earlier version of the Perl code) and I have done it on x86 and on ARM32.

And I also run the standalone OSSTest (on x86)

And then I also do a livepatch using the livepatch-build-tools on x86 to patch some silly function.

So from a testing perspective these patches have been tested very exhaustively.

Quoted 2 lines

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#17 lore raw

Re: [PATCH for-4.9 v3 3/3] xen/livepatch: Don't crash on encountering STN_UNDEF relocations

Quoted 30 lines · Konrad Rzeszutek Wilk
Quoted 11 lines · Andrew Cooper
Quoted 10 lines · Julien Grall

Hi,

Quoted 7 lines · Andrew Cooper
Quoted 5 lines · Julien Grall

Hi Andrew,

I am a bit confused, the title says "PATCH for-4.9 v3 3/3". I haven't been CCed on the first two patches. Does it mean you are only looking at this patch to be in 4.9?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Sorry - I messed up the CC lists. The correctness of this patch does depend on the previous two, so all 3 are looking for inclusion.

Given that we don't have livepatch testing in osstest how much test have we done on those 3 patches?

There is testing in OSSTest.

Hurray hurray hurray!

Quoted 5 lines

I've manually run each of the scenarios, including with my livepatch which has a STN_UNDEF relocation.

I don't know what testing Konrad has done.

I run a version of the same tests that are in OSSTest (basically an earlier version of the Perl code) and I have done it on x86 and on ARM32.

Quoted 6 lines

And I also run the standalone OSSTest (on x86)

And then I also do a livepatch using the livepatch-build-tools on x86 to patch some silly function.

So from a testing perspective these patches have been tested very exhaustively.

Well it has not been tested on ARM64 :). I am about to do that.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#18 lore raw

Re: [PATCH for-4.9 v3 3/3] xen/livepatch: Don't crash on encountering STN_UNDEF relocations

Quoted 33 lines · Julien Grall
Quoted 30 lines · Konrad Rzeszutek Wilk
Quoted 11 lines · Andrew Cooper
Quoted 10 lines · Julien Grall

Hi,

Quoted 7 lines · Andrew Cooper
Quoted 5 lines · Julien Grall

Hi Andrew,

I am a bit confused, the title says "PATCH for-4.9 v3 3/3". I haven't been CCed on the first two patches. Does it mean you are only looking at this patch to be in 4.9?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Sorry - I messed up the CC lists. The correctness of this patch does depend on the previous two, so all 3 are looking for inclusion.

Given that we don't have livepatch testing in osstest how much test have we done on those 3 patches?

There is testing in OSSTest.

Hurray hurray hurray!

Quoted 5 lines

I've manually run each of the scenarios, including with my livepatch which has a STN_UNDEF relocation.

I don't know what testing Konrad has done.

I run a version of the same tests that are in OSSTest (basically an earlier version of the Perl code) and I have done it on x86 and on ARM32.

Quoted 8 lines
Quoted 6 lines

And I also run the standalone OSSTest (on x86)

And then I also do a livepatch using the livepatch-build-tools on x86 to patch some silly function.

So from a testing perspective these patches have been tested very exhaustively.

Well it has not been tested on ARM64 :). I am about to do that.

/me facepalm.

I really need to get myself a working ARM64 box that is not expensive.

Also attached is the poor-man livepatch_test.perl script that mirrors what OSSTest does.

[Do adjust the path, it is /usr/lib/debug, but it should be /usr/lib/debug/livepatch with Xen 4.9]

#!/usr/bin/perl

use Data::Dumper;

my @livepatch_files = ("xen_hello_world.livepatch", "xen_replace_world.livepatch",

			"xen_bye_world.livepatch", "xen_nop.livepatch");

my @livepatch_tests = (

	{cmd => "xen-livepatch list", rc => 0},
	{cmd => "xl info | grep xen_extra | grep -q \"Hello World\"", rc => 256},
	{cmd => "xen-livepatch revert xen_hello_world", rc => 256},
	{cmd => "xen-livepatch load xen_hello_world.livepatch", rc => 0},
	{cmd => "xen-livepatch load xen_hello_world.livepatch", rc => 256},
	{cmd => "xen-livepatch list | grep -q xen_hello_world", rc => 0},
	{cmd => "xl info | grep xen_extra | grep -q \"Hello World\"", rc => 0},
	{cmd => "xen-livepatch revert xen_hello_world", rc => 0},
	{cmd => "xl info | grep xen_extra | grep -q \"Hello World\"", rc => 256},
	{cmd => "xen-livepatch unload xen_hello_world", rc => 0},
	{cmd => "xen-livepatch unload xen_hello_world", rc => 256},
	{cmd => "xl info | grep xen_extra | grep -q \"Hello World\"", rc => 256},
	{cmd => "xen-livepatch load xen_hello_world.livepatch", rc => 0},
	{cmd => "xen-livepatch load xen_bye_world.livepatch", rc => 0},
	{cmd => "xl info | grep xen_extra | grep -q \"Bye World\"", rc => 0},
	{cmd => "xen-livepatch upload xen_replace xen_replace_world.livepatch", rc => 0},
	{cmd => "xen-livepatch replace xen_replace", rc => 0},
	{cmd => "xen-livepatch apply xen_hello_world", rc => 256},
	{cmd => "xen-livepatch apply xen_bye_world", rc => 256},
	{cmd => "xl info | grep xen_extra | grep -q \"Hello Again Wor\"", rc => 0},
	{cmd => "xen-livepatch apply xen_replace", rc => 0},
	{cmd => "xen-livepatch revert xen_replace", rc => 0},
	{cmd => "xen-livepatch unload xen_replace", rc => 0},
	{cmd => "xen-livepatch unload xen_hello_world", rc => 0},
	{cmd => "xen-livepatch unload xen_bye_world", rc => 0},
	{cmd => "xen-livepatch list | grep -q xen", rc => 256},
	# If running this under Xen 4.4, or 5.5 it will fail.
	#{cmd => "[ `xl info| grep \"xen_m\" | grep or | sed s/.*:// | uniq | wc -l` == 2 ]", rc => 0},
	{cmd => "xen-livepatch load xen_nop.livepatch", rc => 0},
	{cmd => "xen-livepatch revert xen_nop", rc => 0},
	{cmd => "xen-livepatch apply xen_nop", rc => 0},
	{cmd => "[ `xl info| grep \"xen_m\" | grep or | sed s/.*:// | uniq | wc -l` == 1 ]", rc => 0},
	{cmd => "xen-livepatch unload xen_nop", rc => 256},
	{cmd => "xen-livepatch revert xen_nop", rc => 0},
	{cmd => "xen-livepatch unload xen_nop", rc => 0},
	);

chdir("/usr/lib/debug") or die "cannot change: $!\n";

foreach my $file (@livepatch_files)

{
	if ( ! -f $file ) {
		die "$file is missing!\n";
	}
}
print "Have $#livepatch_tests test-cases\n";
my $rc=0;
for my $i ( 0 .. $#livepatch_tests ) {
	my $expected_rc = $livepatch_tests[$i]{rc};
	my $cmd = $livepatch_tests[$i]{cmd};
	print "Executing: '$cmd:' ..";
	my $rc=system($cmd);
	if ( $rc != $expected_rc ) {
		print "FAILED (got $rc, expected: $expected_rc)\n";
		exit $rc
	}
	print ".. OK!\n";
}

exit $rc

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#19 lore raw

Re: [PATCH for-4.9 v3 3/3] xen/livepatch: Don't crash on encountering STN_UNDEF relocations

Hi Konrad,

Quoted 43 lines · Konrad Rzeszutek Wilk
Quoted 33 lines · Julien Grall
Quoted 30 lines · Konrad Rzeszutek Wilk
Quoted 11 lines · Andrew Cooper
Quoted 10 lines · Julien Grall

Hi,

Quoted 7 lines · Andrew Cooper
Quoted 5 lines · Julien Grall

Hi Andrew,

I am a bit confused, the title says "PATCH for-4.9 v3 3/3". I haven't been CCed on the first two patches. Does it mean you are only looking at this patch to be in 4.9?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Sorry - I messed up the CC lists. The correctness of this patch does depend on the previous two, so all 3 are looking for inclusion.

Given that we don't have livepatch testing in osstest how much test have we done on those 3 patches?

There is testing in OSSTest.

Hurray hurray hurray!

Quoted 5 lines

I've manually run each of the scenarios, including with my livepatch which has a STN_UNDEF relocation.

I don't know what testing Konrad has done.

I run a version of the same tests that are in OSSTest (basically an earlier version of the Perl code) and I have done it on x86 and on ARM32.

Quoted 8 lines
Quoted 6 lines

And I also run the standalone OSSTest (on x86)

And then I also do a livepatch using the livepatch-build-tools on x86 to patch some silly function.

So from a testing perspective these patches have been tested very exhaustively.

Well it has not been tested on ARM64 :). I am about to do that.

Quoted 7 lines

/me facepalm.

I really need to get myself a working ARM64 box that is not expensive.

Also attached is the poor-man livepatch_test.perl script that mirrors what OSSTest does.

I have got an error when executing the script after applying the "nop" livepatch:

Executing: 'xen-livepatch apply xen_nop:' ..Applying xen_nop... completed
.. OK!
Executing: '[ xl info| grep "xen_m" | grep or | sed s/.*:// | uniq | wc -l == 1 ]:' ..sh: 1: [: 1: unexpected operator FAILED (got 512, expected: 0)

But this looks like a script error than livepatch. Although, I was not able to spot the error in the script.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#20 lore raw

Re: [PATCH for-4.9 v3 3/3] xen/livepatch: Don't crash on encountering STN_UNDEF relocations

Quoted 54 lines · Julien Grall

Hi Konrad,

Quoted 43 lines · Konrad Rzeszutek Wilk
Quoted 33 lines · Julien Grall
Quoted 30 lines · Konrad Rzeszutek Wilk
Quoted 11 lines · Andrew Cooper
Quoted 10 lines · Julien Grall

Hi,

Quoted 7 lines · Andrew Cooper
Quoted 5 lines · Julien Grall

Hi Andrew,

I am a bit confused, the title says "PATCH for-4.9 v3 3/3". I haven't been CCed on the first two patches. Does it mean you are only looking at this patch to be in 4.9?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Sorry - I messed up the CC lists. The correctness of this patch does depend on the previous two, so all 3 are looking for inclusion.

Given that we don't have livepatch testing in osstest how much test have we done on those 3 patches?

There is testing in OSSTest.

Hurray hurray hurray!

Quoted 5 lines

I've manually run each of the scenarios, including with my livepatch which has a STN_UNDEF relocation.

I don't know what testing Konrad has done.

I run a version of the same tests that are in OSSTest (basically an earlier version of the Perl code) and I have done it on x86 and on ARM32.

Quoted 8 lines
Quoted 6 lines

And I also run the standalone OSSTest (on x86)

And then I also do a livepatch using the livepatch-build-tools on x86 to patch some silly function.

So from a testing perspective these patches have been tested very exhaustively.

Well it has not been tested on ARM64 :). I am about to do that.

Quoted 7 lines

/me facepalm.

I really need to get myself a working ARM64 box that is not expensive.

Also attached is the poor-man livepatch_test.perl script that mirrors what OSSTest does.

Quoted 8 lines

I have got an error when executing the script after applying the "nop" livepatch:

Executing: 'xen-livepatch apply xen_nop:' ..Applying xen_nop... completed .. OK!
Executing: '[ xl info| grep "xen_m" | grep or | sed s/.*:// | uniq | wc -l == 1 ]:' ..sh: 1: [: 1: unexpected operator
FAILED (got 512, expected: 0)

Yeah I only get that when I execute it from the serial console. When I SSH it works fine.

Quoted 3 lines

But this looks like a script error than livepatch. Although, I was not able to spot the error in the script.

Neither could I. I do also have an earlier variant of this testing script in bash (with less test-cases).

Quoted 5 lines

Cheers,

Signature · 1 line
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#21 lore raw

Re: [PATCH for-4.9 v3 3/3] xen/livepatch: Don't crash on encountering STN_UNDEF relocations

Quoted 68 lines · Konrad Rzeszutek Wilk
Quoted 54 lines · Julien Grall

Hi Konrad,

Quoted 43 lines · Konrad Rzeszutek Wilk
Quoted 33 lines · Julien Grall
Quoted 30 lines · Konrad Rzeszutek Wilk
Quoted 11 lines · Andrew Cooper
Quoted 10 lines · Julien Grall

Hi,

Quoted 7 lines · Andrew Cooper
Quoted 5 lines · Julien Grall

Hi Andrew,

I am a bit confused, the title says "PATCH for-4.9 v3 3/3". I haven't been CCed on the first two patches. Does it mean you are only looking at this patch to be in 4.9?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Sorry - I messed up the CC lists. The correctness of this patch does depend on the previous two, so all 3 are looking for inclusion.

Given that we don't have livepatch testing in osstest how much test have we done on those 3 patches?

There is testing in OSSTest.

Hurray hurray hurray!

Quoted 5 lines

I've manually run each of the scenarios, including with my livepatch which has a STN_UNDEF relocation.

I don't know what testing Konrad has done.

I run a version of the same tests that are in OSSTest (basically an earlier version of the Perl code) and I have done it on x86 and on ARM32.

Quoted 8 lines
Quoted 6 lines

And I also run the standalone OSSTest (on x86)

And then I also do a livepatch using the livepatch-build-tools on x86 to patch some silly function.

So from a testing perspective these patches have been tested very exhaustively.

Well it has not been tested on ARM64 :). I am about to do that.

Quoted 7 lines

/me facepalm.

I really need to get myself a working ARM64 box that is not expensive.

Also attached is the poor-man livepatch_test.perl script that mirrors what OSSTest does.

Quoted 8 lines

I have got an error when executing the script after applying the "nop" livepatch:

Executing: 'xen-livepatch apply xen_nop:' ..Applying xen_nop... completed .. OK!
Executing: '[ xl info| grep "xen_m" | grep or | sed s/.*:// | uniq | wc -l == 1 ]:' ..sh: 1: [: 1: unexpected operator
FAILED (got 512, expected: 0)

Yeah I only get that when I execute it from the serial console. When I SSH it works fine.

Quoted 1 line
Quoted 5 lines
Quoted 2 lines

But this looks like a script error than livepatch. Although, I was not able to spot the error in the script.

Neither could I. I do also have an earlier variant of this testing script in bash (with less test-cases).

I am happy with this patch series to be backported in Xen 4.9:

Can they be backported today please?

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel