Skip to content

ios crash: EXC_BAD_ACCESS KERN_PROTECTION_FAILURE #63

@tomquas

Description

@tomquas

hi, we ran into the following issue on ios 15.8 phones:

          Crashed: com.apple.main-thread
0  UIKitCore                      0x4e8084 -[UIView(Internal) _presentationControllerToNotifyOnLayoutSubviews] + 242
1  UIKitCore                      0x201bfc __UIViewNoteTraitsDidChangeRecursively + 612
2  UIKitCore                      0x201bfc __UIViewNoteTraitsDidChangeRecursively + 612
3  UIKitCore                      0x201bfc __UIViewNoteTraitsDidChangeRecursively + 612
4  UIKitCore                      0x201bfc __UIViewNoteTraitsDidChangeRecursively + 612
5  UIKitCore                      0x201bfc __UIViewNoteTraitsDidChangeRecursively + 612
6  UIKitCore                      0x201bfc __UIViewNoteTraitsDidChangeRecursively + 612
7  UIKitCore                      0x201bfc __UIViewNoteTraitsDidChangeRecursively + 612
8  UIKitCore                      0x201bfc __UIViewNoteTraitsDidChangeRecursively + 612
9  UIKitCore                      0x201bfc __UIViewNoteTraitsDidChangeRecursively + 612
10 UIKitCore                      0x201bfc __UIViewNoteTraitsDidChangeRecursively + 612
11 UIKitCore                      0x499dd0 -[UIWindow _updateWindowTraitsAndNotify:] + 252
12 UIKitCore                      0x215ab4 ___UIWindowHostingScenePerformUpdateWithEffectiveSettings_block_invoke_3 + 60
13 UIKitCore                      0x2a34e4 -[UIWindowScene _enumerateWindowsIncludingInternalWindows:onlyVisibleWindows:asCopy:stopped:withBlock:] + 276
14 UIKitCore                      0x25995c ___UIWindowHostingScenePerformUpdateWithEffectiveSettings_block_invoke_2 + 260
15 UIKitCore                      0x1b2880 +[UIViewController _performWithoutDeferringTransitionsAllowingAnimation:actions:] + 156
16 UIKitCore                      0x20d1f8 ___UIWindowHostingScenePerformUpdateWithEffectiveSettings_block_invoke + 116
17 UIKitCore                      0x163274 +[UIView(Animation) performWithoutAnimation:] + 96
18 UIKitCore                      0x248b64 _UIWindowHostingScenePerformUpdateWithEffectiveSettings + 140
19 UIKitCore                      0x3df108 -[UIScene _guardedSetOverrideSettings:] + 156
20 UIKitCore                      0x3034c8 -[UIScene _applyOverrideSettings:forActions:] + 76
21 UIKitCore                      0xbed14 -[UIWindowScene _applySnapshotSettings:forActions:] + 44
22 UIKitCore                      0x66cf0c -[UIApplication _createSnapshotContextForScene:withName:performLayoutWithSettings:] + 388
23 UIKitCore                      0x264cec __65-[UIApplication _performSnapshotsWithAction:forScene:completion:]_block_invoke_3 + 124
24 FrontBoardServices             0xad9c -[FBSSceneSnapshotAction _executeNextRequest] + 256
25 FrontBoardServices             0xadf0 -[FBSSceneSnapshotAction _executeNextRequest] + 340
26 FrontBoardServices             0x4ca8 -[FBSSceneSnapshotAction executeRequestsWithHandler:completionHandler:expirationHandler:] + 288
27 UIKitCore                      0x2886c4 __65-[UIApplication _performSnapshotsWithAction:forScene:completion:]_block_invoke_2 + 280
28 UIKitCore                      0x50ad14 -[UIApplication _beginSnapshotSessionForScene:withSnapshotBlock:] + 988
29 UIKitCore                      0x5e345c __65-[UIApplication _performSnapshotsWithAction:forScene:completion:]_block_invoke + 132
30 UIKitCore                      0x288264 -[UIScene _enableOverrideSettingsForActions:] + 60
31 UIKitCore                      0x61fff4 -[UIScene _performSystemSnapshotWithActions:] + 120
32 UIKitCore                      0x5cfc08 -[UIApplication _performSnapshotsWithAction:forScene:completion:] + 308
33 UIKitCore                      0x3cba50 __98-[_UISceneSnapshotBSActionsHandler _respondToActions:forFBSScene:inUIScene:fromTransitionContext:]_block_invoke_3 + 168
34 UIKitCore                      0x28f7b8 __98-[_UISceneSnapshotBSActionsHandler _respondToActions:forFBSScene:inUIScene:fromTransitionContext:]_block_invoke_2 + 464
35 UIKitCore                      0x1cc8cc -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 664
36 UIKitCore                      0x20e4cc -[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 264
37 UIKitCore                      0x19ade8 -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] + 448
38 FrontBoardServices             0xc328 -[FBSScene updater:didUpdateSettings:withDiff:transitionContext:completion:] + 500
39 FrontBoardServices             0x2315c __94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke_2 + 124
40 FrontBoardServices             0x9bdc -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 232
41 FrontBoardServices             0xfa68 __94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke + 368
42 libdispatch.dylib              0x64094 _dispatch_client_callout + 16
43 libdispatch.dylib              0x7150 _dispatch_block_invoke_direct$VARIANT$mp + 220
44 FrontBoardServices             0xb2ac __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 40
45 FrontBoardServices             0xa7c0 -[FBSSerialQueue _targetQueue_performNextIfPossible] + 176
46 FrontBoardServices             0xe960 -[FBSSerialQueue _performNextFromRunLoopSource] + 24
47 CoreFoundation                 0xb3448 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
48 CoreFoundation                 0xc3578 __CFRunLoopDoSource0 + 204
49 CoreFoundation                 0x5734 __CFRunLoopDoSources0 + 256
50 CoreFoundation                 0xae08 __CFRunLoopRun + 768
51 CoreFoundation                 0x1e174 CFRunLoopRunSpecific + 572
52 GraphicsServices               0x1988 GSEventRunModal + 160
53 UIKitCore                      0x4e5a88 -[UIApplication _run] + 1080
54 UIKitCore                      0x27ef78 UIApplicationMain + 336
55 libswiftUIKit.dylib            0x27ee4 UIApplicationMain(_:_:_:_:) + 100
56 Runner                         0x4a24 main + 120 (AppDelegate.swift:120)
57 ???                            0x10dd684d0 (Missing)   

Summary: Root Cause Analysis Complete

The Culprit: secure_application Plugin

File: packages/secure_application/ios/Classes/SwiftSecureApplicationPlugin.swift:52-53

What Was Causing the iOS 15.8.2 Crash

The plugin had two fatal lines in applicationWillResignActive:
window.snapshotView(afterScreenUpdates: true) // Line 52 - triggers trait updates
RunLoop.current.run(until: Date(timeIntervalSinceNow:0.5)) // Line 53 - blocks for 500ms

The crash sequence:

User switches apps → iOS calls applicationWillResignActive
iOS starts its own snapshot process for app switcher (triggers trait collection update)
Plugin also triggers a snapshot with afterScreenUpdates: true (triggers another trait update)
Two simultaneous trait collection updates traverse the view hierarchy
They collide → infinite recursion in __UIViewNoteTraitsDidChangeRecursively
Stack overflow → crash at _presentationControllerToNotifyOnLayoutSubviews

Fixes Applied

✅ Removed the problematic snapshot code (lines 52-53)
The snapshot wasn't even being used (result discarded)
Blocking the run loop is terrible practice
Conflicts with iOS's native snapshot mechanism
✅ Fixed deprecated API usage
Replaced UIApplication.shared.windows with iOS 13+ compatible window retrieval
Applied to both applicationWillResignActive and unlock methods
✅ Improved error handling
Added proper guard clauses
Ensures background task always ends

Suggested Fix

See attached diff.
Credits: Claude Code.

ios-diff.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions