Changeset 293509 in webkit
- Timestamp:
- Apr 27, 2022 8:49:37 AM (2 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r293507 r293509 1 2022-04-27 Per Arne Vollan <pvollan@apple.com> 2 3 [macOS] The function getpwnam can sometimes fail 4 https://bugs.webkit.org/show_bug.cgi?id=239513 5 <rdar://89758690> 6 7 Reviewed by Darin Adler. 8 9 The system function getpwnam is caching the results from the first invocation, and will return the cached 10 values after the first call. It may happen that opendirectoryd will invalidate the cached values by 11 posting notifications. If that happens, getpwnam will then fail, since there are no cached values and 12 the WebContent process' sandbox is blocking access to opendirectoryd. This patch addresses this issue 13 by observing these notifications in the UI process, and recreating the cached values for getpwnam, by 14 calling the function in the WebContent process while holding a temporary sandbox extenstion to 15 opendirectoryd. 16 17 * GPUProcess/GPUProcess.h: 18 * GPUProcess/GPUProcess.messages.in: 19 * GPUProcess/mac/GPUProcessMac.mm: 20 (WebKit::GPUProcess::openDirectoryCacheInvalidated): 21 * GPUProcess/mac/com.apple.WebKit.GPUProcess.sb.in: 22 * Shared/AuxiliaryProcess.h: 23 * Shared/mac/AuxiliaryProcessMac.mm: 24 (WebKit::getHomeDirectory): 25 (WebKit::populateSandboxInitializationParameters): 26 (WebKit::AuxiliaryProcess::openDirectoryCacheInvalidated): 27 * UIProcess/Cocoa/WebProcessPoolCocoa.mm: 28 (WebKit::WebProcessPool::registerNotificationObservers): 29 (WebKit::WebProcessPool::unregisterNotificationObservers): 30 * UIProcess/WebProcessPool.h: 31 * WebProcess/WebProcess.h: 32 * WebProcess/WebProcess.messages.in: 33 * WebProcess/cocoa/WebProcessCocoa.mm: 34 (WebKit::WebProcess::openDirectoryCacheInvalidated): 35 * WebProcess/com.apple.WebProcess.sb.in: 36 1 37 2022-04-26 Michael Catanzaro <mcatanzaro@redhat.com> 2 38 -
trunk/Source/WebKit/GPUProcess/GPUProcess.h
r291775 r293509 203 203 #endif 204 204 205 #if PLATFORM(MAC) 206 void openDirectoryCacheInvalidated(SandboxExtension::Handle&&); 207 #endif 208 205 209 // Connections to WebProcesses. 206 210 HashMap<WebCore::ProcessIdentifier, Ref<GPUConnectionToWebProcess>> m_webProcessConnections; -
trunk/Source/WebKit/GPUProcess/GPUProcess.messages.in
r290985 r293509 92 92 #endif 93 93 94 #if PLATFORM(MAC) 95 OpenDirectoryCacheInvalidated(WebKit::SandboxExtension::Handle handle) 96 #endif 97 94 98 WebProcessConnectionCountForTesting() -> (uint64_t count) 95 99 } -
trunk/Source/WebKit/GPUProcess/mac/GPUProcessMac.mm
r289639 r293509 98 98 #endif 99 99 } 100 101 void GPUProcess::openDirectoryCacheInvalidated(SandboxExtension::Handle&& handle) 102 { 103 AuxiliaryProcess::openDirectoryCacheInvalidated(WTFMove(handle)); 104 } 105 100 106 #endif 101 107 -
trunk/Source/WebKit/GPUProcess/mac/com.apple.WebKit.GPUProcess.sb.in
r292971 r293509 877 877 #endif 878 878 879 (allow mach-lookup 880 (require-all 881 (extension "com.apple.webkit.extension.mach") 882 (global-name "com.apple.system.opendirectoryd.libinfo"))) 883 879 884 (allow mach-lookup (with telemetry) 880 885 (global-name "com.apple.relatived.tempest") -
trunk/Source/WebKit/Shared/AuxiliaryProcess.h
r292793 r293509 29 29 #include "MessageReceiverMap.h" 30 30 #include "MessageSender.h" 31 #include "SandboxExtension.h" 31 32 #include <WebCore/ProcessIdentifier.h> 32 33 #include <WebCore/RuntimeApplicationChecks.h> … … 146 147 void applyProcessCreationParameters(const AuxiliaryProcessCreationParameters&); 147 148 149 #if PLATFORM(MAC) 150 void openDirectoryCacheInvalidated(SandboxExtension::Handle&&); 151 #endif 152 148 153 private: 149 154 virtual bool shouldOverrideQuarantine() { return true; } -
trunk/Source/WebKit/Shared/mac/AuxiliaryProcessMac.mm
r293266 r293509 666 666 } 667 667 668 static String getHomeDirectory() 669 { 670 // According to the man page for getpwuid_r, we should use sysconf(_SC_GETPW_R_SIZE_MAX) to determine the size of the buffer. 671 // However, a buffer size of 4096 should be sufficient, since PATH_MAX is 1024. 672 char buffer[4096]; 673 passwd pwd; 674 passwd* result = nullptr; 675 if (getpwuid_r(getuid(), &pwd, buffer, sizeof(buffer), &result) || !result) { 676 WTFLogAlways("%s: Couldn't find home directory", getprogname()); 677 RELEASE_ASSERT_NOT_REACHED(); 678 } 679 return String::fromUTF8(pwd.pw_dir); 680 } 681 668 682 static void populateSandboxInitializationParameters(SandboxInitializationParameters& sandboxParameters) 669 683 { … … 691 705 sandboxParameters.addConfDirectoryParameter("DARWIN_USER_CACHE_DIR", _CS_DARWIN_USER_CACHE_DIR); 692 706 693 char buffer[4096]; 694 int bufferSize = sizeof(buffer); 695 struct passwd pwd; 696 struct passwd* result = 0; 697 if (getpwuid_r(getuid(), &pwd, buffer, bufferSize, &result) || !result) { 698 WTFLogAlways("%s: Couldn't find home directory\n", getprogname()); 699 exit(EX_NOPERM); 700 } 701 702 sandboxParameters.addPathParameter("HOME_DIR", pwd.pw_dir); 703 String path = FileSystem::pathByAppendingComponent(String::fromUTF8(pwd.pw_dir), "Library"_s); 707 auto homeDirectory = getHomeDirectory(); 708 709 sandboxParameters.addPathParameter("HOME_DIR", homeDirectory); 710 String path = FileSystem::pathByAppendingComponent(homeDirectory, "Library"_s); 704 711 sandboxParameters.addPathParameter("HOME_LIBRARY_DIR", FileSystem::fileSystemRepresentation(path).data()); 705 712 path = FileSystem::pathByAppendingComponent(path, "/Preferences"_s); … … 825 832 #endif 826 833 834 void AuxiliaryProcess::openDirectoryCacheInvalidated(SandboxExtension::Handle&& handle) 835 { 836 // When Open Directory has invalidated the in-process cache for the results of getpwnam/getpwuid_r, 837 // we need to rebuild the cache by getting the home directory while holding a temporary sandbox 838 // extension to the associated Open Directory service. 839 840 auto sandboxExtension = SandboxExtension::create(WTFMove(handle)); 841 if (!sandboxExtension) 842 return; 843 844 sandboxExtension->consume(); 845 846 getHomeDirectory(); 847 848 sandboxExtension->revoke(); 849 } 850 827 851 } // namespace WebKit 828 852 -
trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm
r293266 r293509 89 89 #import "WebInspectorPreferenceObserver.h" 90 90 #import <QuartzCore/CARemoteLayerServer.h> 91 #import <notify.h> 92 #import <notify_keys.h> 91 93 #import <pal/spi/mac/NSApplicationSPI.h> 92 94 #else … … 708 710 709 711 addCFNotificationObserver(colorPreferencesDidChangeCallback, AppleColorPreferencesChangedNotification, CFNotificationCenterGetDistributedCenter()); 712 713 const char* messages[] = { kNotifyDSCacheInvalidation, kNotifyDSCacheInvalidationGroup, kNotifyDSCacheInvalidationHost, kNotifyDSCacheInvalidationService, kNotifyDSCacheInvalidationUser }; 714 m_openDirectoryNotifyTokens.reserveInitialCapacity(std::size(messages)); 715 for (auto* message : messages) { 716 int notifyToken; 717 notify_register_dispatch(message, ¬ifyToken, dispatch_get_main_queue(), ^(int token) { 718 RELEASE_LOG(Notifications, "OpenDirectory invalidated cache"); 719 auto handle = SandboxExtension::createHandleForMachLookup("com.apple.system.opendirectoryd.libinfo"_s, std::nullopt); 720 if (!handle) 721 return; 722 #if ENABLE(GPU_PROCESS) 723 if (auto* gpuProcess = GPUProcessProxy::singletonIfCreated()) 724 gpuProcess->send(Messages::GPUProcess::OpenDirectoryCacheInvalidated(*handle), 0); 725 #endif 726 sendToAllProcesses(Messages::WebProcess::OpenDirectoryCacheInvalidated(*handle)); 727 }); 728 m_openDirectoryNotifyTokens.append(notifyToken); 729 } 710 730 #elif !PLATFORM(MACCATALYST) 711 731 addCFNotificationObserver(backlightLevelDidChangeCallback, (__bridge CFStringRef)UIBacklightLevelChangedNotification); … … 771 791 [[NSNotificationCenter defaultCenter] removeObserver:m_deactivationObserver.get()]; 772 792 removeCFNotificationObserver(AppleColorPreferencesChangedNotification, CFNotificationCenterGetDistributedCenter()); 793 for (auto token : m_openDirectoryNotifyTokens) 794 notify_cancel(token); 773 795 #elif !PLATFORM(MACCATALYST) 774 796 removeCFNotificationObserver((__bridge CFStringRef)UIBacklightLevelChangedNotification); -
trunk/Source/WebKit/UIProcess/WebProcessPool.h
r293266 r293509 811 811 std::unique_ptr<WebCore::PowerObserver> m_powerObserver; 812 812 std::unique_ptr<PAL::SystemSleepListener> m_systemSleepListener; 813 Vector<int> m_openDirectoryNotifyTokens; 813 814 #endif 814 815 #if ENABLE(IPC_TESTING_API) -
trunk/Source/WebKit/WebProcess/WebProcess.h
r293329 r293509 30 30 #include "CacheModel.h" 31 31 #include "IdentifierTypes.h" 32 #include "SandboxExtension.h"33 32 #include "StorageAreaMapIdentifier.h" 34 33 #include "TextCheckerState.h" … … 354 353 #endif 355 354 355 #if PLATFORM(MAC) 356 void openDirectoryCacheInvalidated(SandboxExtension::Handle&&); 357 #endif 358 356 359 bool areAllPagesThrottleable() const; 357 360 -
trunk/Source/WebKit/WebProcess/WebProcess.messages.in
r292624 r293509 202 202 SetMediaAccessibilityPreferences(WebCore::CaptionUserPreferences::CaptionDisplayMode displayMode, Vector<String> languages) 203 203 #endif 204 205 #if PLATFORM(MAC) 206 OpenDirectoryCacheInvalidated(WebKit::SandboxExtension::Handle handle) 207 #endif 204 208 } -
trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm
r292632 r293509 1291 1291 } 1292 1292 1293 #if PLATFORM(MAC) 1294 void WebProcess::openDirectoryCacheInvalidated(SandboxExtension::Handle&& handle) 1295 { 1296 AuxiliaryProcess::openDirectoryCacheInvalidated(WTFMove(handle)); 1297 } 1298 #endif 1299 1293 1300 } // namespace WebKit 1294 1301 -
trunk/Source/WebKit/WebProcess/com.apple.WebProcess.sb.in
r292971 r293509 1467 1467 (global-name "com.apple.system.opendirectoryd.membership")) 1468 1468 ) 1469 (allow mach-lookup 1470 (require-all 1471 (extension "com.apple.webkit.extension.mach") 1472 (global-name "com.apple.system.opendirectoryd.libinfo"))) 1469 1473 #else 1470 1474 (allow file-read* file-write* (subpath "/private/var/db/mds/system")) ;; FIXME: This should be removed when <rdar://problem/9538414> is fixed.
Note: See TracChangeset
for help on using the changeset viewer.