[ELFLOADER] handle PT_LOAD host-page overlaps on NON4KPAGE hosts#3657
[ELFLOADER] handle PT_LOAD host-page overlaps on NON4KPAGE hosts#3657yzewei wants to merge 1 commit intoptitSeb:mainfrom
Conversation
|
Additional note: deferred mprotect cannot resolve this issue; it cannot recover the overwritten EXEC statements. |
|
Hi, I just only fixed one NON4KPAGE issue I often confused by other NON4KPAGE issues https://github.com/ptitSeb/box64/issues?q=NON4KPAGE so I just reviewed the patch and asked @yzewei (might not related) question: what if RFC to other NON4KPAGE hunters. Thanks, |
|
@runlevel5 I've modified the logic here; could you please review it and see if there are any potential negative impacts? |
|
I am a bit concerned there might be possible regression for 4K pagesize system with unconditional |
|
@yzewei @xiangzhai please test on 4K-pag systems to confirm no regressions (the |
Yes, that's correct. Because of the unified final protection process, 4K hosts will now also undergo the same final recalculation step. Therefore, this may introduce an additional The purpose of this approach is to unify the final protection model for 4K and non-4K hosts and to stop relying on the old It only happens during ELF loading, not during stable execution, so the performance impact should be minimal. |
Agreed. 4K regression testing is indeed necessary. I've only reproduced and verified the non-4K scenario locally so far. However, I don't have a suitable 4K page environment on hand. Could you please help me verify it? Thank you very much! |
Signed-off-by: Zewei Yang <yangzewei@loongson.cn>
I tested on ARM64 4k and 16k, the ctest all passed and |
Thanks! |
|
@ptitSeb What are your thoughts on this? |
|
I need to think about it, ELF Loader is quite brittle for now. |
Problem
On non-4K page systems, it's possible for adjacent
PT_LOADsegments in x86_64 ELF to fall into the same host page.For example, in an x86 Node.js application, there might be a situation where an
R|Xsegment and an adjacentRsegment share the same 16K page.Under the current logic, inconsistencies between host page permissions and segment-level permissions occur during loading, ultimately leading to SIGSGEV.
Solution Modification
For this type of shared host page situation: adopt a permission stacking strategy.
Modifications
Main Changes:
Added a local helper for host page scope and ELF flags to host
PROT_*On NON4K page systems, added
ElfPhdrNeedsCopyLoad64()checks:Force copy-load if the current
PT_LOADdoes not completely cover the host page.Force copy-load if the host page covered by the current
PT_LOADoverlaps with otherPT_LOADs.Retain the original mmap fast path, but only for segments that "completely cover the host page and do not share the host page with other
PT_LOAD".After all segments are loaded, recalculate the final permission union by host page and uniformly execute
mprotect.Impact
For 4K page systems, existing paths remain unchanged.
For NON4K page systems, only insecure
PT_LOADs will revert to copy-load; the original fast path will still be preserved as much as possible. ## VerificationI verified the following issue locally:
node --versionon the LoongArch big page system has been fixed.