[xen stable-4.7] xen/livepatch: Don't crash on encountering STN_UNDEF relocations

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[xen stable-4.7] xen/livepatch: Don't crash on encountering STN_UNDEF relocations

patchbot
commit ca4ef7b5e800b1cc1631de2f47cf133b19fd1a72
Author:     Andrew Cooper <[hidden email]>
AuthorDate: Mon Aug 28 13:01:23 2017 +0200
Commit:     Jan Beulich <[hidden email]>
CommitDate: Mon Aug 28 13:01:23 2017 +0200

    xen/livepatch: Don't crash on encountering STN_UNDEF relocations
   
    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.
   
    Signed-off-by: Andrew Cooper <[hidden email]>
    Reviewed-by: Stefano Stabellini <[hidden email]>
    Reviewed-by: Konrad Rzeszutek Wilk <[hidden email]>
    Tested-by: Konrad Rzeszutek Wilk <[hidden email]> [x86 and arm32]
    Reviewed-by: Jan Beulich <[hidden email]>
    Reviewed-by: Ross Lagerwall <[hidden email]>
    master commit: 2ff229643b739e2fd0cd0536ee9fca506cfa92f8
    master date: 2017-06-23 15:00:37 +0100
---
 xen/arch/x86/livepatch.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/xen/arch/x86/livepatch.c b/xen/arch/x86/livepatch.c
index 1023fab..1ff52f3 100644
--- a/xen/arch/x86/livepatch.c
+++ b/xen/arch/x86/livepatch.c
@@ -140,12 +140,24 @@ int arch_livepatch_perform_rela(struct livepatch_elf *elf,
 
         symndx = ELF64_R_SYM(r->r_info);
 
-        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;
+        }
 
         dest = base->load_addr + r->r_offset;
         val = r->r_addend + elf->sym[symndx].sym->st_value;
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.7

_______________________________________________
Xen-changelog mailing list
[hidden email]
https://lists.xenproject.org/xen-changelog