diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog index 54da0935a2cd..b1ee198dd099 100644 --- a/Source/JavaScriptCore/ChangeLog +++ b/Source/JavaScriptCore/ChangeLog @@ -1,3 +1,23 @@ +2019-02-18 Tadeu Zagallo + + Bytecode cache should a have a boot-specific validation + https://bugs.webkit.org/show_bug.cgi?id=194769 + + + Reviewed by Keith Miller. + + 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-16 Yusuke Suzuki [JSC] JSWrapperObject should not be destructible diff --git a/Source/JavaScriptCore/runtime/CachedTypes.cpp b/Source/JavaScriptCore/runtime/CachedTypes.cpp index ba29e6ef33c1..acd95dfa9650 100644 --- a/Source/JavaScriptCore/runtime/CachedTypes.cpp +++ b/Source/JavaScriptCore/runtime/CachedTypes.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include namespace JSC { @@ -102,10 +103,10 @@ class Encoder { return malloc(size); } - template - T* malloc() + template + T* malloc(Args&&... args) { - return new (malloc(sizeof(T)).buffer()) T(); + return new (malloc(sizeof(T)).buffer()) T(std::forward(args)...); } ptrdiff_t offsetOf(const void* address) @@ -1990,20 +1991,25 @@ class GenericCacheEntry { bool decode(Decoder&, std::pair&) 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 class CacheEntry : public GenericCacheEntry { public: - CacheEntry() - : GenericCacheEntry(CachedCodeBlockTypeImpl::tag) + CacheEntry(Encoder& encoder) + : GenericCacheEntry(encoder, CachedCodeBlockTypeImpl::tag) { } @@ -2018,11 +2024,7 @@ class CacheEntry : public GenericCacheEntry { bool decode(Decoder& decoder, std::pair& result) const { - if (m_cacheVersion != JSC_BYTECODE_CACHE_VERSION) - return false; - ASSERT(m_tag == CachedCodeBlockTypeImpl::tag); - if (m_tag != CachedCodeBlockTypeImpl::tag) - return false; + ASSERT(tag() == CachedCodeBlockTypeImpl::tag); SourceCodeKey decodedKey; m_key.decode(decoder, decodedKey); result = { WTFMove(decodedKey), m_codeBlock.decode(decoder) }; @@ -2035,6 +2037,11 @@ class CacheEntry : public GenericCacheEntry { bool GenericCacheEntry::decode(Decoder& decoder, std::pair& 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*>(this)->decode(decoder, reinterpret_cast&>(result)); @@ -2054,7 +2061,7 @@ bool GenericCacheEntry::decode(Decoder& decoder, std::pair void encodeCodeBlock(Encoder& encoder, const SourceCodeKey& key, const UnlinkedCodeBlock* codeBlock) { - auto* entry = encoder.template malloc>(); + auto* entry = encoder.template malloc>(encoder); entry->encode(encoder, { key, jsCast(codeBlock) }); } diff --git a/Source/WTF/ChangeLog b/Source/WTF/ChangeLog index 89334ac7c614..672a964d442c 100644 --- a/Source/WTF/ChangeLog +++ b/Source/WTF/ChangeLog @@ -1,3 +1,17 @@ +2019-02-18 Tadeu Zagallo + + Bytecode cache should a have a boot-specific validation + https://bugs.webkit.org/show_bug.cgi?id=194769 + + + Reviewed by Keith Miller. + + Add helper to get kern.bootsessionuuid from sysctl + + * wtf/UUID.cpp: + (WTF::bootSessionUUIDString): + * wtf/UUID.h: + 2019-02-15 Dominik Infuehr Fix deadlock on Linux/x64 between SamplingProfiler and VMTraps diff --git a/Source/WTF/wtf/UUID.cpp b/Source/WTF/wtf/UUID.cpp index 48d64ffb4e2a..85968bf59116 100644 --- a/Source/WTF/wtf/UUID.cpp +++ b/Source/WTF/wtf/UUID.cpp @@ -31,10 +31,15 @@ #include "config.h" #include +#include #include #include #include +#if OS(DARWIN) +#include +#endif + namespace WTF { String createCanonicalUUIDString() @@ -59,4 +64,20 @@ String createCanonicalUUIDString() return builder.toString(); } +String bootSessionUUIDString() +{ + static LazyNeverDestroyed 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(static_cast(uuid), uuidLength - 1); + }); +#endif + return bootSessionUUID; +} + } // namespace WTF diff --git a/Source/WTF/wtf/UUID.h b/Source/WTF/wtf/UUID.h index 8a78755e998f..6acd4624d7df 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; diff --git a/Tools/ChangeLog b/Tools/ChangeLog index 5df658ef89d5..c7298b4472b5 100644 --- a/Tools/ChangeLog +++ b/Tools/ChangeLog @@ -1,3 +1,17 @@ +2019-02-18 Tadeu Zagallo + + Bytecode cache should a have a boot-specific validation + https://bugs.webkit.org/show_bug.cgi?id=194769 + + + Reviewed by Keith Miller. + + Add test for WTF::bootSessionUUIDString() + + * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: + * TestWebKitAPI/Tests/WTF/UUID.cpp: Added. + (TEST): + 2019-02-16 Zalan Bujtas [LFC] Apply min/max width constraints to preferred width computation diff --git a/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj b/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj index 7c6e12360b21..00a5fdb98e56 100644 --- a/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj +++ b/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj @@ -1352,6 +1352,7 @@ 11B7FD22219F46DD0069B27F /* FirstMeaningfulPaintMilestone.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FirstMeaningfulPaintMilestone.cpp; sourceTree = ""; }; 11C2598C21FA618D004C9E23 /* async-script-load.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "async-script-load.html"; sourceTree = ""; }; 14464012167A8305000BD218 /* LayoutUnit.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LayoutUnit.cpp; sourceTree = ""; }; + 144D40EC221B46A7004B474F /* UUID.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UUID.cpp; sourceTree = ""; }; 14F3B11215E45EAB00210069 /* SaturatedArithmeticOperations.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SaturatedArithmeticOperations.cpp; sourceTree = ""; }; 1A02C84B125D4A5E00E3F4BD /* find.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = find.html; sourceTree = ""; }; 1A02C84E125D4A8400E3F4BD /* Find.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Find.cpp; sourceTree = ""; }; @@ -3292,6 +3293,7 @@ 5C5E633D1D0B67940085A025 /* UniqueRef.cpp */, E3A1E78021B25B79008C6007 /* URL.cpp */, E3A1E78421B25B91008C6007 /* URLParser.cpp */, + 144D40EC221B46A7004B474F /* UUID.cpp */, 7CD0D5AA1D5534DE000CC9E1 /* Variant.cpp */, BC55F5F814AD78EE00484BE1 /* Vector.cpp */, 1CB9BC371A67482300FE5678 /* WeakPtr.cpp */, diff --git a/Tools/TestWebKitAPI/Tests/WTF/UUID.cpp b/Tools/TestWebKitAPI/Tests/WTF/UUID.cpp new file mode 100644 index 000000000000..d7de3afc870f --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WTF/UUID.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2019 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#include + +TEST(WTF, BootSessionUUIDIdentity) +{ + EXPECT_EQ(bootSessionUUIDString(), bootSessionUUIDString()); +}