GP-4758 Corrected ELF X86-64 GOT allocation bug. Added a few relocation

types.
This commit is contained in:
ghidra1
2024-07-08 18:57:31 -04:00
parent e5bd423ca5
commit 4658c4c6ca
2 changed files with 37 additions and 2 deletions
@@ -141,6 +141,13 @@ class X86_64_ElfRelocationContext extends ElfRelocationContext<X86_64_ElfRelocat
private 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;
@@ -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,