Skip to content

[KernelCache] Set segment flags based on how XNU initially maps them#7519

Merged
bdash merged 1 commit intodevfrom
test_kc_segment_perms
Oct 23, 2025
Merged

[KernelCache] Set segment flags based on how XNU initially maps them#7519
bdash merged 1 commit intodevfrom
test_kc_segment_perms

Conversation

@bdash
Copy link
Contributor

@bdash bdash commented Oct 23, 2025

XNU maps kernel cache segments in with different permissions than the load commands indicate. For instance, __DATA_CONST is initially mapped as read-write before later being re-mapped as read-only. Treating it as read-only results in analysis falsely assuming that global variables cannot change.

To work around this we maintain a mapping from segment name to initial permissions (i.e., most lax permissions) and favor them over permissions derived from the segment load command. Section semantics are also derived from the segment's permissions when the segment is present in the mapping.

The mapping is based on the initial permissions established by arm_vm_prot_init within the XNU source.

Related to #6718.

… them

XNU maps kernel cache segments in with different permissions than the
load commands indicate. For instance, `__DATA_CONST` is initially mapped
as read-write before later being re-mapped as read-only. Treating it as
read-only results in analysis falsely assuming that global variables
cannot change.

To work around this we maintain a mapping from segment name to initial
permissions (i.e., most lax permissions) and favor them over permissions
derived from the segment load command. Section semantics are also
derived from the segment's permissions when the segment is present in
the mapping.

The mapping is based on the initial permissions established by
`arm_vm_prot_init` within the XNU source.
@bdash bdash force-pushed the test_kc_segment_perms branch from cb6e021 to 9a8faad Compare October 23, 2025 20:34
@bdash bdash merged commit 9a8faad into dev Oct 23, 2025
5 checks passed
@bdash bdash deleted the test_kc_segment_perms branch October 23, 2025 20:40
@emesare emesare added this to the Io milestone Nov 11, 2025
bdash added a commit that referenced this pull request Jan 28, 2026
…y maps them

This was done for kernel cache in
#7519, and is now being
extended to Mach-O images that appear to be XNU kernels (that is, they
contain `__KLD` segments). This improves the experience when opening
kernels from the macOS Kernel Debug Kit.
bdash added a commit that referenced this pull request Feb 2, 2026
…y maps them

This was done for kernel cache in
#7519, and is now being
extended to Mach-O images that appear to be XNU kernels (that is, they
contain `__KLD` segments). This improves the experience when opening
kernels from the macOS Kernel Debug Kit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants