Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before this commit, the
.CRT
section (which contains pointers to image TLS callbacks) and the.idata
section (which contains__imp_
pointers to dllimport functions) that had been created by the GNU linker were writeable.As these function pointers are essential for programs to be functional, they could be exploited to inject malicious code, like the well-known IFUNC backdoor in XZ Utils. The Microsoft linker does not create these sections as writeable; instead, they seem to be merged into
.rdata
and are not modifiable, unless unprotected.LLD also does the same, suggesting these sections be merged into
.rdata
: https://github.com/llvm/llvm-project/blob/ebeb56af5f8f1ff9da8f5a7e98348f460d223de1/lld/COFF/Driver.cpp#L2034-L2048This commit includes the following countermeasures:
.CRT
and.idata
sections (if any) will not be writeable in the final image..CRT
, as well as.ctors
and.dtors
(which were merged into.text
instead), into.rdata
. Merging.idata
into.rdata
seems to prevent dllimport from working, so there's still an.idata
section in the final image. See also: https://stackoverflow.com/questions/22651433/pe-idata-sectionReference: https://sourceware.org/bugzilla/show_bug.cgi?id=32264