Skip to content

Commit 10038d0

Browse files
committed
[RuntimeDyld] Fixed buffer overflows with absolute symbols
Differential Revision: https://reviews.llvm.org/D95596
1 parent cedfa38 commit 10038d0

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ void RuntimeDyldImpl::resolveLocalRelocations() {
146146
// The Section here (Sections[i]) refers to the section in which the
147147
// symbol for the relocation is located. The SectionID in the relocation
148148
// entry provides the section to which the relocation will be applied.
149-
int Idx = it->first;
150-
uint64_t Addr = Sections[Idx].getLoadAddress();
149+
unsigned Idx = it->first;
150+
uint64_t Addr = getSectionLoadAddress(Idx);
151151
LLVM_DEBUG(dbgs() << "Resolving relocations Section #" << Idx << "\t"
152152
<< format("%p", (uintptr_t)Addr) << "\n");
153153
resolveRelocationList(it->second, Addr);
@@ -1077,7 +1077,8 @@ void RuntimeDyldImpl::resolveRelocationList(const RelocationList &Relocs,
10771077
for (unsigned i = 0, e = Relocs.size(); i != e; ++i) {
10781078
const RelocationEntry &RE = Relocs[i];
10791079
// Ignore relocations for sections that were not loaded
1080-
if (Sections[RE.SectionID].getAddress() == nullptr)
1080+
if (RE.SectionID != AbsoluteSymbolSection &&
1081+
Sections[RE.SectionID].getAddress() == nullptr)
10811082
continue;
10821083
resolveRelocation(RE, Value);
10831084
}

llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -462,16 +462,26 @@ class RuntimeDyldImpl {
462462
loadObject(const object::ObjectFile &Obj) = 0;
463463

464464
uint64_t getSectionLoadAddress(unsigned SectionID) const {
465-
return Sections[SectionID].getLoadAddress();
465+
if (SectionID == AbsoluteSymbolSection)
466+
return 0;
467+
else
468+
return Sections[SectionID].getLoadAddress();
466469
}
467470

468471
uint8_t *getSectionAddress(unsigned SectionID) const {
469-
return Sections[SectionID].getAddress();
472+
if (SectionID == AbsoluteSymbolSection)
473+
return nullptr;
474+
else
475+
return Sections[SectionID].getAddress();
470476
}
471477

472478
StringRef getSectionContent(unsigned SectionID) const {
473-
return StringRef(reinterpret_cast<char *>(Sections[SectionID].getAddress()),
474-
Sections[SectionID].getStubOffset() + getMaxStubSize());
479+
if (SectionID == AbsoluteSymbolSection)
480+
return {};
481+
else
482+
return StringRef(
483+
reinterpret_cast<char *>(Sections[SectionID].getAddress()),
484+
Sections[SectionID].getStubOffset() + getMaxStubSize());
475485
}
476486

477487
uint8_t* getSymbolLocalAddress(StringRef Name) const {
@@ -519,9 +529,7 @@ class RuntimeDyldImpl {
519529

520530
for (auto &KV : GlobalSymbolTable) {
521531
auto SectionID = KV.second.getSectionID();
522-
uint64_t SectionAddr = 0;
523-
if (SectionID != AbsoluteSymbolSection)
524-
SectionAddr = getSectionLoadAddress(SectionID);
532+
uint64_t SectionAddr = getSectionLoadAddress(SectionID);
525533
Result[KV.first()] =
526534
JITEvaluatedSymbol(SectionAddr + KV.second.getOffset(), KV.second.getFlags());
527535
}

0 commit comments

Comments
 (0)