Document MemorySegment.reinterpret() as two-gate protected in process isolation model#120
Merged
pfirmstone merged 2 commits intocopilot/update-native-invocation-permissionfrom Apr 20, 2026
Conversation
Agent-Logs-Url: https://github.com/pfirmstone/DirtyChai/sessions/281deea7-ec7e-420d-99e7-cdf4e24aadbb Co-authored-by: pfirmstone <11625778+pfirmstone@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix security vulnerability in reinterpret method
Document Apr 20, 2026
MemorySegment.reinterpret() as two-gate protected in process isolation model
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.
PROCESS_ISOLATION.mdstill describedMemorySegment.reinterpret()as “module-system gate only” even after the runtime fix added aNativeInvocationPermissioncheck inAbstractMemorySegmentImpl.reinterpretInternal(). This update aligns the isolation documentation with the current two-gate enforcement model.Summary table correction
MemorySegment.reinterpret()row in “Summary — What the Guards Protect”:NativeInvocationPermission("reinterpret")+ moduleenableNativeAccess/ Blocked by DirtyChaiGate 1 scope update
MemorySegment.reinterpret(...)→AbstractMemorySegmentImpl.reinterpretInternal()to the Gate 1 entry-point table.Example (updated guard expression)
Original prompt
Analysis of the Fix
The code in
AbstractMemorySegmentImpl.reinterpretInternal()has been updated to add aNativeInvocationPermissionguard forMemorySegment.reinterpret()calls.What Was Fixed
Previously, the
reinterpret()method was only protected by the module system'senableNativeAccessflag, leaving it as a "Module-system gate only" vulnerability (as documented in PROCESS_ISOLATION.md line 635).The fix adds a SecurityManager permission check after the module system check:
This brings
MemorySegment.reinterpret()into compliance with DirtyChai's two-gate defence-in-depth model for native code access:Reflection.ensureNativeAccess()(JVM flag-based)NativeInvocationPermission(policy-auditable)What Needs Documentation Update
The PROCESS_ISOLATION.md document needs to be updated to reflect that this attack path is now "Blocked by DirtyChai" instead of "Module-system gate only".
Specifically, line 635 in the "Summary — What the Guards Protect" table must be updated to show the new status and the guard location:
Current (line 635):
Should become:
Additional context should also be added to describe how the two-gate model now covers this attack path, similar to the pattern documented for
SymbolLookupandSystemLookup.Files to Update
AbstractMemorySegmentImpl.reinterpretInternal()as a guarded entry pointThe following is the prior conversation context from the user's chat exploration (may be truncated):
User: This attack path, Untrusted jar uses MemorySegment.reinterpret() Module enableNativeAccess flag (no SM permission check) Module-system gate only, how effective is it?
Assistant: I'll analyze the security effectiveness of the module-system gate in the context of this attack path. Let me first examine the document you've referenced.
Assistant: Based on the document you've provided, I can analyze the effectiveness of the module-system gate against the
MemorySegment.reinterpret()attack path:The Gap: Module System Gate Only
According to the document (line 635), the attack path where untrusted code uses
MemorySegment.reinterpret()is:This is a residual vulnerability because:
Why This Is Concerning
No SecurityManager enforcement — The document explicitly states there is "no SM permission check" for
MemorySegment.reinterpret(). The only gate is the module system'senableNativeAccessflag.Module system gap in default mode — The module-system's three modes (lines 542–546) are:
ALLOW— no restrictionWARN— warning printed, access granted (default)DENY—IllegalCallerExceptionif module not listedIn the default
WARNmode, access is granted despite the warning.Untrusted code can reinterpret native memory — Via
MemorySegment.reinterpret(), untrusted code can:SymbolLookup/SymbolFindergates (which fire earlier in the chain)Effectiveness Analysis
The module-system gate is incomplete in isolation:
This pull request was created from Copilot chat.