Skip to content

Commit

Permalink
Block access to trustd on macOS
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=264685
rdar://114834439

Reviewed by Sihui Liu.

This can be achieved by using a new flag to skip code sign validation for trusted plugins.
This change also enables us to remove eager opening of the trustd connection.

* Source/WebCore/PAL/pal/spi/cf/VideoToolboxSPI.h:
* Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm:
(WebKit::WebProcessPool::platformInitializeWebProcess):
* Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::setVideoDecoderBehaviors):
(WebKit::WebProcess::platformInitializeWebProcess):
* Source/WebKit/WebProcess/com.apple.WebProcess.sb.in:

Canonical link: https://commits.webkit.org/270720@main
  • Loading branch information
pvollan committed Nov 14, 2023
1 parent 362150b commit e1fa6b5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions Source/WebCore/PAL/pal/spi/cf/VideoToolboxSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum {
kVTRestrictions_AvoidHardwareDecoders = 1UL << 1,
kVTRestrictions_AvoidIOSurfaceBackings = 1UL << 2,
kVTRestrictions_AvoidHardwarePixelTransfer = 1UL << 3,
kVTRestrictions_RegisterLimitedSystemDecodersWithoutValidation = 1UL<<6
};
typedef uint32_t VTVideoDecoderRestrictions;

Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ static void logProcessPoolState(const WebProcessPool& pool)
#endif

#if HAVE(VIDEO_RESTRICTED_DECODING)
#if PLATFORM(MAC)
#if PLATFORM(MAC) && !ENABLE(TRUSTD_BLOCKING_IN_WEBCONTENT)
// FIXME: this will not be needed when rdar://74144544 is fixed.
if (auto trustdExtensionHandle = SandboxExtension::createHandleForMachLookup("com.apple.trustd.agent"_s, std::nullopt))
parameters.trustdExtensionHandle = WTFMove(*trustdExtensionHandle);
Expand Down
8 changes: 6 additions & 2 deletions Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ static void setVideoDecoderBehaviors(OptionSet<VideoDecoderBehavior> videoDecode
if (videoDecoderBehavior.contains(VideoDecoderBehavior::AvoidIOSurface))
flags |= kVTRestrictions_AvoidIOSurfaceBackings;

#if ENABLE(TRUSTD_BLOCKING_IN_WEBCONTENT)
flags |= kVTRestrictions_RegisterLimitedSystemDecodersWithoutValidation;
#endif

PAL::softLinkVideoToolboxVTRestrictVideoDecoders(flags, allowedCodecTypeList.data(), allowedCodecTypeList.size());
}

Expand Down Expand Up @@ -346,7 +350,7 @@ static void setVideoDecoderBehaviors(OptionSet<VideoDecoderBehavior> videoDecode
#endif

#if HAVE(VIDEO_RESTRICTED_DECODING)
#if PLATFORM(MAC)
#if PLATFORM(MAC) && !ENABLE(TRUSTD_BLOCKING_IN_WEBCONTENT)
OSObjectPtr<dispatch_semaphore_t> codeCheckSemaphore;
if (SandboxExtension::consumePermanently(parameters.trustdExtensionHandle)) {
// Open up a Mach connection to trustd by doing a code check validation on the main bundle.
Expand Down Expand Up @@ -547,7 +551,7 @@ static void setVideoDecoderBehaviors(OptionSet<VideoDecoderBehavior> videoDecode

disableURLSchemeCheckInDataDetectors();

#if HAVE(VIDEO_RESTRICTED_DECODING) && PLATFORM(MAC)
#if HAVE(VIDEO_RESTRICTED_DECODING) && PLATFORM(MAC) && !ENABLE(TRUSTD_BLOCKING_IN_WEBCONTENT)
if (codeCheckSemaphore)
dispatch_semaphore_wait(codeCheckSemaphore.get(), DISPATCH_TIME_FOREVER);
#endif
Expand Down
2 changes: 2 additions & 0 deletions Source/WebKit/WebProcess/com.apple.WebProcess.sb.in
Original file line number Diff line number Diff line change
Expand Up @@ -1400,10 +1400,12 @@
))
#endif

#if !ENABLE(TRUSTD_BLOCKING_IN_WEBCONTENT)
(allow mach-lookup
(require-all
(extension "com.apple.webkit.extension.mach")
(global-name "com.apple.trustd.agent")))
#endif

#if ENABLE(LOGD_BLOCKING_IN_WEBCONTENT)
(with-filter (system-attribute apple-internal)
Expand Down

0 comments on commit e1fa6b5

Please sign in to comment.