Skip to content

Commit d0f1870

Browse files
author
Samuel Groß
committed
Convert SerializeDeserializeGenerator to a ProgramTemplate
... as that feels like the slightly more natural choice for what it is attempting to achieve (it's essentially a "mini-fuzzer" targeting the value serializer in V8).
1 parent 98a14e9 commit d0f1870

1 file changed

Lines changed: 42 additions & 35 deletions

File tree

Sources/FuzzilliCli/Profiles/V8Profile.swift

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -94,36 +94,6 @@ fileprivate let WorkerGenerator = RecursiveCodeGenerator("WorkerGenerator") { b
9494
// Fuzzilli can now use the worker.
9595
}
9696

97-
fileprivate let SerializeDeserializeGenerator = CodeGenerator("SerializeDeserializeGenerator", input: .object()) { b, o in
98-
// Load necessary builtins
99-
let d8 = b.loadBuiltin("d8")
100-
let serializer = b.getProperty("serializer", of: d8)
101-
let Uint8Array = b.loadBuiltin("Uint8Array")
102-
103-
// Serialize a random object
104-
let content = b.callMethod("serialize", on: serializer, withArgs: [o])
105-
let u8 = b.construct(Uint8Array, withArgs: [content])
106-
107-
// Choose a random byte to change
108-
let index = Int64.random(in: 0..<100)
109-
110-
// Either flip or replace the byte
111-
let newByte: Variable
112-
if probability(0.5) {
113-
let bit = b.loadInt(1 << Int.random(in: 0..<8))
114-
let oldByte = b.getElement(index, of: u8)
115-
newByte = b.binary(oldByte, bit, with: .Xor)
116-
} else {
117-
newByte = b.loadInt(Int64.random(in: 0..<256))
118-
}
119-
b.setElement(index, of: u8, to: newByte)
120-
121-
// Deserialize the resulting buffer
122-
let _ = b.callMethod("deserialize", on: serializer, withArgs: [content])
123-
124-
// Deserialized object is available in a variable now and can be used by following code
125-
}
126-
12797
// Insert random GC calls throughout our code.
12898
fileprivate let GcGenerator = CodeGenerator("GcGenerator") { b in
12999
let gc = b.loadBuiltin("gc")
@@ -139,7 +109,7 @@ fileprivate let GcGenerator = CodeGenerator("GcGenerator") { b in
139109
b.callFunction(gc, withArgs: [b.createObject(with: ["type": type, "execution": execution])])
140110
}
141111

142-
fileprivate let MapTransitionsTemplate = ProgramTemplate("MapTransitionsTemplate") { b in
112+
fileprivate let MapTransitionFuzzer = ProgramTemplate("MapTransitionFuzzer") { b in
143113
// This template is meant to stress the v8 Map transition mechanisms.
144114
// Basically, it generates a bunch of CreateObject, GetProperty, SetProperty, FunctionDefinition,
145115
// and CallFunction operations operating on a small set of objects and property names.
@@ -304,9 +274,45 @@ fileprivate let MapTransitionsTemplate = ProgramTemplate("MapTransitionsTemplate
304274
}
305275
}
306276

277+
fileprivate let ValueSerializerFuzzer = ProgramTemplate("ValueSerializerFuzzer") { b in
278+
b.buildPrefix()
279+
280+
// Create some random values that can be serialized below.
281+
b.build(n: 50)
282+
283+
// Load necessary builtins
284+
let d8 = b.loadBuiltin("d8")
285+
let serializer = b.getProperty("serializer", of: d8)
286+
let Uint8Array = b.loadBuiltin("Uint8Array")
287+
288+
// Serialize a random object
289+
let content = b.callMethod("serialize", on: serializer, withArgs: [b.randomVariable()])
290+
let u8 = b.construct(Uint8Array, withArgs: [content])
291+
292+
// Choose a random byte to change
293+
let index = Int64.random(in: 0..<100)
294+
295+
// Either flip or replace the byte
296+
let newByte: Variable
297+
if probability(0.5) {
298+
let bit = b.loadInt(1 << Int.random(in: 0..<8))
299+
let oldByte = b.getElement(index, of: u8)
300+
newByte = b.binary(oldByte, bit, with: .Xor)
301+
} else {
302+
newByte = b.loadInt(Int64.random(in: 0..<256))
303+
}
304+
b.setElement(index, of: u8, to: newByte)
305+
306+
// Deserialize the resulting buffer
307+
let _ = b.callMethod("deserialize", on: serializer, withArgs: [content])
308+
309+
// Generate some more random code to (hopefully) use the deserialized objects in some interesting way.
310+
b.build(n: 10)
311+
}
312+
307313
// This template fuzzes the RegExp engine.
308314
// It finds bugs like: crbug.com/1437346 and crbug.com/1439691.
309-
fileprivate let RegExpFuzzerTemplate = ProgramTemplate("RegExpFuzzerTemplate") { b in
315+
fileprivate let RegExpFuzzer = ProgramTemplate("RegExpFuzzer") { b in
310316
// Taken from: https://source.chromium.org/chromium/chromium/src/+/refs/heads/main:v8/test/fuzzer/regexp-builtins.cc;l=212;drc=a61b95c63b0b75c1cfe872d9c8cdf927c226046e
311317
let twoByteSubjectString = "f\\uD83D\\uDCA9ba\\u2603"
312318

@@ -525,14 +531,15 @@ let v8Profile = Profile(
525531
(ForceTurboFanCompilationGenerator, 5),
526532
(ForceMaglevCompilationGenerator, 5),
527533
(TurbofanVerifyTypeGenerator, 10),
528-
(SerializeDeserializeGenerator, 10),
534+
529535
(WorkerGenerator, 10),
530536
(GcGenerator, 10),
531537
],
532538

533539
additionalProgramTemplates: WeightedList<ProgramTemplate>([
534-
(MapTransitionsTemplate, 1),
535-
(RegExpFuzzerTemplate, 1),
540+
(MapTransitionFuzzer, 1),
541+
(ValueSerializerFuzzer, 1),
542+
(RegExpFuzzer, 1),
536543
]),
537544

538545
disabledCodeGenerators: [],

0 commit comments

Comments
 (0)