Changeset 244921 in webkit


Ignore:
Timestamp:
May 3, 2019 2:24:06 PM (5 years ago)
Author:
sihui_liu@apple.com
Message:

Add assertion to check whether shm files have maximum FileProtection of CompleteUnlessOpen
https://bugs.webkit.org/show_bug.cgi?id=197390
<rdar://problem/42685773>

Reviewed by Geoffrey Garen.

Source/WebCore:

We have seen crashes about accessing database files after device is locked. We are suspecting this is because
shm files have wrong data protection class, but shm files should not have Complete class protection when it
is created. It is likely the protection class is changed later. Add an assertion to verify our guess. If the
crash signature changes after this patch, we probably need to change database implementation. If it is not, we
have other problem than data protection.

  • platform/sql/SQLiteDatabase.cpp:

(WebCore::SQLiteDatabase::open):

Source/WebKit:

Move data protection check to WebCore so it can be applied to database files.

  • NetworkProcess/cache/NetworkCacheBlobStorage.cpp:

(WebKit::NetworkCache::BlobStorage::add):

  • NetworkProcess/cache/NetworkCacheFileSystem.cpp:

(WebKit::NetworkCache::makeSafeToUseMemoryMapForPath): Deleted.

  • NetworkProcess/cache/NetworkCacheFileSystem.h:
  • NetworkProcess/cache/NetworkCacheFileSystemCocoa.mm: Removed.
  • SourcesCocoa.txt:
  • UIProcess/API/APIContentRuleListStore.cpp:

(API::openAndMapOrCopyContentRuleList):
(API::compiledToFile):

Source/WTF:

  • wtf/FileSystem.cpp:

(WTF::FileSystemImpl::isSafeToUseMemoryMapForPath):
(WTF::FileSystemImpl::makeSafeToUseMemoryMapForPath):

  • wtf/FileSystem.h:
  • wtf/cocoa/FileSystemCocoa.mm:

(WTF::FileSystemImpl::isSafeToUseMemoryMapForPath):
(WTF::FileSystemImpl::makeSafeToUseMemoryMapForPath):

Location:
trunk/Source
Files:
1 deleted
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r244907 r244921  
     12019-05-03  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Add assertion to check whether shm files have maximum FileProtection of CompleteUnlessOpen
     4        https://bugs.webkit.org/show_bug.cgi?id=197390
     5        <rdar://problem/42685773>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        * wtf/FileSystem.cpp:
     10        (WTF::FileSystemImpl::isSafeToUseMemoryMapForPath):
     11        (WTF::FileSystemImpl::makeSafeToUseMemoryMapForPath):
     12        * wtf/FileSystem.h:
     13        * wtf/cocoa/FileSystemCocoa.mm:
     14        (WTF::FileSystemImpl::isSafeToUseMemoryMapForPath):
     15        (WTF::FileSystemImpl::makeSafeToUseMemoryMapForPath):
     16
    1172019-05-03  Commit Queue  <commit-queue@webkit.org>
    218
  • trunk/Source/WTF/wtf/FileSystem.cpp

    r240437 r244921  
    364364}
    365365
     366#if !PLATFORM(IOS_FAMILY)
     367bool isSafeToUseMemoryMapForPath(const String&)
     368{
     369    return true;
     370}
     371
     372void makeSafeToUseMemoryMapForPath(const String&)
     373{
     374}
     375#endif
     376
    366377} // namespace FileSystemImpl
    367378} // namespace WTF
  • trunk/Source/WTF/wtf/FileSystem.h

    r240600 r244921  
    188188WTF_EXPORT_PRIVATE String realPath(const String&);
    189189
     190WTF_EXPORT_PRIVATE bool isSafeToUseMemoryMapForPath(const String&);
     191WTF_EXPORT_PRIVATE void makeSafeToUseMemoryMapForPath(const String&);
     192
    190193class MappedFileData {
    191194public:
  • trunk/Source/WTF/wtf/cocoa/FileSystemCocoa.mm

    r240437 r244921  
    140140}
    141141
     142#if PLATFORM(IOS_FAMILY)
     143bool isSafeToUseMemoryMapForPath(const String& path)
     144{
     145    NSError *error = nil;
     146    NSDictionary<NSFileAttributeKey, id> *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:&error];
     147    if (error) {
     148        LOG_ERROR("Unable to get path protection class");
     149        return false;
     150    }
     151    if ([[attributes objectForKey:NSFileProtectionKey] isEqualToString:NSFileProtectionComplete]) {
     152        LOG_ERROR("Path protection class is NSFileProtectionComplete, so it is not safe to use memory map");
     153        return false;
     154    }
     155    return true;
     156}
     157
     158void makeSafeToUseMemoryMapForPath(const String& path)
     159{
     160    if (isSafeToUseMemoryMapForPath(path))
     161        return;
     162   
     163    NSError *error = nil;
     164    BOOL success = [[NSFileManager defaultManager] setAttributes:@{ NSFileProtectionKey: NSFileProtectionCompleteUnlessOpen } ofItemAtPath:path error:&error];
     165    ASSERT(!error);
     166    ASSERT_UNUSED(success, success);
     167}
     168#endif
     169
    142170} // namespace FileSystemImpl
    143171} // namespace WTF
  • trunk/Source/WebCore/ChangeLog

    r244918 r244921  
     12019-05-03  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Add assertion to check whether shm files have maximum FileProtection of CompleteUnlessOpen
     4        https://bugs.webkit.org/show_bug.cgi?id=197390
     5        <rdar://problem/42685773>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        We have seen crashes about accessing database files after device is locked. We are suspecting this is because
     10        shm files have wrong data protection class, but shm files should not have Complete class protection when it
     11        is created. It is likely the protection class is changed later. Add an assertion to verify our guess. If the
     12        crash signature changes after this patch, we probably need to change database implementation. If it is not, we
     13        have other problem than data protection.
     14
     15        * platform/sql/SQLiteDatabase.cpp:
     16        (WebCore::SQLiteDatabase::open):
     17
    1182019-05-03  Youenn Fablet  <youenn@apple.com>
    219
  • trunk/Source/WebCore/platform/sql/SQLiteDatabase.cpp

    r243939 r244921  
    149149    if (openMode != OpenMode::ReadOnly)
    150150        useWALJournalMode();
     151
     152    String shmFileName = makeString(filename, "-shm"_s);
     153    if (FileSystem::fileExists(shmFileName))
     154        RELEASE_ASSERT(FileSystem::isSafeToUseMemoryMapForPath(shmFileName));
    151155
    152156    return isOpen();
  • trunk/Source/WebKit/ChangeLog

    r244920 r244921  
     12019-05-03  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Add assertion to check whether shm files have maximum FileProtection of CompleteUnlessOpen
     4        https://bugs.webkit.org/show_bug.cgi?id=197390
     5        <rdar://problem/42685773>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        Move data protection check to WebCore so it can be applied to database files.
     10
     11        * NetworkProcess/cache/NetworkCacheBlobStorage.cpp:
     12        (WebKit::NetworkCache::BlobStorage::add):
     13        * NetworkProcess/cache/NetworkCacheFileSystem.cpp:
     14        (WebKit::NetworkCache::makeSafeToUseMemoryMapForPath): Deleted.
     15        * NetworkProcess/cache/NetworkCacheFileSystem.h:
     16        * NetworkProcess/cache/NetworkCacheFileSystemCocoa.mm: Removed.
     17        * SourcesCocoa.txt:
     18        * UIProcess/API/APIContentRuleListStore.cpp:
     19        (API::openAndMapOrCopyContentRuleList):
     20        (API::compiledToFile):
     21
    1222019-05-03  Chris Dumez  <cdumez@apple.com>
    223
  • trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheBlobStorage.cpp

    r244678 r244921  
    9595
    9696    String blobPathString = blobPathForHash(hash);
    97     makeSafeToUseMemoryMapForPath(blobPathString);
     97    FileSystem::makeSafeToUseMemoryMapForPath(blobPathString);
    9898   
    9999    auto blobPath = FileSystem::fileSystemRepresentation(blobPathString);
  • trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.cpp

    r244678 r244921  
    146146}
    147147
    148 #if !PLATFORM(IOS_FAMILY)
    149 void makeSafeToUseMemoryMapForPath(const String&)
    150 {
    151 }
    152 #endif
    153 
    154148}
    155149}
  • trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.h

    r244678 r244921  
    4343void updateFileModificationTimeIfNeeded(const String& path);
    4444
    45 void makeSafeToUseMemoryMapForPath(const String&);
    46 
    4745}
    4846}
  • trunk/Source/WebKit/SourcesCocoa.txt

    r244747 r244921  
    2323
    2424NetworkProcess/cache/NetworkCacheDataCocoa.mm
    25 NetworkProcess/cache/NetworkCacheFileSystemCocoa.mm
    2625NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm
    2726
  • trunk/Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp

    r244597 r244921  
    209209static Optional<MappedData> openAndMapOrCopyContentRuleList(const WTF::String& path)
    210210{
    211     WebKit::NetworkCache::makeSafeToUseMemoryMapForPath(path);
     211    FileSystem::makeSafeToUseMemoryMapForPath(path);
    212212    WebKit::NetworkCache::Data fileData = mapFile(fileSystemRepresentation(path).data());
    213213    if (fileData.isNull())
     
    387387    }
    388388   
    389     makeSafeToUseMemoryMapForPath(finalFilePath);
     389    FileSystem::makeSafeToUseMemoryMapForPath(finalFilePath);
    390390   
    391391    return {{ WTFMove(metaData), WTFMove(mappedData) }};
Note: See TracChangeset for help on using the changeset viewer.