powerpc/modules: Add REL24 relocation support of livepatch symbols
authorKamalesh Babulal <kamalesh@linux.vnet.ibm.com>
Tue, 14 Nov 2017 09:29:08 +0000 (04:29 -0500)
committerMichael Ellerman <mpe@ellerman.id.au>
Mon, 11 Dec 2017 02:03:28 +0000 (13:03 +1100)
Livepatch re-uses module loader function apply_relocate_add() to write
relocations, instead of managing them by arch-dependent
klp_write_module_reloc() function.

apply_relocate_add() doesn't understand livepatch symbols (marked with
SHN_LIVEPATCH symbol section index) and assumes them to be local
symbols by default for R_PPC64_REL24 relocation type. It fails with an
error, when trying to calculate offset with local_entry_offset():

  module_64: kpatch_meminfo: REL24 -1152921504897399800 out of range!

Whereas livepatch symbols are essentially SHN_UNDEF, should be called
via stub used for global calls. This issue can be fixed by teaching
apply_relocate_add() to handle both SHN_UNDEF/SHN_LIVEPATCH symbols
via the same stub. This patch extends SHN_UNDEF code to handle
livepatch symbols too.

Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/kernel/module_64.c

index 759104b99f9feb5940d186d0402ab5622e7ca347..1685b40f393514603ec15cf2c5b8fb8c5b1577b8 100644 (file)
@@ -614,7 +614,8 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
 
                case R_PPC_REL24:
                        /* FIXME: Handle weak symbols here --RR */
-                       if (sym->st_shndx == SHN_UNDEF) {
+                       if (sym->st_shndx == SHN_UNDEF ||
+                           sym->st_shndx == SHN_LIVEPATCH) {
                                /* External: go via stub */
                                value = stub_for_addr(sechdrs, value, me);
                                if (!value)