Changeset 260913 in webkit
- Timestamp:
- Apr 29, 2020, 1:39:03 PM (5 years ago)
- Location:
- trunk/Source
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r260906 r260913 1 2020-04-29 Mark Lam <mark.lam@apple.com> 2 3 Freezing of Gigacage and JSC Configs should be thread safe. 4 https://bugs.webkit.org/show_bug.cgi?id=211201 5 <rdar://problem/62597619> 6 7 Reviewed by Yusuke Suzuki. 8 9 If a client creates multiple VM instances in different threads concurrently, the 10 following race can occur: 11 12 Config::permanentlyFreeze() contains the following code: 13 14 if (!g_jscConfig.isPermanentlyFrozen) // Point P1 15 g_jscConfig.isPermanentlyFrozen = true; // Point P2 16 17 Let's say there are 2 threads T1 and T2. 18 19 1. T1 creates a VM and gets to point P1, and sees that g_jscConfig.isPermanentlyFrozen is not set. 20 T1 is about to execute P2 when it gets pre-empted. 21 22 2. T2 creates a VM and gets to point P1, and sees that g_jscConfig.isPermanentlyFrozen is not set. 23 T2 proceeds to point P2 and sets g_jscConfig.isPermanentlyFrozen to true. 24 T2 goes on to freeze the Config and makes it not writable. 25 26 3. T1 gets to run again, and proceeds to point P2. 27 T1 tries to set g_jscConfig.isPermanentlyFrozen to true. 28 But because the Config has been frozen against writes, the write to 29 g_jscConfig.isPermanentlyFrozen results in a crash. 30 31 This is a classic TOCTOU bug. The fix is simply to ensure that only one thread 32 can enter Config::permanentlyFreeze() at a time. 33 34 Ditto for Gigacage::permanentlyFreezeGigacageConfig(). 35 36 * runtime/JSCConfig.cpp: 37 (JSC::Config::permanentlyFreeze): 38 1 39 2020-04-29 Yusuke Suzuki <ysuzuki@apple.com> 2 40 -
trunk/Source/JavaScriptCore/runtime/JSCConfig.cpp
r258857 r260913 1 1 /* 2 * Copyright (C) 2019 Apple Inc. All rights reserved.2 * Copyright (C) 2019-2020 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 27 27 #include "JSCConfig.h" 28 28 29 #include <wtf/Lock.h> 29 30 #include <wtf/ResourceUsage.h> 30 31 #include <wtf/StdLibExtras.h> … … 54 55 void Config::permanentlyFreeze() 55 56 { 57 static Lock configLock; 58 auto locker = holdLock(configLock); 59 56 60 RELEASE_ASSERT(roundUpToMultipleOf(pageSize(), ConfigSizeToProtect) == ConfigSizeToProtect); 57 61 -
trunk/Source/bmalloc/ChangeLog
r260712 r260913 1 2020-04-29 Mark Lam <mark.lam@apple.com> 2 3 Freezing of Gigacage and JSC Configs should be thread safe. 4 https://bugs.webkit.org/show_bug.cgi?id=211201 5 <rdar://problem/62597619> 6 7 Reviewed by Yusuke Suzuki. 8 9 * bmalloc/Gigacage.cpp: 10 (Gigacage::bmalloc::permanentlyFreezeGigacageConfig): 11 1 12 2020-04-25 Darin Adler <darin@apple.com> 2 13 -
trunk/Source/bmalloc/bmalloc/Gigacage.cpp
r254781 r260913 1 1 /* 2 * Copyright (C) 2017-20 19Apple Inc. All rights reserved.2 * Copyright (C) 2017-2020 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 28 28 #include "CryptoRandom.h" 29 29 #include "Environment.h" 30 #include "Mutex.h" 30 31 #include "ProcessCheck.h" 31 32 #include "StaticPerProcess.h" … … 34 35 #include "bmalloc.h" 35 36 #include <cstdio> 36 #include <mutex>37 37 38 38 #if BOS(DARWIN) … … 118 118 static void permanentlyFreezeGigacageConfig() 119 119 { 120 static Mutex configLock; 121 LockHolder locking(configLock); 122 120 123 if (!g_gigacageConfig.isPermanentlyFrozen) { 121 124 unfreezeGigacageConfig();
Note:
See TracChangeset
for help on using the changeset viewer.