<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[212244] trunk/Source/WebKit2</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/212244">212244</a></dd>
<dt>Author</dt> <dd>antti@apple.com</dd>
<dt>Date</dt> <dd>2017-02-13 13:30:21 -0800 (Mon, 13 Feb 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Disable mmap'd cache files if container is class A
https://bugs.webkit.org/show_bug.cgi?id=168241
&lt;rdar://problem/23676252&gt;

Reviewed by JF Bastien and Chris Dumez.

If the mmap'd cache file gets evicted and the device is locked,
then WebContent won't be able to bring the file back in under
class A, causing SIGBUS.

In those circumstances, don't use mmap'd files.

* NetworkProcess/cache/NetworkCache.h:
(WebKit::NetworkCache::Cache::canUseSharedMemoryForBodyData):
* NetworkProcess/cache/NetworkCacheEntry.cpp:
(WebKit::NetworkCache::Entry::initializeShareableResourceHandleFromStorageRecord):

    Don't initialize the shareable resource handle for the map if forbidden.

* NetworkProcess/cache/NetworkCacheFileSystem.cpp:
(WebKit::NetworkCache::canUseSharedMemoryForPath):

    Query the system for the protection status of the cache path.

* NetworkProcess/cache/NetworkCacheFileSystem.h:
* NetworkProcess/cache/NetworkCacheStorage.cpp:
(WebKit::NetworkCache::Storage::Storage):
* NetworkProcess/cache/NetworkCacheStorage.h:
(WebKit::NetworkCache::Storage::canUseSharedMemoryForBodyData):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCachecpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheh">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheEntrycpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheFileSystemcpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheFileSystem.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheFileSystemh">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheFileSystem.h</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheStoragecpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheStorageh">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (212243 => 212244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2017-02-13 21:11:36 UTC (rev 212243)
+++ trunk/Source/WebKit2/ChangeLog        2017-02-13 21:30:21 UTC (rev 212244)
</span><span class="lines">@@ -1,3 +1,35 @@
</span><ins>+2017-02-13  Antti Koivisto  &lt;antti@apple.com&gt;
+
+        Disable mmap'd cache files if container is class A
+        https://bugs.webkit.org/show_bug.cgi?id=168241
+        &lt;rdar://problem/23676252&gt;
+
+        Reviewed by JF Bastien and Chris Dumez.
+
+        If the mmap'd cache file gets evicted and the device is locked,
+        then WebContent won't be able to bring the file back in under
+        class A, causing SIGBUS.
+
+        In those circumstances, don't use mmap'd files.
+
+        * NetworkProcess/cache/NetworkCache.h:
+        (WebKit::NetworkCache::Cache::canUseSharedMemoryForBodyData):
+        * NetworkProcess/cache/NetworkCacheEntry.cpp:
+        (WebKit::NetworkCache::Entry::initializeShareableResourceHandleFromStorageRecord):
+
+            Don't initialize the shareable resource handle for the map if forbidden.
+
+        * NetworkProcess/cache/NetworkCacheFileSystem.cpp:
+        (WebKit::NetworkCache::canUseSharedMemoryForPath):
+
+            Query the system for the protection status of the cache path.
+
+        * NetworkProcess/cache/NetworkCacheFileSystem.h:
+        * NetworkProcess/cache/NetworkCacheStorage.cpp:
+        (WebKit::NetworkCache::Storage::Storage):
+        * NetworkProcess/cache/NetworkCacheStorage.h:
+        (WebKit::NetworkCache::Storage::canUseSharedMemoryForBodyData):
+
</ins><span class="cx"> 2017-02-13  Youenn Fablet  &lt;youennf@gmail.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [WebRTC] libwebrtc socket factory is not assigning the right socket type
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCachecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp (212243 => 212244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp        2017-02-13 21:11:36 UTC (rev 212243)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp        2017-02-13 21:30:21 UTC (rev 212244)
</span><span class="lines">@@ -382,13 +382,15 @@
</span><span class="cx">     auto cacheEntry = makeEntry(request, response, WTFMove(responseData));
</span><span class="cx">     auto record = cacheEntry-&gt;encodeAsStorageRecord();
</span><span class="cx"> 
</span><del>-    m_storage-&gt;store(record, [completionHandler = WTFMove(completionHandler)](const Data&amp; bodyData) {
</del><ins>+    m_storage-&gt;store(record, [this, completionHandler = WTFMove(completionHandler)](const Data&amp; bodyData) {
</ins><span class="cx">         MappedBody mappedBody;
</span><span class="cx"> #if ENABLE(SHAREABLE_RESOURCE)
</span><del>-        if (auto sharedMemory = bodyData.tryCreateSharedMemory()) {
-            mappedBody.shareableResource = ShareableResource::create(sharedMemory.releaseNonNull(), 0, bodyData.size());
-            ASSERT(mappedBody.shareableResource);
-            mappedBody.shareableResource-&gt;createHandle(mappedBody.shareableResourceHandle);
</del><ins>+        if (canUseSharedMemoryForBodyData()) {
+            if (auto sharedMemory = bodyData.tryCreateSharedMemory()) {
+                mappedBody.shareableResource = ShareableResource::create(sharedMemory.releaseNonNull(), 0, bodyData.size());
+                ASSERT(mappedBody.shareableResource);
+                mappedBody.shareableResource-&gt;createHandle(mappedBody.shareableResourceHandle);
+            }
</ins><span class="cx">         }
</span><span class="cx"> #endif
</span><span class="cx">         completionHandler(mappedBody);
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h (212243 => 212244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h        2017-02-13 21:11:36 UTC (rev 212243)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h        2017-02-13 21:30:21 UTC (rev 212244)
</span><span class="lines">@@ -130,6 +130,7 @@
</span><span class="cx">     void dumpContentsToFile();
</span><span class="cx"> 
</span><span class="cx">     String recordsPath() const;
</span><ins>+    bool canUseSharedMemoryForBodyData() const { return m_storage &amp;&amp; m_storage-&gt;canUseSharedMemoryForBodyData(); }
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
</span><span class="cx">     SpeculativeLoadManager* speculativeLoadManager() { return m_speculativeLoadManager.get(); }
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheEntrycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp (212243 => 212244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp        2017-02-13 21:11:36 UTC (rev 212243)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp        2017-02-13 21:30:21 UTC (rev 212244)
</span><span class="lines">@@ -146,6 +146,9 @@
</span><span class="cx"> #if ENABLE(SHAREABLE_RESOURCE)
</span><span class="cx"> void Entry::initializeShareableResourceHandleFromStorageRecord() const
</span><span class="cx"> {
</span><ins>+    if (!NetworkCache::singleton().canUseSharedMemoryForBodyData())
+        return;
+
</ins><span class="cx">     auto sharedMemory = m_sourceStorageRecord.body.tryCreateSharedMemory();
</span><span class="cx">     if (!sharedMemory)
</span><span class="cx">         return;
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheFileSystemcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheFileSystem.cpp (212243 => 212244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheFileSystem.cpp        2017-02-13 21:11:36 UTC (rev 212243)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheFileSystem.cpp        2017-02-13 21:30:21 UTC (rev 212244)
</span><span class="lines">@@ -28,13 +28,20 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(NETWORK_CACHE)
</span><span class="cx"> 
</span><ins>+#include &quot;Logging.h&quot;
</ins><span class="cx"> #include &lt;WebCore/FileSystem.h&gt;
</span><span class="cx"> #include &lt;dirent.h&gt;
</span><span class="cx"> #include &lt;sys/stat.h&gt;
</span><span class="cx"> #include &lt;sys/time.h&gt;
</span><ins>+#include &lt;wtf/Assertions.h&gt;
</ins><span class="cx"> #include &lt;wtf/Function.h&gt;
</span><span class="cx"> #include &lt;wtf/text/CString.h&gt;
</span><span class="cx"> 
</span><ins>+#if PLATFORM(IOS) &amp;&amp; !PLATFORM(IOS_SIMULATOR)
+#include &lt;sys/attr.h&gt;
+#include &lt;unistd.h&gt;
+#endif
+
</ins><span class="cx"> #if USE(SOUP)
</span><span class="cx"> #include &lt;gio/gio.h&gt;
</span><span class="cx"> #include &lt;wtf/glib/GRefPtr.h&gt;
</span><span class="lines">@@ -126,7 +133,38 @@
</span><span class="cx">     utimes(WebCore::fileSystemRepresentation(path).data(), nullptr);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool canUseSharedMemoryForPath(const String&amp; path)
+{
+#if PLATFORM(IOS) &amp;&amp; !PLATFORM(IOS_SIMULATOR)
+    struct {
+        uint32_t length;
+        uint32_t protectionClass;
+    } attrBuffer;
+
+    attrlist attrList = { };
+    attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
+    attrList.commonattr = ATTR_CMN_DATA_PROTECT_FLAGS;
+    int32_t error = getattrlist(WebCore::fileSystemRepresentation(path).data(), &amp;attrList, &amp;attrBuffer, sizeof(attrBuffer), FSOPT_NOFOLLOW);
+    if (error) {
+        RELEASE_LOG_ERROR(Network, &quot;Unable to get cache directory protection class, disabling use of shared mapped memory&quot;);
+        return false;
+    }
+
+    // For stricter protection classes shared maps could disappear when device is locked.
+    const uint32_t fileProtectionCompleteUntilFirstUserAuthentication = 3;
+    bool isSafe = attrBuffer.protectionClass &gt;= fileProtectionCompleteUntilFirstUserAuthentication;
+
+    if (!isSafe)
+        RELEASE_LOG(Network, &quot;Disallowing use of shared mapped memory due to container protection class %u&quot;, attrBuffer.protectionClass);
+
+    return isSafe;
+#else
+    UNUSED_PARAM(path);
+    return true;
+#endif
</ins><span class="cx"> }
</span><ins>+
</ins><span class="cx"> }
</span><ins>+}
</ins><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(NETWORK_CACHE)
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheFileSystemh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheFileSystem.h (212243 => 212244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheFileSystem.h        2017-02-13 21:11:36 UTC (rev 212243)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheFileSystem.h        2017-02-13 21:30:21 UTC (rev 212244)
</span><span class="lines">@@ -46,6 +46,8 @@
</span><span class="cx"> FileTimes fileTimes(const String&amp; path);
</span><span class="cx"> void updateFileModificationTimeIfNeeded(const String&amp; path);
</span><span class="cx"> 
</span><ins>+bool canUseSharedMemoryForPath(const String&amp; path);
+
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheStoragecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp (212243 => 212244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp        2017-02-13 21:11:36 UTC (rev 212243)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp        2017-02-13 21:30:21 UTC (rev 212244)
</span><span class="lines">@@ -211,6 +211,7 @@
</span><span class="cx">     : m_basePath(baseDirectoryPath)
</span><span class="cx">     , m_recordsPath(makeRecordsDirectoryPath(baseDirectoryPath))
</span><span class="cx">     , m_salt(salt)
</span><ins>+    , m_canUseSharedMemoryForBodyData(canUseSharedMemoryForPath(baseDirectoryPath))
</ins><span class="cx">     , m_readOperationTimeoutTimer(*this, &amp;Storage::cancelAllReadOperations)
</span><span class="cx">     , m_writeOperationDispatchTimer(*this, &amp;Storage::dispatchPendingWriteOperations)
</span><span class="cx">     , m_ioQueue(WorkQueue::create(&quot;com.apple.WebKit.Cache.Storage&quot;, WorkQueue::Type::Concurrent))
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheStorageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h (212243 => 212244)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h        2017-02-13 21:11:36 UTC (rev 212243)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h        2017-02-13 21:30:21 UTC (rev 212244)
</span><span class="lines">@@ -100,6 +100,8 @@
</span><span class="cx"> 
</span><span class="cx">     const Salt&amp; salt() const { return m_salt; }
</span><span class="cx"> 
</span><ins>+    bool canUseSharedMemoryForBodyData() const { return m_canUseSharedMemoryForBodyData; }
+
</ins><span class="cx">     ~Storage();
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="lines">@@ -146,6 +148,8 @@
</span><span class="cx"> 
</span><span class="cx">     const Salt m_salt;
</span><span class="cx"> 
</span><ins>+    const bool m_canUseSharedMemoryForBodyData;
+
</ins><span class="cx">     size_t m_capacity { std::numeric_limits&lt;size_t&gt;::max() };
</span><span class="cx">     size_t m_approximateRecordsSize { 0 };
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>