WebKit Bugzilla
Attachment 362308 Details for
Bug 194769
: Bytecode cache should a have a boot-specific validation
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-194769-20190218203726.patch (text/plain), 6.63 KB, created by
Tadeu Zagallo
on 2019-02-18 11:38:02 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Tadeu Zagallo
Created:
2019-02-18 11:38:02 PST
Size:
6.63 KB
patch
obsolete
>Subversion Revision: 241660 >diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog >index eeff7e648620c59aa5ef2982828c5962a794065f..bdc07d10388d646f543a276ead6df66d7de8d62b 100644 >--- a/Source/JavaScriptCore/ChangeLog >+++ b/Source/JavaScriptCore/ChangeLog >@@ -1,3 +1,23 @@ >+2019-02-18 Tadeu Zagallo <tzagallo@apple.com> >+ >+ Bytecode cache should a have a boot-specific validation >+ https://bugs.webkit.org/show_bug.cgi?id=194769 >+ <rdar://problem/48149509> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add the boot UUID to the cached bytecode to enforce that it is not reused >+ across reboots. >+ >+ * runtime/CachedTypes.cpp: >+ (JSC::Encoder::malloc): >+ (JSC::GenericCacheEntry::GenericCacheEntry): >+ (JSC::GenericCacheEntry::tag const): >+ (JSC::CacheEntry::CacheEntry): >+ (JSC::CacheEntry::decode const): >+ (JSC::GenericCacheEntry::decode const): >+ (JSC::encodeCodeBlock): >+ > 2019-02-18 Tadeu Zagallo <tzagallo@apple.com> > > Add version number to cached bytecode >diff --git a/Source/WTF/ChangeLog b/Source/WTF/ChangeLog >index ad61a22c006ec06fe080dd09b84a90c38049785d..334b9f6780df5c13a65529812e54667acad43481 100644 >--- a/Source/WTF/ChangeLog >+++ b/Source/WTF/ChangeLog >@@ -1,3 +1,17 @@ >+2019-02-18 Tadeu Zagallo <tzagallo@apple.com> >+ >+ Bytecode cache should a have a boot-specific validation >+ https://bugs.webkit.org/show_bug.cgi?id=194769 >+ <rdar://problem/48149509> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add helper to get kern.bootsessionuuid from sysctl >+ >+ * wtf/UUID.cpp: >+ (WTF::bootSessionUUIDString): >+ * wtf/UUID.h: >+ > 2019-02-17 David Kilzer <ddkilzer@apple.com> > > Unreviewed, rolling out r241620. >diff --git a/Source/JavaScriptCore/runtime/CachedTypes.cpp b/Source/JavaScriptCore/runtime/CachedTypes.cpp >index ba29e6ef33c1b8eaeb82076ffbb6d4c159c8ad85..acd95dfa9650ed01346215da43799285cf4662f8 100644 >--- a/Source/JavaScriptCore/runtime/CachedTypes.cpp >+++ b/Source/JavaScriptCore/runtime/CachedTypes.cpp >@@ -41,6 +41,7 @@ > #include <wtf/FastMalloc.h> > #include <wtf/Forward.h> > #include <wtf/Optional.h> >+#include <wtf/UUID.h> > #include <wtf/text/AtomicStringImpl.h> > > namespace JSC { >@@ -102,10 +103,10 @@ public: > return malloc(size); > } > >- template<typename T> >- T* malloc() >+ template<typename T, typename... Args> >+ T* malloc(Args&&... args) > { >- return new (malloc(sizeof(T)).buffer()) T(); >+ return new (malloc(sizeof(T)).buffer()) T(std::forward<Args>(args)...); > } > > ptrdiff_t offsetOf(const void* address) >@@ -1990,20 +1991,25 @@ public: > bool decode(Decoder&, std::pair<SourceCodeKey, UnlinkedCodeBlock*>&) const; > > protected: >- GenericCacheEntry(CachedCodeBlockTag tag) >+ GenericCacheEntry(Encoder& encoder, CachedCodeBlockTag tag) > : m_tag(tag) > { >+ m_bootSessionUUID.encode(encoder, bootSessionUUIDString()); > } > >+ CachedCodeBlockTag tag() const { return m_tag; } >+ >+private: > uint32_t m_cacheVersion { JSC_BYTECODE_CACHE_VERSION }; >+ CachedString m_bootSessionUUID; > CachedCodeBlockTag m_tag; > }; > > template<typename UnlinkedCodeBlockType> > class CacheEntry : public GenericCacheEntry { > public: >- CacheEntry() >- : GenericCacheEntry(CachedCodeBlockTypeImpl<UnlinkedCodeBlockType>::tag) >+ CacheEntry(Encoder& encoder) >+ : GenericCacheEntry(encoder, CachedCodeBlockTypeImpl<UnlinkedCodeBlockType>::tag) > { > } > >@@ -2018,11 +2024,7 @@ private: > > bool decode(Decoder& decoder, std::pair<SourceCodeKey, UnlinkedCodeBlockType*>& result) const > { >- if (m_cacheVersion != JSC_BYTECODE_CACHE_VERSION) >- return false; >- ASSERT(m_tag == CachedCodeBlockTypeImpl<UnlinkedCodeBlockType>::tag); >- if (m_tag != CachedCodeBlockTypeImpl<UnlinkedCodeBlockType>::tag) >- return false; >+ ASSERT(tag() == CachedCodeBlockTypeImpl<UnlinkedCodeBlockType>::tag); > SourceCodeKey decodedKey; > m_key.decode(decoder, decodedKey); > result = { WTFMove(decodedKey), m_codeBlock.decode(decoder) }; >@@ -2035,6 +2037,11 @@ private: > > bool GenericCacheEntry::decode(Decoder& decoder, std::pair<SourceCodeKey, UnlinkedCodeBlock*>& result) const > { >+ if (m_cacheVersion != JSC_BYTECODE_CACHE_VERSION) >+ return false; >+ if (m_bootSessionUUID.decode(decoder) != bootSessionUUIDString()) >+ return false; >+ > switch (m_tag) { > case CachedProgramCodeBlockTag: > return reinterpret_cast<const CacheEntry<UnlinkedProgramCodeBlock>*>(this)->decode(decoder, reinterpret_cast<std::pair<SourceCodeKey, UnlinkedProgramCodeBlock*>&>(result)); >@@ -2054,7 +2061,7 @@ bool GenericCacheEntry::decode(Decoder& decoder, std::pair<SourceCodeKey, Unlink > template<typename UnlinkedCodeBlockType> > void encodeCodeBlock(Encoder& encoder, const SourceCodeKey& key, const UnlinkedCodeBlock* codeBlock) > { >- auto* entry = encoder.template malloc<CacheEntry<UnlinkedCodeBlockType>>(); >+ auto* entry = encoder.template malloc<CacheEntry<UnlinkedCodeBlockType>>(encoder); > entry->encode(encoder, { key, jsCast<const UnlinkedCodeBlockType*>(codeBlock) }); > } > >diff --git a/Source/WTF/wtf/UUID.cpp b/Source/WTF/wtf/UUID.cpp >index 48d64ffb4e2a58b9b486de60d77554d222323d37..3f837d210231a8c2cd088fb0e7dbfd6dcf335b49 100644 >--- a/Source/WTF/wtf/UUID.cpp >+++ b/Source/WTF/wtf/UUID.cpp >@@ -31,10 +31,15 @@ > #include "config.h" > #include <wtf/UUID.h> > >+#include <mutex> > #include <wtf/CryptographicallyRandomNumber.h> > #include <wtf/HexNumber.h> > #include <wtf/text/StringBuilder.h> > >+#if OS(DARWIN) >+#include <sys/sysctl.h> >+#endif >+ > namespace WTF { > > String createCanonicalUUIDString() >@@ -59,4 +64,20 @@ String createCanonicalUUIDString() > return builder.toString(); > } > >+String bootSessionUUIDString() >+{ >+ static LazyNeverDestroyed<String> bootSessionUUID; >+#if OS(DARWIN) >+ static std::once_flag onceKey; >+ std::call_once(onceKey, [] { >+ size_t uuidLength = 37; >+ char uuid[uuidLength]; >+ if (sysctlbyname("kern.bootsessionuuid", uuid, &uuidLength, nullptr, 0)) >+ return; >+ bootSessionUUID.construct(String(uuid, 36)); >+ }); >+#endif >+ return bootSessionUUID; >+} >+ > } // namespace WTF >diff --git a/Source/WTF/wtf/UUID.h b/Source/WTF/wtf/UUID.h >index 8a78755e998f941292dd4a3c71ff862b73faafd8..6acd4624d7df1a439b48750eb64a728a47e34adb 100644 >--- a/Source/WTF/wtf/UUID.h >+++ b/Source/WTF/wtf/UUID.h >@@ -45,6 +45,9 @@ namespace WTF { > > WTF_EXPORT_PRIVATE String createCanonicalUUIDString(); > >+WTF_EXPORT_PRIVATE String bootSessionUUIDString(); >+ > } > > using WTF::createCanonicalUUIDString; >+using WTF::bootSessionUUIDString;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 194769
:
362267
|
362278
|
362289
|
362308
|
362310