-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdom_storage_v8_patch.diff
463 lines (431 loc) · 16.7 KB
/
dom_storage_v8_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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
diff --git a/include/v8-value.h b/include/v8-value.h
index c80ae06..0bc801e 100644
--- a/include/v8-value.h
+++ b/include/v8-value.h
@@ -29,6 +29,24 @@ class Uint32;
*/
class V8_EXPORT Value : public Data {
public:
+
+// PanoptiChrome
+
+// + void Print();
+
+ Isolate *GetIsolate();
+
+ bool IsHeapAllocated();
+
+ void SetTaint();
+ bool IsTainted();
+ std::string GetTaintData();
+ void SetTaintData(std::string taint_data);
+// + std::vector<bool> GetTaintedBytes();
+
+// + void PrintTaintSinkDetails(Isolate *isolate, FILE *out);
+
+
/**
* Returns true if this value is the undefined value. See ECMA-262
* 4.3.10.
diff --git a/src/api/api.cc b/src/api/api.cc
index 86585cf..0dc10b4 100644
--- a/src/api/api.cc
+++ b/src/api/api.cc
@@ -3834,6 +3834,119 @@ bool ValueDeserializer::ReadRawBytes(size_t length, const void** data) {
// --- D a t a ---
+// PanoptiChrome
+Isolate* Value::GetIsolate() {
+ i::Handle<i::Object> object = Utils::OpenHandle(this);
+
+ if (object->IsHeapObject()) {
+ // i::Isolate* isolate = object->GetIsolate();
+ // i::Isolate* isolate = Isolate::Current();
+ // Isolate* isolate = i::Heap::FromWritableHeapObject(*this)->isolate();
+
+ i::Isolate* i_isolate;
+ if (object->InWritableSharedSpace()) {
+ i_isolate = i::Isolate::Current();
+ } else {
+ // It is safe to call GetIsolateFromWritableHeapObject because
+ // SupportsExternalization already checked that the object is writable.
+ i_isolate = i::GetIsolateFromWritableObject(i::HeapObject::cast(*object));
+ }
+
+ return reinterpret_cast<Isolate*>(i_isolate);
+ }
+ return NULL;
+}
+
+bool Value::IsHeapAllocated() {
+ i::Handle<i::Object> object = Utils::OpenHandle(this);
+ return object->IsHeapObject();
+}
+
+void Value::SetTaint() {
+ i::Handle<i::Object> object = Utils::OpenHandle(this);
+
+ // auto object = Utils::OpenHandle(this);
+ // auto i_isolate = object->GetIsolate();
+
+ // CHECK(object.IsHeapObject()); // No Smi.
+ if (object->IsHeapObject()) {
+ // i::Isolate* isolate = object->GetIsolate();
+ // i::Isolate* isolate = Isolate::Current();
+ // Isolate* isolate = i::Heap::FromWritableHeapObject(*this)->isolate();
+
+ i::Isolate* i_isolate;
+ // if (object->InWritableSharedSpace()) {
+ i_isolate = i::Isolate::Current();
+ // }
+ // else {
+ // // It is safe to call GetIsolateFromWritableHeapObject because
+ // // SupportsExternalization already checked that the object is writable.
+ // // i_isolate =
+ // i::GetIsolateFromWritableObject(i::HeapObject::cast(*object));
+ // i_isolate = i::GetIsolateFromHeapObject(i::HeapObject::cast(*object));
+
+ // }
+ i::JavaScriptStackFrameIterator it(i_isolate);
+ if (!it.done()) {
+ i_isolate->SetTaintForV8Object(object);
+ }
+ }
+}
+
+bool Value::IsTainted() {
+ i::Handle<i::Object> object = Utils::OpenHandle(this);
+ if (object->IsHeapObject()) {
+ i::Isolate* i_isolate;
+ // if (object->InWritableSharedSpace()) {
+ i_isolate = i::Isolate::Current();
+ // }
+ // else {
+ // // It is safe to call GetIsolateFromWritableHeapObject because
+ // // SupportsExternalization already checked that the object is writable.
+ // i_isolate = i::GetIsolateFromWritableObject(i::HeapObject::cast(*object));
+ // }
+ return i_isolate->IsV8ObjectTainted(object);
+ }
+ return false;
+}
+
+
+std::string Value::GetTaintData() {
+ i::Handle<i::Object> object = Utils::OpenHandle(this);
+ if (object->IsHeapObject()) {
+ i::Isolate* i_isolate;
+ // if (object->InWritableSharedSpace()) {
+ i_isolate = i::Isolate::Current();
+ // }
+ // else {
+ // // It is safe to call GetIsolateFromWritableHeapObject because
+ // // SupportsExternalization already checked that the object is writable.
+ // i_isolate = i::GetIsolateFromWritableObject(i::HeapObject::cast(*object));
+ // }
+
+ return i_isolate->getObjectTaintSource(object);
+ }
+ return "";
+}
+
+void Value::SetTaintData(std::string taint_data){
+ i::Handle<i::Object> object = Utils::OpenHandle(this);
+ if (object->IsHeapObject()) {
+ i::Isolate* i_isolate;
+ // if (object->InWritableSharedSpace()) {
+ i_isolate = i::Isolate::Current();
+ // }
+ // else {
+ // // It is safe to call GetIsolateFromWritableHeapObject because
+ // // SupportsExternalization already checked that the object is writable.
+ // i_isolate = i::GetIsolateFromWritableObject(i::HeapObject::cast(*object));
+ // }
+
+ i_isolate->SetTaintForV8Object(object, taint_data);
+ }
+
+}
+
bool Value::FullIsUndefined() const {
i::Handle<i::Object> object = Utils::OpenHandle(this);
bool result = object->IsUndefined();
diff --git a/src/builtins/builtins-api.cc b/src/builtins/builtins-api.cc
index f160d7c..2a870b1 100644
diff --git a/src/interpreter/bytecode-generator.cc b/src/interpreter/bytecode-generator.cc
index 94c1594..331244f 100644
--- a/src/interpreter/bytecode-generator.cc
+++ b/src/interpreter/bytecode-generator.cc
@@ -3597,7 +3597,7 @@ void BytecodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
object_literal_context_scope.SetEnteredIf(false);
builder()->LoadAccumulatorWithRegister(literal);
-// PanoptiChrome :: changes for objectliteral
+ // PanoptiChrome :: changes for objectliteral
RegisterAllocationScope register_scope(this);
RegisterList runtime_call_args_fast =
@@ -6235,7 +6235,7 @@ void BytecodeGenerator::VisitCall(Call* expr) {
// PanoptiChrome
// args format :: arguments, accumulator, start_position,
- // expression_position
+ // expression_position, property name (if property)
builder()->StoreAccumulatorInRegister(
register_allocator()->GrowRegisterList(&args));
@@ -6252,9 +6252,29 @@ void BytecodeGenerator::VisitCall(Call* expr) {
.StoreAccumulatorInRegister(
register_allocator()->GrowRegisterList(&args));
+ if (call_type == Call::NAMED_PROPERTY_CALL ||
+ call_type == Call::KEYED_PROPERTY_CALL) {
+ if (expr->expression()->IsProperty() &&
+ expr->expression()->AsProperty()->key()->IsPropertyName()) {
+ builder()
+ ->LoadLiteral(expr->expression()
+ ->AsProperty()
+ ->key()
+ ->AsLiteral()
+ ->AsRawPropertyName())
+ .StoreAccumulatorInRegister(
+ register_allocator()->GrowRegisterList(&args));
+ }
+ }
+
builder()->CallRuntime(Runtime::kTaintAnalysis_OnVisitCallArguments, args);
- args = args.Truncate(args.register_count() - 3);
+ if (call_type == Call::NAMED_PROPERTY_CALL ||
+ call_type == Call::KEYED_PROPERTY_CALL) {
+ args = args.Truncate(args.register_count() - 4);
+ } else {
+ args = args.Truncate(args.register_count() - 3);
+ }
// remove stored accumulator, scope position, expr position
// PanoptiChrome :: changes end
@@ -6328,6 +6348,17 @@ void BytecodeGenerator::VisitCall(Call* expr) {
->LoadLiteral(Smi::FromInt(expr->position()))
.StoreAccumulatorInRegister(
register_allocator()->GrowRegisterList(&runtime_call_args_OVC));
+ // if (call_type == Call::NAMED_PROPERTY_CALL ||
+ // call_type == Call::KEYED_PROPERTY_CALL) {
+ // builder()
+ // ->LoadLiteral(expr->expression()
+ // ->AsProperty()
+ // ->key()
+ // ->AsLiteral()
+ // ->AsRawPropertyName())
+ // .StoreAccumulatorInRegister(
+ // register_allocator()->GrowRegisterList(&runtime_call_args));
+ // }
builder()->CallRuntime(Runtime::kTaintAnalysis_OnVisitCallArguments,
runtime_call_args_OVC);
@@ -6407,12 +6438,11 @@ void BytecodeGenerator::VisitCall(Call* expr) {
builder()->StoreAccumulatorInRegister(
register_allocator()->GrowRegisterList(&runtime_call_args));
-//store calle in register list
-
- builder()->LoadAccumulatorWithRegister(callee);
- builder()->StoreAccumulatorInRegister(
- register_allocator()->GrowRegisterList(&runtime_call_args));
+ // store calle in register list
+ builder()->LoadAccumulatorWithRegister(callee);
+ builder()->StoreAccumulatorInRegister(
+ register_allocator()->GrowRegisterList(&runtime_call_args));
// args passed to the call
for (int i = 0; i < args.register_count(); i++) {
@@ -6421,17 +6451,17 @@ void BytecodeGenerator::VisitCall(Call* expr) {
register_allocator()->GrowRegisterList(&runtime_call_args));
}
- // Scope position
- builder()
- ->LoadLiteral(Smi::FromInt(current_scope()->start_position()))
- .StoreAccumulatorInRegister(
- register_allocator()->GrowRegisterList(&runtime_call_args));
+ // Scope position
+ builder()
+ ->LoadLiteral(Smi::FromInt(current_scope()->start_position()))
+ .StoreAccumulatorInRegister(
+ register_allocator()->GrowRegisterList(&runtime_call_args));
- // expression position
- builder()
- ->LoadLiteral(Smi::FromInt(expr->position()))
- .StoreAccumulatorInRegister(
- register_allocator()->GrowRegisterList(&runtime_call_args));
+ // expression position
+ builder()
+ ->LoadLiteral(Smi::FromInt(expr->position()))
+ .StoreAccumulatorInRegister(
+ register_allocator()->GrowRegisterList(&runtime_call_args));
builder()->CallRuntime(Runtime::kTaintAnalysis_JustPrintArgs,
runtime_call_args);
@@ -6439,7 +6469,6 @@ void BytecodeGenerator::VisitCall(Call* expr) {
} else {
builder()->CallAnyReceiver(
callee, args, feedback_index(feedback_spec()->AddCallICSlot()));
-
}
}
diff --git a/src/runtime/runtime-taint.cc b/src/runtime/runtime-taint.cc
index c062e1a..e0a0b71 100644
--- a/src/runtime/runtime-taint.cc
+++ b/src/runtime/runtime-taint.cc
@@ -497,7 +497,6 @@ class VisV8Logger {
std::ostream& out() const { return data->log; }
};
-
RUNTIME_FUNCTION(Runtime_TaintAnalysis_JustPrintArgs) {
// IGNORE_NON_PROPAGATION_CONTEXTS(isolate, true, UNDEFINED_VALUE_HEAP);
@@ -683,7 +682,7 @@ RUNTIME_FUNCTION(Runtime_TaintAnalysis_OnVisitPropertyCall) {
std::cout << "\n0. Return Value :: ";
return_value->Print();
std::cout << "1. Home Object :: ";
- // home_object->Print();
+ home_object->Print();
std::cout << "Arguments :: ";
for (int i = 2; i < args.length() - 3; i++)
std::cout << std::endl << i << ". " << args.at(i);
@@ -808,32 +807,93 @@ RUNTIME_FUNCTION(Runtime_TaintAnalysis_OnVisitCallArguments) {
// if (!isolate->ShouldTaintBusiness()) return UNDEFINED_VALUE_HEAP;
HandleScope handle_scope(isolate);
- Handle<Object> backup_obj = args.at(args.length() - 3);
+ Handle<Object> obj = args.at(0);
+ Handle<Object> backup_obj;
+ ScopeDFG* dfg;
+ int scope_position;
+ int expr_position;
+ std::string obj_name_str, prop_name_str;
- IGNORE_NON_PROPAGATION_CONTEXTS(isolate, true, *backup_obj);
+ Handle<Object> last_arg = args.at(args.length() - 1);
- auto scope_position = args.smi_value_at(args.length() - 2);
- auto expr_position = args.smi_value_at(args.length() - 1);
+ if (last_arg->IsSmi()) {
+ // normal case : no property call
+ backup_obj = args.at(args.length() - 3);
+
+ IGNORE_NON_PROPAGATION_CONTEXTS(isolate, true, *backup_obj);
+
+ scope_position = args.smi_value_at(args.length() - 2);
+ expr_position = args.smi_value_at(args.length() - 1);
#ifdef DEBUG
- if (isolate->inRKDebugMode()) {
- std::cout << "\n\nRuntime_OnVisitCallArguments :: " << args.length();
+ if (isolate->inRKDebugMode()) {
+ std::cout << "\n\nRuntime_OnVisitCallArguments :: " << args.length();
+
+ std::cout << "\nArguments :: ";
+ for (int i = 0; i < args.length() - 3; i++) {
+ std::cout << "\nArg " << i << ". " << args.at(i) << std::flush;
+ }
+
+ std::cout << std::endl << args.length() - 3 << ". Backup Object :: ";
+ backup_obj->Print();
- std::cout << "\nArguments :: ";
- for (int i = 0; i < args.length() - 3; i++) {
- std::cout << "\nArg " << i << ". " << args.at(i) << std::flush;
+ std::cout << args.length() - 2
+ << ". Scope Position :: " << scope_position;
+ std::cout << std::endl
+ << args.length() - 1
+ << ". Expression Position :: " << expr_position << std::endl
+ << std::flush;
}
+#endif
+ } else {
+ // property call
+ Handle<JSReceiver> rcvr = handle(JSReceiver::cast(*obj), isolate);
+ Handle<String> ctor = JSReceiver::GetConstructorName(isolate, rcvr);
- std::cout << std::endl << args.length() - 3 << ". Backup Object :: ";
- // backup_obj->Print();
+ obj_name_str = ctor->ToCString().get();
- std::cout << args.length() - 2 << ". Scope Position :: " << scope_position;
- std::cout << std::endl
- << args.length() - 1
- << ". Expression Position :: " << expr_position << std::endl
- << std::flush;
- }
+ backup_obj = args.at(args.length() - 4);
+
+ IGNORE_NON_PROPAGATION_CONTEXTS(isolate, true, *backup_obj);
+
+ scope_position = args.smi_value_at(args.length() - 3);
+ expr_position = args.smi_value_at(args.length() - 2);
+ Handle<String> property_name =
+ handle(String::cast(*args.at(args.length() - 1)), isolate);
+
+ prop_name_str = property_name->ToCString().get();
+
+#ifdef DEBUG
+ if (isolate->inRKDebugMode()) {
+ std::cout << "\n\nRuntime_OnVisitCallArguments :: " << args.length();
+
+ std::cout << "\nArguments :: ";
+ for (int i = 0; i < args.length() - 4; i++) {
+ std::cout << "\nArg " << i << ". " << args.at(i) << std::flush;
+ }
+
+ std::cout << std::endl << args.length() - 4 << ". Backup Object :: ";
+ backup_obj->Print();
+
+ std::cout << args.length() - 3
+ << ". Scope Position :: " << scope_position;
+ std::cout << std::endl
+ << args.length() - 2
+ << ". Expression Position :: " << expr_position << std::endl
+ << std::flush;
+ std::cout << std::endl << args.length() - 1 << ". Property name ::";
+ property_name->Print();
+ }
#endif
+ }
+
+ // args[1].Print();
+ // std::cout<<"\nARGS :: " <<args.at(1);
+ // std::cout<<"\nADDress :: " << args.address_of_arg_at(1);
+
+ // args[1].ptr = args[2].ptr();
+
+ // std::cout << "\nMaybe Object name::" << obj_name_str << std::endl;
JavaScriptStackFrameIterator it(isolate);
Handle<JSFunction> function(it.frame()->function(), isolate);
@@ -841,7 +901,7 @@ RUNTIME_FUNCTION(Runtime_TaintAnalysis_OnVisitCallArguments) {
ParseInfo* info_ = isolate->GetCompilationInfo(function);
if (info_ == NULL) return *backup_obj;
- ScopeDFG* dfg = isolate->GetScopeDFG(info_, scope_position);
+ dfg = isolate->GetScopeDFG(info_, scope_position);
if (dfg != NULL) dfg->PropagateTaint(it.frame());
CallLocator locator(isolate, info_->scope(), expr_position);
@@ -857,13 +917,13 @@ RUNTIME_FUNCTION(Runtime_TaintAnalysis_OnVisitCallArguments) {
#ifdef DEBUG
if (isolate->inRKDebugMode()) {
std::cout << "\nPrinting Located Arguments :: " << std::endl;
- // (t_args->at(i))->Print(isolate);
+ (t_args->at(i))->Print(isolate);
std::cout << std::flush;
}
#endif
if (checker.Check(t_args->at(i))) {
- Handle<Object> obj = args.at(i);
+ Handle<Object> obj = args.at(i+1);
if (obj->IsSmi()) {
std::cout << "\nVisitArguments -> VisitAndPushIntoRegisterList "
@@ -873,6 +933,25 @@ RUNTIME_FUNCTION(Runtime_TaintAnalysis_OnVisitCallArguments) {
if (!obj->IsSmi()) {
isolate->SetTaintForV8Object(obj);
checker.PopulatePropagatedFrom(obj);
+
+ // if i is 2, obj name is Storage, property name is setItem, then
+ // add _tainted_<taint sources> to the string
+
+ if (i == 1 && !last_arg->IsSmi() && args.at(2)->IsString() &&
+ obj_name_str == "Storage" && prop_name_str == "setItem") {
+ Handle<Object> str;
+ std::string final_source;
+
+ final_source = (String::cast(*(args.at(2)))).ToCString().get();
+ // add taint token to final_source variable
+ final_source += "_tainted";
+ final_source += isolate->getObjectTaintSource(obj);
+ str = isolate->factory()->NewStringFromAsciiChecked(
+ final_source.c_str());
+
+ // String test_str = "test";
+ *(args.address_of_arg_at(2)) = str->ptr();
+ }
}
}
}