-
Notifications
You must be signed in to change notification settings - Fork 291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pe: only process RelocDir->Size of reloc section #562
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,7 +87,7 @@ relocate_coff (PE_COFF_LOADER_IMAGE_CONTEXT *context, | |
/* RelocBaseEnd here is the address of the first entry /past/ the | ||
* table. */ | ||
RelocBaseEnd = ImageAddress(orig, size, Section->PointerToRawData + | ||
Section->Misc.VirtualSize); | ||
context->RelocDir->Size); | ||
|
||
if (!RelocBase && !RelocBaseEnd) | ||
return EFI_SUCCESS; | ||
|
@@ -741,7 +741,7 @@ read_header(void *data, unsigned int datasize, | |
context->NumberOfSections = PEHdr->Pe32.FileHeader.NumberOfSections; | ||
|
||
if (EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES < context->NumberOfRvaAndSizes) { | ||
perror(L"Image header too small\n"); | ||
perror(L"Image header too large\n"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated really - apologies if I'm misreading this? (Could make separate tiny PR; or remove, if the wording change does not seem right. Tyvm!) |
||
return EFI_UNSUPPORTED; | ||
} | ||
|
||
|
@@ -1277,8 +1277,11 @@ handle_image (void *data, unsigned int datasize, | |
Section->Misc.VirtualSize && | ||
base && end && | ||
RelocBase == base && | ||
RelocBaseEnd == end) { | ||
RelocBaseEnd <= end) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without this change, the file loads but crashes (since shim will attempt to use the file as if there is no reloc section). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, Thanks for this input. Is BS->FreePages correct, here? The various other (pre-existing) Then on to the general idea, yes, in the current version of this PR the code continues if no reloc section is finally found (because this is what the code previously did), but the correct place to decide not to do so (which I tend to agree would be an improvement) would be around line 1331: If you (possibly) meant the suggestion as an alternative fix - i.e. to avoid my crash - then I think that misunderstands the nature of the PR - the file should load and run (not abort, and also - ofc - not crash) and this PR allows it to load. |
||
RelocSection = Section; | ||
} else { | ||
perror(L"Relocation section is invalid \n"); | ||
return EFI_UNSUPPORTED; | ||
Comment on lines
+1283
to
+1284
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest in the case where a reloc section is found but rejected, aborting with an error such as this is helpful (unless there are known cases where ignore and continue behaviour is required?). |
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once the test is modifed to accept the .reloc section, we also have to process only the used size.