Ghidra is a software reverse engineering (SRE) framework
GP-4758 Corrected ELF X86-64 GOT allocation bug. Added a few relocation types.
ghidra14658c4c6ca40
diff --git a/Ghidra/Processors/x86/src/main/java/ghidra/app/util/bin/format/elf/relocation/X86_64_ElfRelocationContext.java b/Ghidra/Processors/x86/src/main/java/ghidra/app/util/bin/format/elf/relocation/X86_64_ElfRelocationContext.javaindex eae466cde5..b93435c7df 100644--- a/Ghidra/Processors/x86/src/main/java/ghidra/app/util/bin/format/elf/relocation/X86_64_ElfRelocationContext.java+++ b/Ghidra/Processors/x86/src/main/java/ghidra/app/util/bin/format/elf/relocation/X86_64_ElfRelocationContext.java@@ -141,6 +141,13 @@ class X86_64_ElfRelocationContext extends ElfRelocationContext<X86_64_ElfRelocatprivate Address allocateGot() {+ if (allocatedGotAddress != null) {+ if (allocatedGotAddress == Address.NO_ADDRESS) {+ return null;+ }+ return allocatedGotAddress;+ }+allocatedGotAddress = Address.NO_ADDRESS;nextAllocatedGotEntryAddress = Address.NO_ADDRESS;@@ -193,7 +200,9 @@ class X86_64_ElfRelocationContext extends ElfRelocationContext<X86_64_ElfRelocat*/private Address getNextAllocatedGotEntryAddress() {if (nextAllocatedGotEntryAddress == null) {- allocateGot();+ if (allocateGot() == null) {+ return Address.NO_ADDRESS; // failed to allocate got+ }}Address addr = nextAllocatedGotEntryAddress;diff --git a/Ghidra/Processors/x86/src/main/java/ghidra/app/util/bin/format/elf/relocation/X86_64_ElfRelocationHandler.java b/Ghidra/Processors/x86/src/main/java/ghidra/app/util/bin/format/elf/relocation/X86_64_ElfRelocationHandler.javaindex f7a0809bb1..20be2c3716 100644--- a/Ghidra/Processors/x86/src/main/java/ghidra/app/util/bin/format/elf/relocation/X86_64_ElfRelocationHandler.java+++ b/Ghidra/Processors/x86/src/main/java/ghidra/app/util/bin/format/elf/relocation/X86_64_ElfRelocationHandler.java@@ -134,7 +134,7 @@ public class X86_64_ElfRelocationHandler extends}catch (NotFoundException e) {markAsError(program, relocationAddress, type, symbolName, symbolIndex,- e.getMessage(), elfRelocationContext.getLog());+ "GOT allocation failure", elfRelocationContext.getLog());return RelocationResult.FAILURE;}break;@@ -257,6 +257,32 @@ public class X86_64_ElfRelocationHandler extends}value = symbolGotAddress.getOffset() + addend - offset;memory.setLong(relocationAddress, value);+ break;++ case R_X86_64_GOT64: // 64 bit GOT entry offset (UNVERIFIED)+ symbolGotAddress = elfRelocationContext.getGotEntryAddress(sym);+ if (symbolGotAddress == null) {+ markAsError(program, relocationAddress, type, symbolName, symbolIndex,+ "GOT allocation failure", elfRelocationContext.getLog());+ return RelocationResult.FAILURE;+ }+ value = symbolGotAddress.getOffset() + addend;+ memory.setLong(relocationAddress, value);+ break;++ case R_X86_64_PLTOFF64: // 64 bit GOT relative offset to PLT entry (UNVERIFIED)+ long dotgot;+ try {+ dotgot = elfRelocationContext.getGOTValue();+ }+ catch (NotFoundException e) {+ markAsError(program, relocationAddress, type, symbolName, symbolIndex,+ "GOT allocation failure", elfRelocationContext.getLog());+ return RelocationResult.FAILURE;+ }+ value = symbolValue - dotgot + addend;+ memory.setLong(relocationAddress, value);+ break;case R_X86_64_RELATIVE:// word64 for LP64 and specifies word32 for ILP32,