-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdom_storage_blink_patch.diff
359 lines (328 loc) · 13 KB
/
dom_storage_blink_patch.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
diff --git a/third_party/blink/renderer/platform/bindings/to_blink_string.cc b/third_party/blink/renderer/platform/bindings/to_blink_string.cc
index 4de6efb2ac..bf2ee97eb4 100644
--- a/third_party/blink/renderer/platform/bindings/to_blink_string.cc
+++ b/third_party/blink/renderer/platform/bindings/to_blink_string.cc
@@ -18,6 +18,10 @@ struct StringTraits {
static const StringClass& FromStringResource(StringResourceBase*);
template <typename V8StringTrait>
static StringClass FromV8String(v8::Isolate*, v8::Local<v8::String>, int);
+
+ // PanoptiChrome
+ static void setTaint(StringClass& string);
+ static void setData(StringClass& string, std::string data);
};
template <>
@@ -27,6 +31,12 @@ struct StringTraits<String> {
}
template <typename V8StringTrait>
static String FromV8String(v8::Isolate*, v8::Local<v8::String>, int);
+
+ // PanoptiChrome
+ static void setTaint(String& string) { string.Impl()->setTaint(); }
+ static void setData(String& string, std::string data) {
+ string.Impl()->setData(data);
+ }
};
template <>
@@ -36,6 +46,12 @@ struct StringTraits<AtomicString> {
}
template <typename V8StringTrait>
static AtomicString FromV8String(v8::Isolate*, v8::Local<v8::String>, int);
+
+ // PanoptiChrome
+ static void setTaint(AtomicString& string) { string.Impl()->setTaint(); }
+ static void setData(AtomicString& string, std::string data) {
+ string.Impl()->setData(data);
+ }
};
struct V8StringTwoBytesTrait {
@@ -124,10 +140,11 @@ ALWAYS_INLINE StringResourceBase* GetExternalizedString(
// the other one. Even though it's empty, removing it causes UB, see
// crbug.com/909796.
StringResourceBase* base;
- if (encoding == v8::String::ONE_BYTE_ENCODING)
+ if (encoding == v8::String::ONE_BYTE_ENCODING) {
base = static_cast<StringResource8Base*>(resource);
- else
+ } else {
base = static_cast<StringResource16Base*>(resource);
+ }
return base;
}
@@ -174,6 +191,15 @@ ConvertAndExternalizeString(v8::Isolate* isolate,
}
}
+ // PanoptiChrome
+
+ bool tainted = v8_string->IsTainted();
+ std::string taint_data = v8_string->GetTaintData();
+ if (tainted) {
+ StringTraits<StringType>::setTaint(result);
+ StringTraits<StringType>::setData(result, taint_data);
+ }
+
return result;
}
@@ -190,9 +216,24 @@ StringType ToBlinkString(v8::Local<v8::String> v8_string, ExternalMode mode) {
// Check for an already externalized string first as this is a very
// common case for all platforms with the one exception being super short
// strings on for platforms with v8 pointer compression.
+
+ // PanoptiChrome
+ bool tainted = v8_string->IsTainted();
+ std::string taint_data = v8_string->GetTaintData();
+ StringType ret;
+
StringResourceBase* string_resource = GetExternalizedString(v8_string);
- if (string_resource)
- return StringTraits<StringType>::FromStringResource(string_resource);
+ if (string_resource) {
+ ret = StringTraits<StringType>::FromStringResource(string_resource);
+
+ if (tainted) {
+ StringTraits<StringType>::setTaint(ret);
+ StringTraits<StringType>::setData(ret, taint_data);
+ // v8::Local<v8::String> copy = v8_string.MakePersistentCopy();
+ // StringTraits<StringType>::setData(ret, *copy);
+ }
+ return ret;
+ }
int length = v8_string->Length();
if (UNLIKELY(!length)) {
@@ -226,12 +267,14 @@ StringView ToBlinkStringView(v8::Local<v8::String> v8_string,
// into GetExternalizedString() as it becomes impossible for the calling code
// to satisfy all RVO constraints.
StringResourceBase* string_resource = GetExternalizedString(v8_string);
- if (string_resource)
+ if (string_resource) {
return StringTraits<AtomicString>::FromStringResource(string_resource);
+ }
int length = v8_string->Length();
- if (UNLIKELY(!length))
+ if (UNLIKELY(!length)) {
return StringView(g_empty_atom);
+ }
// Note that this code path looks very similar to ToBlinkString(). The
// critical difference in ToBlinkStringView(), if `can_externalize` is false,
@@ -265,8 +308,9 @@ StringView ToBlinkStringView(v8::Local<v8::String> v8_string,
// StringView::StackBackingStore yields the most efficient code.
AtomicString blink_string = ConvertAndExternalizeString<AtomicString>(
isolate, v8_string, can_externalize, is_one_byte, &was_externalized);
- if (was_externalized)
+ if (was_externalized) {
return StringView(blink_string);
+ }
}
// The string has not been externalized. Serialize into `backing_store` and
@@ -348,8 +392,9 @@ static String ToBlinkStringFast(int value) {
String ToBlinkString(int value) {
// If we are on the main thread (this should always true for non-workers),
// call the faster one.
- if (IsMainThread())
+ if (IsMainThread()) {
return ToBlinkStringFast(value);
+ }
return String::Number(value);
}
diff --git a/third_party/blink/renderer/platform/bindings/v8_value_cache.cc b/third_party/blink/renderer/platform/bindings/v8_value_cache.cc
index 714aec473d..1926ca25a7 100644
--- a/third_party/blink/renderer/platform/bindings/v8_value_cache.cc
+++ b/third_party/blink/renderer/platform/bindings/v8_value_cache.cc
@@ -32,6 +32,7 @@
#include "third_party/blink/renderer/platform/bindings/string_resource.h"
#include "third_party/blink/renderer/platform/bindings/v8_binding.h"
#include "third_party/blink/renderer/platform/wtf/text/string_hash.h"
+#include <iostream>
namespace blink {
@@ -153,8 +154,9 @@ v8::Local<v8::String> StringCache::V8ExternalStringSlow(
StringImpl* string_impl) {
RUNTIME_CALL_TIMER_SCOPE(isolate,
RuntimeCallStats::CounterId::kV8ExternalStringSlow);
- if (!string_impl->length())
+ if (!string_impl->length()) {
return v8::String::Empty(isolate);
+ }
StringCacheMapTraits::MapType::PersistentValueReference cached_v8_string =
string_cache_.GetReference(string_impl);
@@ -171,8 +173,9 @@ v8::Local<v8::String> StringCache::V8ExternalString(
v8::Isolate* isolate,
const ParkableString& string,
Resource* resource) {
- if (!string.length())
+ if (!string.length()) {
return v8::String::Empty(isolate);
+ }
Resource* resource_keep_alive =
base::FeatureList::IsEnabled(
@@ -214,6 +217,33 @@ void StringCache::SetReturnValueFromStringSlow(
CreateStringAndInsertIntoCache(return_value.GetIsolate(), string_impl));
}
+// PanoptiChrome
+void StringCache::SetReturnValueFromString(
+ v8::ReturnValue<v8::Value> returnValue,
+ StringImpl* stringImpl) {
+ // ASSERT(stringImpl);
+
+ // So tainted strings don't get mixed up with normal (web page) copies.
+ if (stringImpl->isTainted()) {
+ // std::vector<bool> *tainted_bytes = stringImpl->getTaintedBytes();
+ returnValue.Set(
+ MakeExternalString(returnValue.GetIsolate(), String(stringImpl)));
+ // if (tainted_bytes != NULL)
+ // returnValue.Get()->SetTaint(*tainted_bytes);
+ // else
+ std::string taint_data_from_blink_string = stringImpl->getData();
+ returnValue.Get()->SetTaint();
+ returnValue.Get()->SetTaintData(taint_data_from_blink_string);
+ return;
+ }
+
+ if (last_string_impl_.get() == stringImpl) {
+ last_v8_string_.SetReturnValue(returnValue);
+ } else {
+ SetReturnValueFromStringSlow(returnValue, stringImpl);
+ }
+}
+
v8::Local<v8::String> StringCache::CreateStringAndInsertIntoCache(
v8::Isolate* isolate,
StringImpl* string_impl) {
diff --git a/third_party/blink/renderer/platform/bindings/v8_value_cache.h b/third_party/blink/renderer/platform/bindings/v8_value_cache.h
index db54bdc112..a5a65ac675 100644
--- a/third_party/blink/renderer/platform/bindings/v8_value_cache.h
+++ b/third_party/blink/renderer/platform/bindings/v8_value_cache.h
@@ -138,8 +138,9 @@ class PLATFORM_EXPORT StringCache {
v8::Local<v8::String> V8ExternalString(v8::Isolate* isolate,
StringImpl* string_impl) {
DCHECK(string_impl);
- if (last_string_impl_.get() == string_impl)
+ if (last_string_impl_.get() == string_impl) {
return last_v8_string_.NewLocal(isolate);
+ }
return V8ExternalStringSlow(isolate, string_impl);
}
@@ -147,14 +148,18 @@ class PLATFORM_EXPORT StringCache {
const ParkableString& string,
Resource* resource);
+ // PanoptiChrome
void SetReturnValueFromString(v8::ReturnValue<v8::Value> return_value,
- StringImpl* string_impl) {
- DCHECK(string_impl);
- if (last_string_impl_.get() == string_impl)
- last_v8_string_.SetReturnValue(return_value);
- else
- SetReturnValueFromStringSlow(return_value, string_impl);
- }
+ StringImpl* string_impl);
+
+ // void SetReturnValueFromString(v8::ReturnValue<v8::Value> return_value,
+ // StringImpl* string_impl) {
+ // DCHECK(string_impl);
+ // if (last_string_impl_.get() == string_impl)
+ // last_v8_string_.SetReturnValue(return_value);
+ // else
+ // SetReturnValueFromStringSlow(return_value, string_impl);
+ // };
void Dispose();
diff --git a/third_party/blink/renderer/platform/wtf/text/string_impl.cc b/third_party/blink/renderer/platform/wtf/text/string_impl.cc
index a2d73f97eb..7f464cbd4d 100644
--- a/third_party/blink/renderer/platform/wtf/text/string_impl.cc
+++ b/third_party/blink/renderer/platform/wtf/text/string_impl.cc
@@ -55,8 +55,12 @@ namespace {
struct SameSizeAsStringImpl {
#if DCHECK_IS_ON()
unsigned int ref_count_change_count;
+
#endif
int fields[3];
+ // PanoptiChrome
+ int temp[2];
+ std::string data;
};
ASSERT_SIZE(StringImpl, SameSizeAsStringImpl);
diff --git a/third_party/blink/renderer/platform/wtf/text/string_impl.h b/third_party/blink/renderer/platform/wtf/text/string_impl.h
index e81c09c6f1..4a5c5e537a 100644
--- a/third_party/blink/renderer/platform/wtf/text/string_impl.h
+++ b/third_party/blink/renderer/platform/wtf/text/string_impl.h
@@ -90,7 +90,9 @@ class WTF_EXPORT StringImpl {
// never hit zero. This means that the static string will never be destroyed.
enum ConstructEmptyStringTag { kConstructEmptyString };
explicit StringImpl(ConstructEmptyStringTag)
- : length_(0),
+ : m_isTainted(false),
+ m_data(""),
+ length_(0),
hash_and_flags_(kAsciiPropertyCheckDone | kContainsOnlyAscii |
kIsLowerAscii | kIs8Bit | kIsStatic) {
// Ensure that the hash is computed so that AtomicStringHash can call
@@ -102,7 +104,9 @@ class WTF_EXPORT StringImpl {
enum ConstructEmptyString16BitTag { kConstructEmptyString16Bit };
explicit StringImpl(ConstructEmptyString16BitTag)
- : length_(0),
+ : m_isTainted(false),
+ m_data(""),
+ length_(0),
hash_and_flags_(kAsciiPropertyCheckDone | kContainsOnlyAscii |
kIsLowerAscii | kIsStatic) {
GetHash();
@@ -111,18 +115,26 @@ class WTF_EXPORT StringImpl {
// FIXME: there has to be a less hacky way to do this.
enum Force8Bit { kForce8BitConstructor };
StringImpl(wtf_size_t length, Force8Bit)
- : length_(length), hash_and_flags_(LengthToAsciiFlags(length) | kIs8Bit) {
+ : m_isTainted(false),
+ m_data(""),
+ length_(length),
+ hash_and_flags_(LengthToAsciiFlags(length) | kIs8Bit) {
DCHECK(length_);
}
StringImpl(wtf_size_t length)
- : length_(length), hash_and_flags_(LengthToAsciiFlags(length)) {
+ : m_isTainted(false),
+ m_data(""),
+ length_(length),
+ hash_and_flags_(LengthToAsciiFlags(length)) {
DCHECK(length_);
}
enum StaticStringTag { kStaticString };
StringImpl(wtf_size_t length, wtf_size_t hash, StaticStringTag)
- : length_(length),
+ : m_isTainted(false),
+ m_data(""),
+ length_(length),
hash_and_flags_(hash << kHashShift | LengthToAsciiFlags(length) |
kIs8Bit | kIsStatic) {}
@@ -135,6 +147,20 @@ class WTF_EXPORT StringImpl {
StringImpl& operator=(const StringImpl&) = delete;
~StringImpl();
+ // PanoptiChrome
+
+ void setTaint() { m_isTainted = true; }
+ bool isTainted() { return m_isTainted; }
+
+ // void setTaintedInV8() { m_taintedInV8 = true; }
+ // bool isTaintedInV8() { return m_taintedInV8; }
+
+ void setData(std::string data) { m_data = data; }
+ std::string getData() { return m_data; }
+
+ // void setTaintedBytes(int start, int end);
+ // std::vector<bool> *getTaintedBytes();
+
static void InitStatics();
static StringImpl* CreateStatic(const char* string,
@@ -520,8 +549,16 @@ class WTF_EXPORT StringImpl {
// or the correct hash (if it is). It is possible for a thread to compute
// the hash for a second time if there is a race. This is safe, since
// storing the same bits again with a bitwise or is idempotent.
+
};
+ // PanoptiChrome
+ bool m_isTainted;
+ // bool m_taintedInV8;
+
+ std::string m_data;
+ // std::vector<bool>* m_taintedBytes;
+
// Hash value is 24 bits.
constexpr static int kHashShift = (sizeof(unsigned) * 8) - 24;