Reporting Issues
Bug 3328 - DxeCore: PE code section protection uses raw file size
Summary: DxeCore: PE code section protection uses raw file size
Status: RESOLVED WONTFIX
Alias: None
Product: EDK2
Classification: Unclassified
Component: Code (show other bugs)
Version: Current
Hardware: All All
: Lowest normal
Assignee: gaoliming
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-04-12 11:21 UTC by Marvin Häuser
Modified: 2024-03-06 13:15 UTC (History)
12 users (show)

See Also:
EDK II Code First industry standard specifications: ---
Branch URL:
Release(s) the issue is observed: EDK II Master
The OS the target platform is running: ---
Package: MdeModulePkg
Release(s) the issues must be fixed: EDK II Master
Tianocore documents:


Attachments
suggested patch (1.83 KB, patch)
2023-02-22 10:57 UTC, Gerd Hoffmann
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Marvin Häuser 2021-04-12 11:21:46 UTC
PE/COFF image sections have two sizes, the "raw" size (i.e. the size section data occupies in a stored file) and "virtual" size (i.e. the size section data occupies in a loaded image). There is no strict relation between them, i.e. raw size can be lesser than, equal to, or greater than virtual size. As memory protection always works on loaded images, virtual size needs to be used to ensure adequate permissions. Yet, the current code uses the raw file size[1].

[1] https://github.com/tianocore/edk2/blob/2072c22a0d63c780b0cc6377f6d4ffb116ad6144/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c#L528
Comment 1 John Mathews 2021-05-05 14:31:54 UTC
Moving this to CONFIRMED, per discussion in the 5/5 Infosec meeting.
Comment 2 Gerd Hoffmann 2023-02-22 10:57:00 UTC
Created attachment 1332 [details]
suggested patch

Simple one-line fix, not applied for almost two years.
May I ask what the heck you are waiting for?
Comment 3 Marvin Häuser 2023-02-22 11:24:51 UTC
Sorry Gerd, not terribly interested in working on this code. Applying red tape could fool people into believing it’s adequate afterwards. :)
Comment 4 Gerd Hoffmann 2023-02-23 02:34:02 UTC
(In reply to Marvin Häuser from comment #3)
> Sorry Gerd, not terribly interested in working on this code.

Oh, that question was directed to bug assignee and SecurityPkg maintainer.
Caring about bugs, especially security bugs, is their duty IMHO.

Bug reporter also providing fixes is a nice-to-have,
but certainly not required.

> Applying red tape could fool people into believing it’s adequate afterwards. :)

Yea, no doubt there is more, looking at the list of open security bugs there are multiple PE-related ones and I have my doubts that this is complete.

I guess your recommendation is to swap the complete image loader instead?
Comment 5 Marvin Häuser 2023-02-23 04:55:33 UTC
Actually both interpretations are valid. While replacing the image loader also basically is mandatory - I got a “we don’t care about the details, just give us literally anything else” from multiple core contributors back then -, this sub-code in particular is its own design defect. Basically the notion of PE section permissions is ignored entirely and a heuristic is applied to divide the image into code (RX) and data (RW) segments, with no support for configurations like RNX whatsoever. I don’t remember the other issues with it, but I’m pretty sure there were more.

But yes, my image loader replacement proposal did fix this implicitly and is now maintained in a downstream fork, fixing this BZ, most of my other BZs, and more at: https://github.com/acidanthera/audk

Mainlining it was shelved after an uncontroversial no-op (w.r.t. the compiled result) patch with prerequisites was not merged after extensive discussion, one R-b, a ping by me, a ping by a colleague, and a real-world toolchain bug it was able to discover via the STATIC_ASSERTs (which also had its fix ignored at the time): https://edk2.groups.io/g/devel/topic/84909448

Please just unembargo and mark as WONTFIX.
Comment 6 John Mathews 2024-03-06 13:15:57 UTC
As recommended by Marvin, unembargo and mark as WONTFIX.