Merge pull request #15441 from hrydgard/modinfoaddr-errorcheck

Add a check to the elf loader, preventing a crash on bad module info addr
This commit is contained in:
Unknown W. Brackets 2022-03-13 15:55:42 -07:00 committed by GitHub
commit 97bc7a1ae3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1285,10 +1285,26 @@ static PSPModule *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 load
SectionID sceModuleInfoSection = reader.GetSectionByName(".rodata.sceModuleInfo");
PspModuleInfo *modinfo;
u32 modinfoaddr;
if (sceModuleInfoSection != -1)
modinfo = (PspModuleInfo *)Memory::GetPointer(reader.GetSectionAddr(sceModuleInfoSection));
modinfoaddr = reader.GetSectionAddr(sceModuleInfoSection);
else
modinfo = (PspModuleInfo *)Memory::GetPointer(reader.GetSegmentVaddr(0) + (reader.GetSegmentPaddr(0) & 0x7FFFFFFF) - reader.GetSegmentOffset(0));
modinfoaddr = reader.GetSegmentVaddr(0) + (reader.GetSegmentPaddr(0) & 0x7FFFFFFF) - reader.GetSegmentOffset(0);
if (!Memory::IsValidAddress(modinfoaddr)) {
*error_string = StringFromFormat("Bad module info address %08x", modinfoaddr);
ERROR_LOG(SCEMODULE, "Bad module info address %08x", modinfoaddr);
if (newptr)
delete[] newptr;
module->Cleanup();
kernelObjects.Destroy<PSPModule>(module->GetUID());
error = SCE_KERNEL_ERROR_BAD_FILE; // Probably not the right error code.
return nullptr;
}
modinfo = (PspModuleInfo *)Memory::GetPointer(modinfoaddr);
module->nm.nsegment = reader.GetNumSegments();
module->nm.attribute = modinfo->moduleAttrs;