← Back to Pull requests

Mark reviewed DeviceCheck methods safe #869

Open
LucaCappelletti94 opened this pull request with 10 lines diff across 3 files
View on GitHub
LucaCappelletti94 LucaCappelletti94 commented on Oct 06, 2026 04:05 UTC
Author

Enables the blanket safety defaults for DeviceCheck, which makes DCDevice and the DCAppAttestService instance methods safe. Their completion handlers already take a SendableBlock, and on macOS 26.6.2 the token handler does run on a framework thread, so nothing more is needed there.

DCAppAttestService::sharedService stays unsafe. Every instance method first goes through -[DCAppAttestService appAttestController], which creates its controller lazily with a plain load, store and release of the previous value, and sharedService hands that one instance to every thread. Calling isSupported from eight threads on a fresh instance crashes within a thousand rounds on macOS 15.7.9, 26.6.2 and 27.0.1, while the same harness with the controller created beforehand runs cleanly (FB25187723). An instance from new is neither Send nor Sync, so its methods stay safe.

App Attest only works on iOS and iPadOS, since isSupported answers NO on a Mac. The iOS 26.1 decompilation shows the same lazy _appAttestController getter, while the iOS 18.2 one has no such ivar.

Code that forbids unsafe still cannot read the mut NSData and mut NSError these handlers receive until #837 lands.

The regenerated bindings are in the generated fork.

Diff: 10 lines (+9 / -1) across 3 files Reviewer: madsmtm Review duration: 13663m
All Vouch review confidence checks passed
Residual risk 0.02 = Change Risk (0.20) × (1 − Review Confidence (0.88)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.20 · 10 lines diff across 3 files
0.20
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.91 · 3 substantive comment(s)
0.91
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
87%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.143
Real PR Conversation Timeline
5 items
madsmtm madsmtm commented on code on Oct 11, 2026 13:52 UTC
Code Review
framework-crates/objc2-device-check/translation-config.toml:1
@@ -7,3 +7,13 @@ ios = "11.0"
 tvos = "11.0"
 watchos = "9.0"
 visionos = "1.0"
+
+unsafe-default-safety.documentation-is-reviewed = true
+unsafe-default-safety.bounds-checked-internally = true
+
+# The first call lazily creates the service's controller with an unsynchronized
+# load and store, so it must not race another call on the same instance.
+class.DCAppAttestService.methods.isSupported.unsafe = true

Am I misunderstanding? Isn't it DCAppAttestService.sharedService that should be unsafe, and the rest that are safe?

madsmtm madsmtm commented on Oct 11, 2026 13:55 UTC
Reviewer

Thanks for working on this.

Same as with https://github.com/madsmtm/objc2/pull/864, could I get you to file a FB with Apple about this?

---

Surprisingly, we probably _could_ work around this by adding this to lib.rs:

// #[ctor]
#[used]
#[link_section = "__DATA,__mod_init_func,mod_init_funcs"]
static INIT: extern "C" fn() = {
    extern "C" fn init() {
        let service = DCAppAttestService::sharedService();
        service.isSupported();
        service.xyz();
    }
    init
};

Not sure how good of an idea this would be though, since the user could (very theoretically) still end up in a situation where they themselves spawn threads and use DCAppAttestService from a ctor that runs before this one, so I'd prefer to wait with doing that until we hear from Apple.

LucaCappelletti94 LucaCappelletti94 commented on code on Oct 14, 2026 21:11 UTC
Code Review
framework-crates/objc2-device-check/translation-config.toml:1
@@ -7,3 +7,13 @@ ios = "11.0"
 tvos = "11.0"
 watchos = "9.0"
 visionos = "1.0"
+
+unsafe-default-safety.documentation-is-reviewed = true
+unsafe-default-safety.bounds-checked-internally = true
+
+# The first call lazily creates the service's controller with an unsynchronized
+# load and store, so it must not race another call on the same instance.
+class.DCAppAttestService.methods.isSupported.unsafe = true

sharedService is the unsafe one now, and the four instance methods together with new and init are safe. DCAppAttestService is neither Send nor Sync, so an instance from new stays on one thread, and only sharedService can hand the same instance to several threads.

LucaCappelletti94 LucaCappelletti94 commented on Oct 14, 2026 21:11 UTC
Author

The Apple report is FB25187723.

The initializer would need to call an instance method as well, for example DCAppAttestService::sharedService().isSupported(). sharedService itself is already guarded by dispatch_once, and the race is in the controller that the first instance method call creates.

Reviewers
Assignees
LucaCappelletti94 LucaCappelletti94
Labels
risk: low confidence: 87.8% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 20.3% (LOW) · Higher = larger blast radius
20.3%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 87.8% · Lower = rushed or shallow review
87.8%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 2.5% · Safe to merge
2.5%
Repository