Repository navigation
Mark reviewed DeviceCheck methods safe - #869
LucaCappelletti94 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Thanks for working on this.
Same as with #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.
| # 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 |
There was a problem hiding this comment.
Am I misunderstanding? Isn't it DCAppAttestService.sharedService that should be unsafe, and the rest that are safe?
There was a problem hiding this comment.
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.
d5a94df to
6276b8d
Compare
|
The Apple report is FB25187723. The initializer would need to call an instance method as well, for example |
6276b8d to
cfedcc5
Compare
Enables the blanket safety defaults for
DeviceCheck, which makesDCDeviceand theDCAppAttestServiceinstance methods safe. Their completion handlers already take aSendableBlock, and on macOS 26.6.2 the token handler does run on a framework thread, so nothing more is needed there.DCAppAttestService::sharedServicestaysunsafe. Every instance method first goes through-[DCAppAttestService appAttestController], which creates its controller lazily with a plain load, store and release of the previous value, andsharedServicehands that one instance to every thread. CallingisSupportedfrom 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 fromnewis neitherSendnorSync, so its methods stay safe.App Attest only works on iOS and iPadOS, since
isSupportedanswersNOon a Mac. The iOS 26.1 decompilation shows the same lazy_appAttestControllergetter, while the iOS 18.2 one has no such ivar.Code that forbids
unsafestill cannot read the*mut NSDataand*mut NSErrorthese handlers receive until #837 lands.The regenerated bindings are in the generated fork.