Repository navigation
fix(linux): protect the full memory range across page boundaries - #37
Merged
qubka merged 1 commit intoNov 1, 2026
Merged
Conversation
Include the first-page offset when calculating the aligned protection length. Otherwise, a trampoline crossing a page boundary can leave its last page non-executable and cause SIGSEGV. Preserve zero-length behavior and add regression coverage for crossing, aligned, exact-boundary, and zero-length ranges, including restoration. Signed-off-by: Mai Ooizumi <mai@imomoe.moe>
Member
|
Thanks @Mai-Ooizumi - clean fix, well explained. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes a bug in PolyHook2's Linux
PLH::MemAccessor::mem_protectimplementation where memory ranges that start at a non-page-aligned address and cross a page boundary fail to update protection flags on the trailing page.Root Cause
Previously,
mem_protectroundeddestdown to the nearest page boundary (aligned_dest), but roundedsizeup independently (MEMORY_ROUND_UP(size, pageSize)):When
desthas a large intra-page offset (e.g.,pageSize - 16) andsizeis small (e.g.,32bytes),[dest, dest + size)spans two pages, whereasMEMORY_ROUND_UP(size, pageSize)only equals1 * pageSize. As a result,mprotectonly updates the first page, leaving the second page of a trampoline or patched region without the requested protection (e.g., non-executable, causing aSIGSEGVwhen executed).Changes
patches/polyhook.patch(sources/MemAccessor.cpp): Include the intra-page offset (dest - aligned_dest) when rounding up the protection length, while preservingaligned_size = 0whensize == 0(used for querying current page protection):patches/polyhook.patch(UnitTests/linux/TestMemProtector.cpp): Add unit tests covering ranges that cross page boundaries, end exactly at a page boundary, start on a page boundary, and have zero length at an unaligned address, as well as verifying restoration of original protections.CMakeLists.txt: Wire up CTest (polyhook_mem_protect_tests) on Linux whenBUILD_TESTINGis enabled.