Bug 211254

Summary: [iOS] Unable to take RunningBoard process assertions in the iOS Simulator
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: WebKit2Assignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: aestes, ap, bfulgham, ddkilzer, ggaren, keith_miller, krollin, mitz, thorton, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=211392
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch none

Description Chris Dumez 2020-04-30 14:21:19 PDT
Unable to take RunningBoard process assertions in the iOS Simulator due to a missing entitlement.
Comment 1 Radar WebKit Bug Importer 2020-04-30 14:21:34 PDT
<rdar://problem/62674074>
Comment 2 Chris Dumez 2020-04-30 14:25:59 PDT
Created attachment 398092 [details]
Patch
Comment 3 Alexey Proskuryakov 2020-04-30 17:30:00 PDT
Comment on attachment 398092 [details]
Patch

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

> Source/WebKit/ChangeLog:17
> +        * GPUProcess/EntryPoint/Cocoa/XPCService/GPUService/Info-iOS.plist:
> +        * NetworkProcess/EntryPoint/Cocoa/XPCService/NetworkService/Info-iOS.plist:
> +        * WebProcess/EntryPoint/Cocoa/XPCService/WebContentService/Info-iOS.plist:

Aren't these plists also used for macCatalyst?
Comment 4 Chris Dumez 2020-04-30 17:51:01 PDT
(In reply to Alexey Proskuryakov from comment #3)
> Comment on attachment 398092 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=398092&action=review
> 
> > Source/WebKit/ChangeLog:17
> > +        * GPUProcess/EntryPoint/Cocoa/XPCService/GPUService/Info-iOS.plist:
> > +        * NetworkProcess/EntryPoint/Cocoa/XPCService/NetworkService/Info-iOS.plist:
> > +        * WebProcess/EntryPoint/Cocoa/XPCService/WebContentService/Info-iOS.plist:
> 
> Aren't these plists also used for macCatalyst?

Why? Do we have issues with RunningBoard assertions in macCatalyst? This bug is about iOS simulator.
Comment 5 Alexey Proskuryakov 2020-04-30 18:12:24 PDT
Right, so why add this in macCatalyst, what is I think what you are doing.
Comment 6 Chris Dumez 2020-04-30 20:42:11 PDT
Comment on attachment 398092 [details]
Patch

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

>>> Source/WebKit/ChangeLog:17
>>> +        * WebProcess/EntryPoint/Cocoa/XPCService/WebContentService/Info-iOS.plist:
>> 
>> Aren't these plists also used for macCatalyst?
> 
> Why? Do we have issues with RunningBoard assertions in macCatalyst? This bug is about iOS simulator.

You mean that the plists are shared between iOS and catalyst? That may be. does it matter? My new entries only have an impact in iOS simulator.
Comment 7 Alexey Proskuryakov 2020-05-01 09:57:25 PDT
Well, we usually try to not leave such tripmines.
Comment 8 Chris Dumez 2020-05-01 10:06:38 PDT
(In reply to Alexey Proskuryakov from comment #7)
> Well, we usually try to not leave such tripmines.

Why is it a tripmine? As I mentioned, it does not hurt.

Is there a better alternative? Is your proposal to split those plist files for Catalyst and Simulator? (I have not verified they are currently shared).
Comment 9 Alexey Proskuryakov 2020-05-01 10:31:02 PDT
How can you be certain that it doesn't hurt, and never will? If nothing else, it's virtually guaranteed to confuse engineers investigating RunningBoard related issues in the future.

> Is there a better alternative?

Source/WebKit/Scripts/process-entitlements.sh builds accurate entitlements for each platform.
Comment 10 Chris Dumez 2020-05-01 11:03:01 PDT
Ok, I am the proper entitlement working finally, with some help from our experts at Apple. I will upload a patch shortly.
Comment 11 Chris Dumez 2020-05-01 11:10:53 PDT
Created attachment 398206 [details]
Patch
Comment 12 EWS 2020-05-01 13:09:48 PDT
Committed r261015: <https://trac.webkit.org/changeset/261015>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 398206 [details].
Comment 13 Chris Dumez 2020-05-01 15:56:14 PDT
Reverted r261015 for reason:

Seems to have broken clean builds

Committed r261033: <https://trac.webkit.org/changeset/261033>
Comment 14 Chris Dumez 2020-05-01 15:59:23 PDT
*.entitlements files no longer seem to get generated for clean macOS builds...
Comment 15 Chris Dumez 2020-05-01 17:02:34 PDT
Comment on attachment 398206 [details]
Patch

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

> Source/WebKit/Configurations/BaseXPCService.xcconfig:87
> +CODE_SIGN_ENTITLEMENTS = $(WK_PROCESSED_XCENT_FILE);

It looks to me that it is trying to code sign before the $(WK_PROCESSED_XCENT_FILE) file is even generated. I am not sure yet how to express the dependency.
Comment 16 Chris Dumez 2020-05-01 18:00:37 PDT
(In reply to Chris Dumez from comment #15)
> Comment on attachment 398206 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=398206&action=review
> 
> > Source/WebKit/Configurations/BaseXPCService.xcconfig:87
> > +CODE_SIGN_ENTITLEMENTS = $(WK_PROCESSED_XCENT_FILE);
> 
> It looks to me that it is trying to code sign before the
> $(WK_PROCESSED_XCENT_FILE) file is even generated. I am not sure yet how to
> express the dependency.

CODE_SIGN_ENTITLEMENTS seems to expect the file to already exist and it doesn't because it gets generated via a "Run Script Phase" in Xcode. I don't know how to make this work. If anyone knows, please let me know.
Comment 17 Chris Dumez 2020-05-04 09:41:35 PDT
Created attachment 398377 [details]
Patch
Comment 18 Chris Dumez 2020-05-04 09:42:25 PDT
Created attachment 398378 [details]
Patch
Comment 19 Alexey Proskuryakov 2020-05-04 09:55:46 PDT
Comment on attachment 398378 [details]
Patch

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

> Source/WebKit/Configurations/BaseXPCService.xcconfig:-91
> -WK_LIBRARY_VALIDATION_CODE_SIGN_FLAGS_iossimulatorfamily = $(WK_LIBRARY_VALIDATION_CODE_SIGN_FLAGS_iossimulatorfamily_XBS_$(RC_XBS));

Can you explain what replaces the logic that excluded RC_XBS builds, that used to be here and in process-entitlements.sh? I doubt that we are supposed to have com.apple.security.get-task-allow in production builds. But also not sure why we checked the environment variable instead of build configuration.

> Source/WebKit/Configurations/BaseXPCService.xcconfig:93
> +CODE_SIGN_ENTITLEMENTS_iphonesimulator = Resources/ios/XPCService-ios-simulator.entitlements
> +CODE_SIGN_ENTITLEMENTS_appletvsimulator = Resources/ios/XPCService-ios-simulator.entitlements
> +CODE_SIGN_ENTITLEMENTS_watchsimulator = Resources/ios/XPCService-ios-simulator.entitlements

I think that the file should be named XPCService-embedded-simulator.entitlements.
Comment 20 Chris Dumez 2020-05-04 10:00:51 PDT
(In reply to Alexey Proskuryakov from comment #19)
> Comment on attachment 398378 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=398378&action=review
> 
> > Source/WebKit/Configurations/BaseXPCService.xcconfig:-91
> > -WK_LIBRARY_VALIDATION_CODE_SIGN_FLAGS_iossimulatorfamily = $(WK_LIBRARY_VALIDATION_CODE_SIGN_FLAGS_iossimulatorfamily_XBS_$(RC_XBS));
> 
> Can you explain what replaces the logic that excluded RC_XBS builds, that
> used to be here and in process-entitlements.sh? I doubt that we are supposed
> to have com.apple.security.get-task-allow in production builds. But also not
> sure why we checked the environment variable instead of build configuration.

For now, nothing. I am not clear why we were excluding RC_XBS builds (or what those are). The fact is that we were not added the entitlements properly previously for simulator builds. This meant that the entitlements applied to the host instead of inside the simulator. Now that it is no longer a real entitlement, I am not convinced it needs to be conditionalized. I tried to be conservative and keep the entitlement in question but odds are that it is not needed at all (since it was not properly added before).

> 
> > Source/WebKit/Configurations/BaseXPCService.xcconfig:93
> > +CODE_SIGN_ENTITLEMENTS_iphonesimulator = Resources/ios/XPCService-ios-simulator.entitlements
> > +CODE_SIGN_ENTITLEMENTS_appletvsimulator = Resources/ios/XPCService-ios-simulator.entitlements
> > +CODE_SIGN_ENTITLEMENTS_watchsimulator = Resources/ios/XPCService-ios-simulator.entitlements
> 
> I think that the file should be named
> XPCService-embedded-simulator.entitlements.

Ok.


Note that my personal preference would still be to use the script to generate the entitlements for simulator builds. However, I could not figure out how to make it work with CODE_SIGN_ENTITLEMENTS directive.
I figured I would do something that works and if somebody has a idea on how to make this work better, I would fix it.
Comment 21 Chris Dumez 2020-05-04 10:03:24 PDT
Created attachment 398382 [details]
Patch
Comment 22 Alexey Proskuryakov 2020-05-04 10:15:38 PDT
Having com.apple.security.get-task-allow on production builds seems likely to prevent them from going through Apple build system successfully. And it's not even clear to me if it's macOS or simulator side that needs to see it - after all, it's for using the debugger from macOS.

> Note that my personal preference would still be to use the script to generate the entitlements for simulator builds. However, I could not figure out how to make it work with CODE_SIGN_ENTITLEMENTS directive.

Understood. I'm obviously not an expert on these things.
Comment 23 Geoffrey Garen 2020-05-04 10:30:17 PDT
Comment on attachment 398382 [details]
Patch

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

> Source/WebKit/Scripts/process-entitlements.sh:211
> -    [[ "${RC_XBS}" != YES ]] && plistbuddy Add :com.apple.security.get-task-allow bool YES
> +    cp "${CODE_SIGN_ENTITLEMENTS}" "${WK_PROCESSED_XCENT_FILE}"

According to https://developer.apple.com/documentation/xcode/notarizing_macos_software_before_distribution/resolving_common_notarization_issues, get-task-allow is a security hole in production builds. This might mean that this change is a security hole, and/or that some B&I verifier will fail when trying to build with buildit or build in B&I or Guardian.

I'm a little surprised, since this implies that we do not allow attaching the debugger to any production software? But apparently that's the case:

(lldb) attach 8112
error: attach failed: cannot attach to process due to System Integrity Protection
Comment 24 Geoffrey Garen 2020-05-04 10:36:33 PDT
> According to
> https://developer.apple.com/documentation/xcode/
> notarizing_macos_software_before_distribution/
> resolving_common_notarization_issues, get-task-allow is a security hole in
> production builds...

That said, the only purpose of a Simulator build is debugging, so maybe it's OK to apply this entitlement to production simulator builds.
Comment 25 Geoffrey Garen 2020-05-04 10:44:58 PDT
Comment on attachment 398382 [details]
Patch

r=me

I don't think we'll know for sure whether a submission will build correctly until we try it. The most important thing is to know how we'll unblock the submission if it fails to build. Chris confirmed that we could just roll out this patch, since it has no dependencies yet.
Comment 26 Alexey Proskuryakov 2020-05-04 11:14:57 PDT
Is there any binary in the SDK with this entitlement today? Landing an incorrect change and hoping that tools won't block it seems exceptionally cavalier.
Comment 27 Chris Dumez 2020-05-04 11:20:28 PDT
(In reply to Alexey Proskuryakov from comment #26)
> Is there any binary in the SDK with this entitlement today? Landing an
> incorrect change and hoping that tools won't block it seems exceptionally
> cavalier.

This is not a real entitlement. It does not apply on the host system (anymore).
Comment 28 Geoffrey Garen 2020-05-04 11:38:00 PDT
> Is there any binary in the SDK with this entitlement today? Landing an
> incorrect change and hoping that tools won't block it seems exceptionally
> cavalier.

There is a discussion of the correctness of the change above.
Comment 29 EWS 2020-05-04 12:28:25 PDT
Committed r261099: <https://trac.webkit.org/changeset/261099>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 398382 [details].
Comment 30 Chris Dumez 2020-05-04 12:28:31 PDT
From https://developer.apple.com/documentation/xcode/notarizing_macos_software_before_distribution/resolving_common_notarization_issues:
"""
As a result, Xcode automatically strips the entitlement from your app when you export and sign it using the standard workflow.
"""

Now that we use the regular CODE_SIGN_ENTITLEMENTS for iOS simulator builds, it looks to be that Xcode is in charge of stripping this entitlement for production builds.

For other builds, we use a custom signing workflow so the entitlement would not get stripped.
Comment 31 Chris Dumez 2020-05-04 13:08:14 PDT
(In reply to Chris Dumez from comment #30)
> From
> https://developer.apple.com/documentation/xcode/
> notarizing_macos_software_before_distribution/
> resolving_common_notarization_issues:
> """
> As a result, Xcode automatically strips the entitlement from your app when
> you export and sign it using the standard workflow.
> """
> 
> Now that we use the regular CODE_SIGN_ENTITLEMENTS for iOS simulator builds,
> it looks to be that Xcode is in charge of stripping this entitlement for
> production builds.
> 
> For other builds, we use a custom signing workflow so the entitlement would
> not get stripped.

I am currently testing a patch at https://bugs.webkit.org/show_bug.cgi?id=211392 to avoid having to specific the get-task-allow explicitly and let Xcode take care of it for us.
Comment 32 Chris Dumez 2020-05-04 15:09:26 PDT
(In reply to Chris Dumez from comment #31)
> (In reply to Chris Dumez from comment #30)
> > From
> > https://developer.apple.com/documentation/xcode/
> > notarizing_macos_software_before_distribution/
> > resolving_common_notarization_issues:
> > """
> > As a result, Xcode automatically strips the entitlement from your app when
> > you export and sign it using the standard workflow.
> > """
> > 
> > Now that we use the regular CODE_SIGN_ENTITLEMENTS for iOS simulator builds,
> > it looks to be that Xcode is in charge of stripping this entitlement for
> > production builds.
> > 
> > For other builds, we use a custom signing workflow so the entitlement would
> > not get stripped.
> 
> I am currently testing a patch at
> https://bugs.webkit.org/show_bug.cgi?id=211392 to avoid having to specific
> the get-task-allow explicitly and let Xcode take care of it for us.

Follow-up in https://trac.webkit.org/changeset/261116.
Comment 33 Alexey Proskuryakov 2020-05-04 15:18:08 PDT
This looks substantially more convincing!