From 9a8faad50f56d748fcd1498c170797c67bb53217 Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Wed, 22 Oct 2025 19:52:19 -0700 Subject: [KernelCache] Set segment permissions based on how XNU initially maps 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. --- view/kernelcache/core/MachOProcessor.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'view/kernelcache/core/MachOProcessor.cpp') diff --git a/view/kernelcache/core/MachOProcessor.cpp b/view/kernelcache/core/MachOProcessor.cpp index 42faba24..fb3d2b27 100644 --- a/view/kernelcache/core/MachOProcessor.cpp +++ b/view/kernelcache/core/MachOProcessor.cpp @@ -193,8 +193,9 @@ uint64_t KernelCacheMachOProcessor::ApplyHeaderSections(KernelCacheMachOHeader& semantics = ReadWriteDataSectionSemantics; if (strncmp(section.sectname, "__auth_got", sizeof(section.sectname)) == 0) semantics = ReadOnlyDataSectionSemantics; - if (strncmp(section.segname, "__DATA_CONST", sizeof(section.segname)) == 0) - semantics = ReadOnlyDataSectionSemantics; + + if (auto overriddenSemantics = SectionSemanticsForSection(section)) + semantics = static_cast(overriddenSemantics); // Typically a view would add auto sections but those won't persist when loading the BNDB. // if we want to use an auto section here we would need to allow the core to apply auto sections from the database. -- cgit v1.3.1