Title: [243034] trunk/Source
Revision
243034
Author
pvol...@apple.com
Date
2019-03-15 22:44:22 -0700 (Fri, 15 Mar 2019)

Log Message

[iOS] Block the accessibility server when accessibility is not enabled.
https://bugs.webkit.org/show_bug.cgi?id=195342

Reviewed by Brent Fulgham.

Source/WebKit:

By default, block the iOS accessibility server in the sandbox. If accessibility is enabled,
let the UI process issue a mach extension to the WebContent process. The UI process will
issue the mach extension the the WebContent process by its process identifier. The sandbox
extension handle is sent to the WebContent process to be consumed. The message will be sent
when the WebProcess has finished launching, and also when accessibility is turned on.

* Platform/spi/ios/AccessibilitySupportSPI.h:
* Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb:
* Shared/SandboxExtension.h:
* Shared/mac/SandboxExtensionMac.mm:
(WebKit::SandboxExtensionImpl::create):
(WebKit::SandboxExtensionImpl::sandboxExtensionForType):
(WebKit::SandboxExtensionImpl::SandboxExtensionImpl):
(WebKit::SandboxExtension::createHandleForMachLookupByPid):
* UIProcess/Cocoa/WebProcessPoolCocoa.mm:
(WebKit::WebProcessPool::registerNotificationObservers):
(WebKit::WebProcessPool::unregisterNotificationObservers):
* UIProcess/WebProcessPool.h:
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::didFinishLaunching):
* UIProcess/WebProcessProxy.h:
* UIProcess/ios/WebProcessProxyIOS.mm:
(WebKit::WebProcessProxy::unblockAccessibilityServerIfNeeded):
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::unblockAccessibilityServer):
* WebProcess/WebProcess.h:
* WebProcess/WebProcess.messages.in:

Source/WTF:

Add SPI to issue a mach extension to a process by pid. Also, add a macro for
the availability of this SPI.

* wtf/Platform.h:
* wtf/spi/darwin/SandboxSPI.h:

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (243033 => 243034)


--- trunk/Source/WTF/ChangeLog	2019-03-16 05:21:43 UTC (rev 243033)
+++ trunk/Source/WTF/ChangeLog	2019-03-16 05:44:22 UTC (rev 243034)
@@ -1,3 +1,16 @@
+2019-03-15  Per Arne Vollan  <pvol...@apple.com>
+
+        [iOS] Block the accessibility server when accessibility is not enabled.
+        https://bugs.webkit.org/show_bug.cgi?id=195342
+
+        Reviewed by Brent Fulgham.
+
+        Add SPI to issue a mach extension to a process by pid. Also, add a macro for
+        the availability of this SPI.
+
+        * wtf/Platform.h:
+        * wtf/spi/darwin/SandboxSPI.h:
+
 2019-03-15  Eric Carlson  <eric.carl...@apple.com>
 
         Add media stream release logging

Modified: trunk/Source/WTF/wtf/Platform.h (243033 => 243034)


--- trunk/Source/WTF/wtf/Platform.h	2019-03-16 05:21:43 UTC (rev 243033)
+++ trunk/Source/WTF/wtf/Platform.h	2019-03-16 05:44:22 UTC (rev 243034)
@@ -1505,6 +1505,10 @@
 #define HAVE_CSCHECKFIXDISABLE 1
 #endif
 
+#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || (PLATFORM(IOS_FAMILY) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 130000)
+#define HAVE_SANDBOX_ISSUE_MACH_EXTENSION_TO_PROCESS_BY_PID 1
+#endif
+
 #if PLATFORM(MAC)
 #define ENABLE_MONOSPACE_FONT_EXCEPTION (__MAC_OS_X_VERSION_MIN_REQUIRED < 101500)
 #elif PLATFORM(IOS_FAMILY)

Modified: trunk/Source/WTF/wtf/spi/darwin/SandboxSPI.h (243033 => 243034)


--- trunk/Source/WTF/wtf/spi/darwin/SandboxSPI.h	2019-03-16 05:21:43 UTC (rev 243033)
+++ trunk/Source/WTF/wtf/spi/darwin/SandboxSPI.h	2019-03-16 05:44:22 UTC (rev 243034)
@@ -63,6 +63,7 @@
 
 char *sandbox_extension_issue_file(const char *extension_class, const char *path, uint32_t flags);
 char *sandbox_extension_issue_generic(const char *extension_class, uint32_t flags);
+char *sandbox_extension_issue_mach_to_process_by_pid(const char *extension_class, const char *name, uint32_t flags, pid_t);
 int sandbox_check(pid_t, const char *operation, enum sandbox_filter_type, ...);
 int sandbox_check_by_audit_token(audit_token_t, const char *operation, enum sandbox_filter_type, ...);
 int sandbox_container_path_for_pid(pid_t, char *buffer, size_t bufsize);

Modified: trunk/Source/WebKit/ChangeLog (243033 => 243034)


--- trunk/Source/WebKit/ChangeLog	2019-03-16 05:21:43 UTC (rev 243033)
+++ trunk/Source/WebKit/ChangeLog	2019-03-16 05:44:22 UTC (rev 243034)
@@ -1,3 +1,38 @@
+2019-03-15  Per Arne Vollan  <pvol...@apple.com>
+
+        [iOS] Block the accessibility server when accessibility is not enabled.
+        https://bugs.webkit.org/show_bug.cgi?id=195342
+
+        Reviewed by Brent Fulgham.
+
+        By default, block the iOS accessibility server in the sandbox. If accessibility is enabled,
+        let the UI process issue a mach extension to the WebContent process. The UI process will
+        issue the mach extension the the WebContent process by its process identifier. The sandbox
+        extension handle is sent to the WebContent process to be consumed. The message will be sent
+        when the WebProcess has finished launching, and also when accessibility is turned on.
+
+        * Platform/spi/ios/AccessibilitySupportSPI.h:
+        * Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb:
+        * Shared/SandboxExtension.h:
+        * Shared/mac/SandboxExtensionMac.mm:
+        (WebKit::SandboxExtensionImpl::create):
+        (WebKit::SandboxExtensionImpl::sandboxExtensionForType):
+        (WebKit::SandboxExtensionImpl::SandboxExtensionImpl):
+        (WebKit::SandboxExtension::createHandleForMachLookupByPid):
+        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
+        (WebKit::WebProcessPool::registerNotificationObservers):
+        (WebKit::WebProcessPool::unregisterNotificationObservers):
+        * UIProcess/WebProcessPool.h:
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::didFinishLaunching):
+        * UIProcess/WebProcessProxy.h:
+        * UIProcess/ios/WebProcessProxyIOS.mm:
+        (WebKit::WebProcessProxy::unblockAccessibilityServerIfNeeded):
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::unblockAccessibilityServer):
+        * WebProcess/WebProcess.h:
+        * WebProcess/WebProcess.messages.in:
+
 2019-03-15  Timothy Hatcher  <timo...@apple.com>
 
         Unreviewed speculative build fix for non-Cocoa ports after r243012.

Modified: trunk/Source/WebKit/Platform/spi/ios/AccessibilitySupportSPI.h (243033 => 243034)


--- trunk/Source/WebKit/Platform/spi/ios/AccessibilitySupportSPI.h	2019-03-16 05:21:43 UTC (rev 243033)
+++ trunk/Source/WebKit/Platform/spi/ios/AccessibilitySupportSPI.h	2019-03-16 05:44:22 UTC (rev 243034)
@@ -41,6 +41,8 @@
 #if PLATFORM(IOS_FAMILY)
 extern Boolean _AXSKeyRepeatEnabled();
 extern CFTimeInterval _AXSKeyRepeatDelay();
+extern Boolean _AXSApplicationAccessibilityEnabled();
+extern CFStringRef kAXSApplicationAccessibilityEnabledNotification;
 #endif
 
 #if ENABLE(ACCESSIBILITY_EVENTS)

Modified: trunk/Source/WebKit/Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb (243033 => 243034)


--- trunk/Source/WebKit/Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb	2019-03-16 05:21:43 UTC (rev 243033)
+++ trunk/Source/WebKit/Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb	2019-03-16 05:44:22 UTC (rev 243034)
@@ -188,7 +188,6 @@
     (global-name "com.apple.backboard.hid.focus")
     (global-name "com.apple.backboard.hid.services")
     (global-name "com.apple.iohideventsystem")
-    (global-name "com.apple.iphone.axserver-systemwide")
     (global-name "com.apple.frontboard.workspace")
     (global-name "com.apple.frontboard.systemappservices"))
 
@@ -451,6 +450,8 @@
 (deny mach-lookup (with send-signal SIGKILL)
     (global-name "com.apple.backboard.hid.services"))
 
+(allow mach-lookup (extension "com.apple.webkit.extension.mach"))
+
 ;; These services have been identified as unused during living-on.
 ;; This list overrides some definitions above and in common.sb.
 ;; FIXME: remove overridden rules once the final list has been

Modified: trunk/Source/WebKit/Shared/SandboxExtension.h (243033 => 243034)


--- trunk/Source/WebKit/Shared/SandboxExtension.h	2019-03-16 05:21:43 UTC (rev 243033)
+++ trunk/Source/WebKit/Shared/SandboxExtension.h	2019-03-16 05:44:22 UTC (rev 243034)
@@ -46,6 +46,7 @@
     enum class Type {
         ReadOnly,
         ReadWrite,
+        Mach,
         Generic,
     };
 
@@ -101,6 +102,7 @@
     static bool createHandleForReadWriteDirectory(const String& path, Handle&); // Will attempt to create the directory.
     static String createHandleForTemporaryFile(const String& prefix, Type, Handle&);
     static bool createHandleForGenericExtension(const String& extensionClass, Handle&);
+    static bool createHandleForMachLookupByPid(const String& service, pid_t, Handle&);
     ~SandboxExtension();
 
     bool consume();

Modified: trunk/Source/WebKit/Shared/mac/SandboxExtensionMac.mm (243033 => 243034)


--- trunk/Source/WebKit/Shared/mac/SandboxExtensionMac.mm	2019-03-16 05:21:43 UTC (rev 243033)
+++ trunk/Source/WebKit/Shared/mac/SandboxExtensionMac.mm	2019-03-16 05:44:22 UTC (rev 243034)
@@ -40,9 +40,9 @@
 
 class SandboxExtensionImpl {
 public:
-    static std::unique_ptr<SandboxExtensionImpl> create(const char* path, SandboxExtension::Type type)
+    static std::unique_ptr<SandboxExtensionImpl> create(const char* path, SandboxExtension::Type type, Optional<pid_t> pid = WTF::nullopt)
     {
-        std::unique_ptr<SandboxExtensionImpl> impl { new SandboxExtensionImpl(path, type) };
+        std::unique_ptr<SandboxExtensionImpl> impl { new SandboxExtensionImpl(path, type, pid) };
         if (!impl->m_token)
             return nullptr;
         return impl;
@@ -64,6 +64,10 @@
 #if PLATFORM(IOS_FAMILY_SIMULATOR)
         return !sandbox_check(getpid(), 0, SANDBOX_FILTER_NONE);
 #else
+        if (m_handle == -1) {
+            LOG_ERROR("Could not create a sandbox extension for '%s', errno = %d", m_token, errno);
+            return false;
+        }
         return m_handle;
 #endif
     }
@@ -80,7 +84,7 @@
     }
 
 private:
-    char* sandboxExtensionForType(const char* path, SandboxExtension::Type type)
+    char* sandboxExtensionForType(const char* path, SandboxExtension::Type type, Optional<pid_t> pid = WTF::nullopt)
     {
         switch (type) {
         case SandboxExtension::Type::ReadOnly:
@@ -87,13 +91,21 @@
             return sandbox_extension_issue_file(APP_SANDBOX_READ, path, 0);
         case SandboxExtension::Type::ReadWrite:
             return sandbox_extension_issue_file(APP_SANDBOX_READ_WRITE, path, 0);
+        case SandboxExtension::Type::Mach:
+#if HAVE(SANDBOX_ISSUE_MACH_EXTENSION_TO_PROCESS_BY_PID)
+            return sandbox_extension_issue_mach_to_process_by_pid("com.apple.webkit.extension.mach"_s, path, 0, pid.value());
+#else
+            UNUSED_PARAM(pid);
+            ASSERT_NOT_REACHED();
+            return nullptr;
+#endif
         case SandboxExtension::Type::Generic:
             return sandbox_extension_issue_generic(path, 0);
         }
     }
 
-    SandboxExtensionImpl(const char* path, SandboxExtension::Type type)
-        : m_token { sandboxExtensionForType(path, type) }
+    SandboxExtensionImpl(const char* path, SandboxExtension::Type type, Optional<pid_t> pid = WTF::nullopt)
+        : m_token { sandboxExtensionForType(path, type, pid) }
     {
     }
 
@@ -357,6 +369,19 @@
     return true;
 }
 
+bool SandboxExtension::createHandleForMachLookupByPid(const String& service, pid_t pid, Handle& handle)
+{
+    ASSERT(!handle.m_sandboxExtension);
+    
+    handle.m_sandboxExtension = SandboxExtensionImpl::create(service.utf8().data(), Type::Mach, pid);
+    if (!handle.m_sandboxExtension) {
+        WTFLogAlways("Could not create a '%s' sandbox extension", service.utf8().data());
+        return false;
+    }
+    
+    return true;
+}
+
 SandboxExtension::SandboxExtension(const Handle& handle)
     : m_sandboxExtension(WTFMove(handle.m_sandboxExtension))
 {

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm (243033 => 243034)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2019-03-16 05:21:43 UTC (rev 243033)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm	2019-03-16 05:44:22 UTC (rev 243034)
@@ -26,6 +26,7 @@
 #import "config.h"
 #import "WebProcessPool.h"
 
+#import "AccessibilitySupportSPI.h"
 #import "CookieStorageUtilsCF.h"
 #import "LegacyCustomProtocolManagerClient.h"
 #import "NetworkProcessCreationParameters.h"
@@ -447,6 +448,10 @@
     }];
 #elif PLATFORM(IOS)
     CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), this, backlightLevelDidChangeCallback, static_cast<CFStringRef>(UIBacklightLevelChangedNotification), nullptr, CFNotificationSuspensionBehaviorCoalesce);
+    m_accessibilityEnabledObserver = [[NSNotificationCenter defaultCenter] addObserverForName:(__bridge id)kAXSApplicationAccessibilityEnabledNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *) {
+        for (size_t i = 0; i < m_processes.size(); ++i)
+            m_processes[i]->unblockAccessibilityServerIfNeeded();
+    }];
 #endif // !PLATFORM(IOS_FAMILY)
 }
 
@@ -466,6 +471,7 @@
     [[NSNotificationCenter defaultCenter] removeObserver:m_deactivationObserver.get()];
 #elif PLATFORM(IOS)
     CFNotificationCenterRemoveObserver(CFNotificationCenterGetDarwinNotifyCenter(), this, static_cast<CFStringRef>(UIBacklightLevelChangedNotification) , nullptr);
+    [[NSNotificationCenter defaultCenter] removeObserver:m_accessibilityEnabledObserver.get()];
 #endif // !PLATFORM(IOS_FAMILY)
 }
 

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.h (243033 => 243034)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.h	2019-03-16 05:21:43 UTC (rev 243033)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.h	2019-03-16 05:44:22 UTC (rev 243034)
@@ -673,6 +673,10 @@
     std::unique_ptr<PerActivityStateCPUUsageSampler> m_perActivityStateCPUUsageSampler;
 #endif
 
+#if PLATFORM(IOS_FAMILY)
+    RetainPtr<NSObject> m_accessibilityEnabledObserver;
+#endif
+
     bool m_shouldUseTestingNetworkSession { false };
 
     bool m_processTerminationEnabled { true };

Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp (243033 => 243034)


--- trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2019-03-16 05:21:43 UTC (rev 243033)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2019-03-16 05:44:22 UTC (rev 243034)
@@ -759,6 +759,8 @@
         if (xpc_connection_t xpcConnection = connection()->xpcConnection())
             m_throttler.didConnectToProcess(xpc_connection_get_pid(xpcConnection));
     }
+
+    unblockAccessibilityServerIfNeeded();
 #endif
 }
 

Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.h (243033 => 243034)


--- trunk/Source/WebKit/UIProcess/WebProcessProxy.h	2019-03-16 05:21:43 UTC (rev 243033)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.h	2019-03-16 05:44:22 UTC (rev 243034)
@@ -293,6 +293,10 @@
     void revokeAudioCaptureExtension() { m_mediaCaptureSandboxExtensions &= ~Audio; }
 #endif
 
+#if PLATFORM(IOS_FAMILY)
+    void unblockAccessibilityServerIfNeeded();
+#endif
+
 protected:
     static uint64_t generatePageID();
     WebProcessProxy(WebProcessPool&, WebsiteDataStore&, IsPrewarmed);
@@ -431,6 +435,7 @@
 #if PLATFORM(IOS_FAMILY)
     ForegroundWebProcessToken m_foregroundToken;
     BackgroundWebProcessToken m_backgroundToken;
+    bool m_hasSentMessageToUnblockAccessibilityServer { false };
 #endif
 
     HashMap<String, uint64_t> m_pageURLRetainCountMap;

Modified: trunk/Source/WebKit/UIProcess/ios/WebProcessProxyIOS.mm (243033 => 243034)


--- trunk/Source/WebKit/UIProcess/ios/WebProcessProxyIOS.mm	2019-03-16 05:21:43 UTC (rev 243033)
+++ trunk/Source/WebKit/UIProcess/ios/WebProcessProxyIOS.mm	2019-03-16 05:44:22 UTC (rev 243034)
@@ -28,6 +28,7 @@
 
 #if PLATFORM(IOS_FAMILY)
 
+#import "AccessibilitySupportSPI.h"
 #import "WKFullKeyboardAccessWatcher.h"
 #import "WebProcessMessages.h"
 
@@ -42,6 +43,25 @@
 #endif
 }
 
+void WebProcessProxy::unblockAccessibilityServerIfNeeded()
+{
+    if (m_hasSentMessageToUnblockAccessibilityServer)
+        return;
+    if (!_AXSApplicationAccessibilityEnabled())
+        return;
+    if (!processIdentifier())
+        return;
+    if (!canSendMessage())
+        return;
+
+    SandboxExtension::Handle handle;
+    if (!SandboxExtension::createHandleForMachLookupByPid("com.apple.iphone.axserver-systemwide", processIdentifier(), handle))
+        return;
+
+    send(Messages::WebProcess::UnblockAccessibilityServer(handle), 0);
+    m_hasSentMessageToUnblockAccessibilityServer = true;
+}
+
 } // namespace WebKit
 
 #endif // PLATFORM(IOS_FAMILY)

Modified: trunk/Source/WebKit/WebProcess/WebProcess.cpp (243033 => 243034)


--- trunk/Source/WebKit/WebProcess/WebProcess.cpp	2019-03-16 05:21:43 UTC (rev 243033)
+++ trunk/Source/WebKit/WebProcess/WebProcess.cpp	2019-03-16 05:44:22 UTC (rev 243034)
@@ -1867,4 +1867,12 @@
     PlatformKeyboardEvent::setCurrentModifierState({ });
 }
 
+#if PLATFORM(IOS_FAMILY)
+void WebProcess::unblockAccessibilityServer(const SandboxExtension::Handle& handle)
+{
+    bool ok = SandboxExtension::consumePermanently(handle);
+    ASSERT_UNUSED(ok, ok);
+}
+#endif
+
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/WebProcess.h (243033 => 243034)


--- trunk/Source/WebKit/WebProcess/WebProcess.h	2019-03-16 05:21:43 UTC (rev 243033)
+++ trunk/Source/WebKit/WebProcess/WebProcess.h	2019-03-16 05:44:22 UTC (rev 243034)
@@ -245,6 +245,8 @@
 
 #if PLATFORM(IOS_FAMILY)
     void accessibilityProcessSuspendedNotification(bool);
+    
+    void unblockAccessibilityServer(const SandboxExtension::Handle&);
 #endif
 
 #if PLATFORM(IOS)

Modified: trunk/Source/WebKit/WebProcess/WebProcess.messages.in (243033 => 243034)


--- trunk/Source/WebKit/WebProcess/WebProcess.messages.in	2019-03-16 05:21:43 UTC (rev 243033)
+++ trunk/Source/WebKit/WebProcess/WebProcess.messages.in	2019-03-16 05:44:22 UTC (rev 243034)
@@ -157,4 +157,8 @@
 #endif
 
     ClearCurrentModifierStateForTesting()
+
+#if PLATFORM(IOS_FAMILY)
+    UnblockAccessibilityServer(WebKit::SandboxExtension::Handle handle)
+#endif
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to