Title: [293380] trunk/Source/WebKit
Revision
293380
Author
[email protected]
Date
2022-04-25 17:16:10 -0700 (Mon, 25 Apr 2022)

Log Message

HARDENING: Add MESSAGE_CHECK in some Captive Portal cases
https://bugs.webkit.org/show_bug.cgi?id=239551
<rdar://91478748>

Reviewed by Darin Adler.

Add MESSAGE_CHECK protections to a set of message handlers for API prohibited when
sent from a Captive Portal process. This change also adds a flag to the GPUProcessConnectionParameters
struct so that GPU Process connections can be marked as being associated with a Captive Portal
process.

* GPUProcess/GPUConnectionToWebProcess.cpp:
(WebKit::GPUConnectionToWebProcess::GPUConnectionToWebProcess):
(WebKit::GPUConnectionToWebProcess::createGraphicsContextGL):
(WebKit::GPUConnectionToWebProcess::releaseGraphicsContextGL):
* GPUProcess/GPUConnectionToWebProcess.h:
(WebKit::GPUConnectionToWebProcess::isCaptivePortalModeEnabled const):
* GPUProcess/media/RemoteAudioDestinationManager.cpp:
(WebKit::RemoteAudioDestinationManager::createAudioDestination):
(WebKit::RemoteAudioDestinationManager::deleteAudioDestination):
(WebKit::RemoteAudioDestinationManager::startAudioDestination):
(WebKit::RemoteAudioDestinationManager::stopAudioDestination):
* Shared/GPUProcessConnectionParameters.h:
(WebKit::GPUProcessConnectionParameters::encode const):
(WebKit::GPUProcessConnectionParameters::decode):
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::getGPUProcessConnection):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (293379 => 293380)


--- trunk/Source/WebKit/ChangeLog	2022-04-26 00:12:01 UTC (rev 293379)
+++ trunk/Source/WebKit/ChangeLog	2022-04-26 00:16:10 UTC (rev 293380)
@@ -1,3 +1,33 @@
+2022-04-25  Brent Fulgham  <[email protected]>
+
+        HARDENING: Add MESSAGE_CHECK in some Captive Portal cases
+        https://bugs.webkit.org/show_bug.cgi?id=239551
+        <rdar://91478748>
+
+        Reviewed by Darin Adler.
+
+        Add MESSAGE_CHECK protections to a set of message handlers for API prohibited when
+        sent from a Captive Portal process. This change also adds a flag to the GPUProcessConnectionParameters
+        struct so that GPU Process connections can be marked as being associated with a Captive Portal
+        process.
+
+        * GPUProcess/GPUConnectionToWebProcess.cpp:
+        (WebKit::GPUConnectionToWebProcess::GPUConnectionToWebProcess):
+        (WebKit::GPUConnectionToWebProcess::createGraphicsContextGL):
+        (WebKit::GPUConnectionToWebProcess::releaseGraphicsContextGL):
+        * GPUProcess/GPUConnectionToWebProcess.h:
+        (WebKit::GPUConnectionToWebProcess::isCaptivePortalModeEnabled const):
+        * GPUProcess/media/RemoteAudioDestinationManager.cpp:
+        (WebKit::RemoteAudioDestinationManager::createAudioDestination):
+        (WebKit::RemoteAudioDestinationManager::deleteAudioDestination):
+        (WebKit::RemoteAudioDestinationManager::startAudioDestination):
+        (WebKit::RemoteAudioDestinationManager::stopAudioDestination):
+        * Shared/GPUProcessConnectionParameters.h:
+        (WebKit::GPUProcessConnectionParameters::encode const):
+        (WebKit::GPUProcessConnectionParameters::decode):
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::getGPUProcessConnection):
+
 2022-04-25  Devin Rousso  <[email protected]>
 
         Web Inspector: request interception should not be guarded based on service workers

Modified: trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp (293379 => 293380)


--- trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp	2022-04-26 00:12:01 UTC (rev 293379)
+++ trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp	2022-04-26 00:16:10 UTC (rev 293380)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2019-2021 Apple Inc. All rights reserved.
+ * Copyright (C) 2019-2022 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -158,6 +158,8 @@
 #include "RemoteVideoFrameObjectHeap.h"
 #endif
 
+#define MESSAGE_CHECK(assertion) MESSAGE_CHECK_BASE(assertion, (&connection()))
+
 namespace WebKit {
 using namespace WebCore;
 
@@ -257,6 +259,7 @@
 #if HAVE(AUDIT_TOKEN)
     , m_presentingApplicationAuditToken(WTFMove(parameters.presentingApplicationAuditToken))
 #endif
+    , m_isCaptivePortalModeEnabled(parameters.isCaptivePortalModeEnabled)
 #if ENABLE(ROUTING_ARBITRATION) && HAVE(AVAUDIO_ROUTING_ARBITER)
     , m_routingArbitrator(LocalAudioSessionRoutingArbitrator::create(*this))
 #endif
@@ -549,6 +552,8 @@
 #if ENABLE(WEBGL)
 void GPUConnectionToWebProcess::createGraphicsContextGL(WebCore::GraphicsContextGLAttributes attributes, GraphicsContextGLIdentifier graphicsContextGLIdentifier, RenderingBackendIdentifier renderingBackendIdentifier, IPC::StreamConnectionBuffer&& stream)
 {
+    MESSAGE_CHECK(!isCaptivePortalModeEnabled());
+
     auto it = m_remoteRenderingBackendMap.find(renderingBackendIdentifier);
     if (it == m_remoteRenderingBackendMap.end())
         return;
@@ -562,6 +567,8 @@
 
 void GPUConnectionToWebProcess::releaseGraphicsContextGL(GraphicsContextGLIdentifier graphicsContextGLIdentifier)
 {
+    MESSAGE_CHECK(!isCaptivePortalModeEnabled());
+
     m_remoteGraphicsContextGLMap.remove(graphicsContextGLIdentifier);
     if (m_remoteGraphicsContextGLMap.isEmpty())
         gpuProcess().tryExitIfUnusedAndUnderMemoryPressure();
@@ -987,4 +994,6 @@
 
 } // namespace WebKit
 
+#undef MESSAGE_CHECK
+
 #endif // ENABLE(GPU_PROCESS)

Modified: trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.h (293379 => 293380)


--- trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.h	2022-04-26 00:12:01 UTC (rev 293379)
+++ trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.h	2022-04-26 00:16:10 UTC (rev 293380)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2019-2021 Apple Inc. All rights reserved.
+ * Copyright (C) 2019-2022 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -135,6 +135,8 @@
 
     PAL::SessionID sessionID() const { return m_sessionID; }
 
+    bool isCaptivePortalModeEnabled() const { return m_isCaptivePortalModeEnabled; }
+
     Logger& logger();
 
     const String& mediaCacheDirectory() const;
@@ -365,6 +367,7 @@
 
     RefPtr<RemoteRemoteCommandListenerProxy> m_remoteRemoteCommandListener;
     bool m_isActiveNowPlayingProcess { false };
+    bool m_isCaptivePortalModeEnabled { false };
 
 #if ENABLE(ROUTING_ARBITRATION) && HAVE(AVAUDIO_ROUTING_ARBITER)
     UniqueRef<LocalAudioSessionRoutingArbitrator> m_routingArbitrator;

Modified: trunk/Source/WebKit/GPUProcess/media/RemoteAudioDestinationManager.cpp (293379 => 293380)


--- trunk/Source/WebKit/GPUProcess/media/RemoteAudioDestinationManager.cpp	2022-04-26 00:12:01 UTC (rev 293379)
+++ trunk/Source/WebKit/GPUProcess/media/RemoteAudioDestinationManager.cpp	2022-04-26 00:16:10 UTC (rev 293380)
@@ -30,6 +30,7 @@
 
 #include "GPUConnectionToWebProcess.h"
 #include "GPUProcess.h"
+#include "Logging.h"
 #include <WebCore/AudioUtilities.h>
 #include <wtf/ThreadSafeRefCounted.h>
 
@@ -41,6 +42,25 @@
 #include <WebCore/WebAudioBufferList.h>
 #endif
 
+#if ENABLE(IPC_TESTING_API)
+#define WEB_PROCESS_TERMINATE_CONDITION !m_gpuConnectionToWebProcess.connection().ignoreInvalidMessageForTesting()
+#else
+#define WEB_PROCESS_TERMINATE_CONDITION true
+#endif
+
+#define TERMINATE_WEB_PROCESS_WITH_MESSAGE(message) \
+    if (WEB_PROCESS_TERMINATE_CONDITION) { \
+        RELEASE_LOG_FAULT(IPC, "Requesting termination of web process %" PRIu64 " for reason: %" PUBLIC_LOG_STRING, m_gpuConnectionToWebProcess.webProcessIdentifier().toUInt64(), #message); \
+        m_gpuConnectionToWebProcess.terminateWebProcess(); \
+    }
+
+#define MESSAGE_CHECK(assertion, message) do { \
+    if (UNLIKELY(!(assertion))) { \
+        TERMINATE_WEB_PROCESS_WITH_MESSAGE(message); \
+        return; \
+    } \
+} while (0)
+
 namespace WebKit {
 
 class RemoteAudioDestination final
@@ -147,6 +167,8 @@
 
 void RemoteAudioDestinationManager::createAudioDestination(const String& inputDeviceId, uint32_t numberOfInputChannels, uint32_t numberOfOutputChannels, float sampleRate, float hardwareSampleRate, IPC::Semaphore&& renderSemaphore, CompletionHandler<void(const WebKit::RemoteAudioDestinationIdentifier)>&& completionHandler)
 {
+    MESSAGE_CHECK(!m_gpuConnectionToWebProcess.isCaptivePortalModeEnabled(), "Received a createAudioDestination() message from a CaptivePortal.");
+
     auto newID = RemoteAudioDestinationIdentifier::generateThreadSafe();
     auto destination = makeUniqueRef<RemoteAudioDestination>(m_gpuConnectionToWebProcess, newID, inputDeviceId, numberOfInputChannels, numberOfOutputChannels, sampleRate, hardwareSampleRate, WTFMove(renderSemaphore));
     m_audioDestinations.add(newID, WTFMove(destination));
@@ -155,6 +177,8 @@
 
 void RemoteAudioDestinationManager::deleteAudioDestination(RemoteAudioDestinationIdentifier identifier, CompletionHandler<void()>&& completionHandler)
 {
+    MESSAGE_CHECK(!m_gpuConnectionToWebProcess.isCaptivePortalModeEnabled(), "Received a deleteAudioDestination() message from a CaptivePortal.");
+
     m_audioDestinations.remove(identifier);
     completionHandler();
 
@@ -164,6 +188,8 @@
 
 void RemoteAudioDestinationManager::startAudioDestination(RemoteAudioDestinationIdentifier identifier, CompletionHandler<void(bool)>&& completionHandler)
 {
+    MESSAGE_CHECK(!m_gpuConnectionToWebProcess.isCaptivePortalModeEnabled(), "Received a startAudioDestination() message from a CaptivePortal.");
+
     bool isPlaying = false;
     if (auto* item = m_audioDestinations.get(identifier)) {
         item->start();
@@ -174,6 +200,8 @@
 
 void RemoteAudioDestinationManager::stopAudioDestination(RemoteAudioDestinationIdentifier identifier, CompletionHandler<void(bool)>&& completionHandler)
 {
+    MESSAGE_CHECK(!m_gpuConnectionToWebProcess.isCaptivePortalModeEnabled(), "Received a stopAudioDestination() message from a CaptivePortal.");
+
     bool isPlaying = false;
     if (auto* item = m_audioDestinations.get(identifier)) {
         item->stop();
@@ -201,4 +229,8 @@
 
 } // namespace WebKit
 
+#undef MESSAGE_CHECK
+#undef TERMINATE_WEB_PROCESS_WITH_MESSAGE
+#undef WEB_PROCESS_TERMINATE_CONDITION
+
 #endif // ENABLE(GPU_PROCESS) && ENABLE(WEB_AUDIO)

Modified: trunk/Source/WebKit/Shared/GPUProcessConnectionParameters.h (293379 => 293380)


--- trunk/Source/WebKit/Shared/GPUProcessConnectionParameters.h	2022-04-26 00:12:01 UTC (rev 293379)
+++ trunk/Source/WebKit/Shared/GPUProcessConnectionParameters.h	2022-04-26 00:16:10 UTC (rev 293380)
@@ -36,6 +36,7 @@
 struct GPUProcessConnectionParameters {
     WebCore::ProcessIdentity webProcessIdentity;
     Vector<String> overrideLanguages;
+    bool isCaptivePortalModeEnabled { false };
 #if ENABLE(IPC_TESTING_API)
     bool ignoreInvalidMessageForTesting { false };
 #endif
@@ -47,6 +48,7 @@
     {
         encoder << webProcessIdentity;
         encoder << overrideLanguages;
+        encoder << isCaptivePortalModeEnabled;
 #if ENABLE(IPC_TESTING_API)
         encoder << ignoreInvalidMessageForTesting;
 #endif
@@ -67,6 +69,11 @@
         if (!overrideLanguages)
             return std::nullopt;
 
+        std::optional<bool> isCaptivePortalModeEnabled;
+        decoder >> isCaptivePortalModeEnabled;
+        if (!isCaptivePortalModeEnabled)
+            return std::nullopt;
+
 #if ENABLE(IPC_TESTING_API)
         std::optional<bool> ignoreInvalidMessageForTesting;
         decoder >> ignoreInvalidMessageForTesting;
@@ -83,6 +90,7 @@
         return GPUProcessConnectionParameters {
             WTFMove(*webProcessIdentity),
             WTFMove(*overrideLanguages),
+            *isCaptivePortalModeEnabled,
 #if ENABLE(IPC_TESTING_API)
             *ignoreInvalidMessageForTesting,
 #endif

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.cpp (293379 => 293380)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2022-04-26 00:12:01 UTC (rev 293379)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2022-04-26 00:16:10 UTC (rev 293380)
@@ -524,6 +524,8 @@
     parameters.presentingApplicationAuditToken = configuration().presentingApplicationProcessToken();
 #endif
 
+    parameters.isCaptivePortalModeEnabled = webProcessProxy.captivePortalMode() == WebProcessProxy::CaptivePortalMode::Enabled;
+
     ensureGPUProcess().getGPUProcessConnection(webProcessProxy, parameters, [this, weakThis = WeakPtr { *this }, parameters, webProcessProxy = WeakPtr { webProcessProxy }, reply = WTFMove(reply)] (auto& connectionInfo) mutable {
         if (UNLIKELY(!IPC::Connection::identifierIsValid(connectionInfo.identifier()))) {
             // Retry on the next RunLoop iteration because we may be inside the WebProcessPool destructor.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to