Bug 214965

Summary: [iOS] Issue a temporary extension to the MobileGestalt daemon when the MobileGestalt cache is invalid
Product: WebKit Reporter: Per Arne Vollan <pvollan>
Component: WebKit Misc.Assignee: Per Arne Vollan <pvollan>
Status: RESOLVED FIXED    
Severity: Normal CC: bfulgham, darin, ggaren, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch
ggaren: review+
Patch
none
Patch none

Description Per Arne Vollan 2020-07-30 07:01:44 PDT
When the MobileGestalt cache is invalid, some MG queries will fail in the WebContent process, since it has no access to the daemon. This can be fixed by issuing a temporary extension to the daemon, and having the WebContent process query all relevant MG values while holding the extension. This will bring the values into the in-memory cache, which will be valid after the extension to the daemon has been revoked.
Comment 1 Per Arne Vollan 2020-07-30 07:17:05 PDT
Created attachment 405567 [details]
Patch
Comment 2 Per Arne Vollan 2020-07-30 09:59:45 PDT
Created attachment 405584 [details]
Patch
Comment 3 Per Arne Vollan 2020-07-30 10:04:05 PDT
Created attachment 405585 [details]
Patch
Comment 4 Per Arne Vollan 2020-07-30 10:19:02 PDT
Created attachment 405587 [details]
Patch
Comment 5 Geoffrey Garen 2020-07-30 10:55:20 PDT
Comment on attachment 405587 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=405587&action=review

> Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm:206
> +#if PLATFORM(IOS_FAMILY) && !PLATFORM(MACCATALYST)

Does this code need to be platform conditional? If it doesn't need to be platform conditional, I'd suggest making it unconditional.

From the perspective of the WebContent process, it's a better separation of concerns to honor the sandbox extension whenever it is present, regardless of why the UI process issued it. For one thing, the alternative risks issuing an extension and never revoking it!
Comment 6 Per Arne Vollan 2020-07-30 12:06:05 PDT
(In reply to Geoffrey Garen from comment #5)
> Comment on attachment 405587 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=405587&action=review
> 
> > Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm:206
> > +#if PLATFORM(IOS_FAMILY) && !PLATFORM(MACCATALYST)
> 
> Does this code need to be platform conditional? If it doesn't need to be
> platform conditional, I'd suggest making it unconditional.
> 
> From the perspective of the WebContent process, it's a better separation of
> concerns to honor the sandbox extension whenever it is present, regardless
> of why the UI process issued it. For one thing, the alternative risks
> issuing an extension and never revoking it!

That's a good point. In this case, I think this is only relevant on iOS, watchOS, and tvOS, since I believe MobileGestalt is not present elsewhere.

Thanks for reviewing!
Comment 7 Geoffrey Garen 2020-07-30 12:10:44 PDT
Comment on attachment 405587 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=405587&action=review

>>> Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm:206
>>> +#if PLATFORM(IOS_FAMILY) && !PLATFORM(MACCATALYST)
>> 
>> Does this code need to be platform conditional? If it doesn't need to be platform conditional, I'd suggest making it unconditional.
>> 
>> From the perspective of the WebContent process, it's a better separation of concerns to honor the sandbox extension whenever it is present, regardless of why the UI process issued it. For one thing, the alternative risks issuing an extension and never revoking it!
> 
> That's a good point. In this case, I think this is only relevant on iOS, watchOS, and tvOS, since I believe MobileGestalt is not present elsewhere.
> 
> Thanks for reviewing!

How about if we make the calls to MG conditional on platform, but we make the check and consumption of the extension handle cross-platform (by tightening the scope of the #if)?
Comment 8 Per Arne Vollan 2020-07-30 12:34:20 PDT
(In reply to Geoffrey Garen from comment #7)
> Comment on attachment 405587 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=405587&action=review
> 
> >>> Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm:206
> >>> +#if PLATFORM(IOS_FAMILY) && !PLATFORM(MACCATALYST)
> >> 
> >> Does this code need to be platform conditional? If it doesn't need to be platform conditional, I'd suggest making it unconditional.
> >> 
> >> From the perspective of the WebContent process, it's a better separation of concerns to honor the sandbox extension whenever it is present, regardless of why the UI process issued it. For one thing, the alternative risks issuing an extension and never revoking it!
> > 
> > That's a good point. In this case, I think this is only relevant on iOS, watchOS, and tvOS, since I believe MobileGestalt is not present elsewhere.
> > 
> > Thanks for reviewing!
> 
> How about if we make the calls to MG conditional on platform, but we make
> the check and consumption of the extension handle cross-platform (by
> tightening the scope of the #if)?

Sounds good, will fix!

Thanks for reviewing!
Comment 9 Per Arne Vollan 2020-07-30 13:05:05 PDT
Created attachment 405600 [details]
Patch
Comment 10 Geoffrey Garen 2020-07-30 13:37:00 PDT
Comment on attachment 405600 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=405600&action=review

r=me

> Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm:206
> +        auto extension = SandboxExtension::create(WTFMove(*parameters.mobileGestaltExtensionHandle));
> +        if (extension) {

You can merge these two lines as "if (auto extension = ....)".
Comment 11 Per Arne Vollan 2020-07-30 13:40:14 PDT
(In reply to Geoffrey Garen from comment #10)
> Comment on attachment 405600 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=405600&action=review
> 
> r=me
> 
> > Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm:206
> > +        auto extension = SandboxExtension::create(WTFMove(*parameters.mobileGestaltExtensionHandle));
> > +        if (extension) {
> 
> You can merge these two lines as "if (auto extension = ....)".

Great, will do!

Thank you!
Comment 12 Per Arne Vollan 2020-07-30 14:00:57 PDT
rdar://problem/66183188
Comment 13 Per Arne Vollan 2020-07-30 14:10:52 PDT
Created attachment 405616 [details]
Patch
Comment 14 Per Arne Vollan 2020-07-31 06:36:32 PDT
Created attachment 405685 [details]
Patch
Comment 15 EWS 2020-07-31 07:03:39 PDT
Committed r265139: <https://trac.webkit.org/changeset/265139>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 405685 [details].
Comment 16 Darin Adler 2020-08-04 14:26:34 PDT
Comment on attachment 405600 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=405600&action=review

> Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm:209
> +#if PLATFORM(IOS_FAMILY) && !PLATFORM(MACCATALYST)

This needs a comment. I believe it’s trying to ask all the questions that need correct answers from everything that runs inside the sandbox. The comment should say what should and should not be on the list and how it was generated.

I often discourage comments that say *what* something is doing, but we really need comments that say *why*!
Comment 17 Per Arne Vollan 2020-08-04 15:43:47 PDT
(In reply to Darin Adler from comment #16)
> Comment on attachment 405600 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=405600&action=review
> 
> > Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm:209
> > +#if PLATFORM(IOS_FAMILY) && !PLATFORM(MACCATALYST)
> 
> This needs a comment. I believe it’s trying to ask all the questions that
> need correct answers from everything that runs inside the sandbox. The
> comment should say what should and should not be on the list and how it was
> generated.
> 
> I often discourage comments that say *what* something is doing, but we
> really need comments that say *why*!

That is a good point. I will add a comment to this code.

Thanks for reviewing!
Comment 18 Per Arne Vollan 2020-08-04 16:13:07 PDT
(In reply to Darin Adler from comment #16)
> Comment on attachment 405600 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=405600&action=review
> 
> > Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm:209
> > +#if PLATFORM(IOS_FAMILY) && !PLATFORM(MACCATALYST)
> 
> This needs a comment. I believe it’s trying to ask all the questions that
> need correct answers from everything that runs inside the sandbox. The
> comment should say what should and should not be on the list and how it was
> generated.
> 
> I often discourage comments that say *what* something is doing, but we
> really need comments that say *why*!

Added comment in <https://trac.webkit.org/changeset/265267/webkit>.