Skip to content

Commit c807a63

Browse files
committed
profile
1 parent b974cfb commit c807a63

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+52
-4017
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ Special thanks to all users of Fuzzilli who have reported bugs found by it!
248248
- [CVE-2020-1912](https://www.facebook.com/security/advisories/cve-2020-1912): Memory corruption when executing lazily compiled inner generator functions
249249
- [CVE-2020-1914](https://www.facebook.com/security/advisories/cve-2020-1914): Bytecode corruption when handling the SaveGeneratorLong instruction
250250

251+
#### [Workerd](https://github.com/cloudflare/workerd)
252+
- [PR 4793](https://github.com/cloudflare/workerd/pull/4793): OOB write in writeSync due to missing bounds check
253+
- [PR 4845](https://github.com/cloudflare/workerd/pull/4845): UAF in VFS file clone handling
254+
- [PR 4828](https://github.com/cloudflare/workerd/pull/4828): Segmentation fault on undefined keys in DH crypto API.
255+
- [PR 4853](https://github.com/cloudflare/workerd/pull/4853): Workerd hits illegal instruction due to missing branch in FileSystemModule::setLastModified.
256+
251257
## Disclaimer
252258

253259
This is not an officially supported Google product.

Sources/Fuzzilli/Compiler/Compiler.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,10 +1161,9 @@ public class JavaScriptCompiler {
11611161

11621162
case .awaitExpression(let awaitExpression):
11631163
// TODO await is also allowed at the top level of a module
1164-
/*if !contextAnalyzer.context.contains(.asyncFunction) {
1164+
if !contextAnalyzer.context.contains(.asyncFunction) {
11651165
throw CompilerError.invalidNodeError("`await` is currently only supported in async functions")
11661166
}
1167-
*/
11681167
let argument = try compileExpression(awaitExpression.argument)
11691168
return emit(Await(), withInputs: [argument]).output
11701169

Sources/Fuzzilli/Compiler/JavaScriptParser.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public class JavaScriptParser {
4343
do {
4444
try runParserScript(withArguments: [])
4545
} catch {
46-
4746
return nil
4847
}
4948
}

Sources/Fuzzilli/Compiler/Parser/parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function tryReadFile(path) {
3434

3535
// Parse the given JavaScript script and return an AST compatible with Fuzzilli's protobuf-based AST format.
3636
function parse(script, proto) {
37-
let ast = Parser.parse(script, { allowAwaitOutsideFunction: true, plugins: ["topLevelAwait","v8intrinsic"] });
37+
let ast = Parser.parse(script, { plugins: ["v8intrinsic"] });
3838

3939
function assertNoError(err) {
4040
if (err) throw err;

Sources/Fuzzilli/FuzzIL/Code.swift

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -239,21 +239,9 @@ public struct Code: Collection {
239239
throw FuzzilliError.codeVerificationError("variable \(input) is not visible anymore")
240240
}
241241
}
242-
243-
if instr.op is Await {
244-
// if !contextAnalyzer.context.contains(.asyncFunction)
245-
// {
246-
// if contextAnalyzer.context.contains(.subroutine) {
247-
// if !contextAnalyzer.context.contains(.method) && !contextAnalyzer.context.contains(.classMethod) && !contextAnalyzer.context.contains(.javascript) {
248-
// throw FuzzilliError.codeVerificationError("operation \(instr.op.name) inside an invalid context")
249-
// }
250-
// }
251-
// }
252-
// fall-through allow top-level await
253-
} else {
254-
guard instr.op.requiredContext.isSubset(of: contextAnalyzer.context) else {
255-
throw FuzzilliError.codeVerificationError("operation \(instr.op.name) inside an invalid context")
256-
}
242+
243+
guard instr.op.requiredContext.isSubset(of: contextAnalyzer.context) else {
244+
throw FuzzilliError.codeVerificationError("operation \(instr.op.name) inside an invalid context")
257245
}
258246

259247
// Ensure that the instruction exists in the right context

Sources/Fuzzilli/Fuzzer.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ public class Fuzzer {
431431
}
432432

433433
let execution = execute(program, purpose: .programImport)
434+
434435
var wasImported = false
435436
switch execution.outcome {
436437
case .crashed(let termsig):
@@ -673,15 +674,6 @@ public class Fuzzer {
673674
let execution = runner.run(script, withTimeout: timeout ?? config.timeout)
674675
dispatchEvent(events.PostExecute, data: execution)
675676

676-
//Stdout
677-
// if !execution.stdout.isEmpty {
678-
// print(execution.stdout)
679-
// }
680-
681-
// if !execution.stderr.isEmpty {
682-
// print(execution.stderr)
683-
// }
684-
685677
return execution
686678
}
687679

Sources/FuzzilliCli/Profiles/WorkerdProfile.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020 Google LLC
1+
// Copyright 2025 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -15,9 +15,8 @@
1515
import Fuzzilli
1616

1717
let workerdProfile = Profile(
18-
processArgs: { randomize in
19-
["--reprl-fuzzilli"]
20-
},
18+
processArgs: { randomize in ["fuzzilli"] },
19+
2120

2221
processEnv: [:],
2322

Sources/REPRLRun/main.swift

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
import Foundation
216
import libreprl
317

418
func convertToCArray(_ array: [String]) -> UnsafeMutablePointer<UnsafePointer<Int8>?> {
5-
print("Converting array to C array: \(array)")
619
let buffer = UnsafeMutablePointer<UnsafePointer<Int8>?>.allocate(capacity: array.count + 1)
720
for (i, str) in array.enumerated() {
821
buffer[i] = UnsafePointer(str.withCString(strdup))
@@ -11,25 +24,12 @@ func convertToCArray(_ array: [String]) -> UnsafeMutablePointer<UnsafePointer<In
1124
return buffer
1225
}
1326

14-
func printREPRLOutput(_ ctx: OpaquePointer?) {
15-
let fuzzout = String(cString: reprl_fetch_fuzzout(ctx))
16-
let stdout = String(cString: reprl_fetch_stdout(ctx))
17-
let stderr = String(cString: reprl_fetch_stderr(ctx))
18-
19-
print("========== Fuzzout ==========")
20-
print(fuzzout)
21-
print("========== Stdout ==========")
22-
print(stdout)
23-
print("========== Stderr ==========")
24-
print(stderr)
25-
}
26-
2727
if CommandLine.arguments.count < 2 {
2828
print("Usage: \(CommandLine.arguments[0]) path/to/js_shell [args, ...]")
2929
exit(0)
3030
}
3131

32-
print("Creating REPRL context...")
32+
3333
let ctx = libreprl.reprl_create_context()
3434
if ctx == nil {
3535
print("Failed to create REPRL context??")
@@ -38,25 +38,16 @@ if ctx == nil {
3838

3939
let argv = convertToCArray(Array(CommandLine.arguments[1...]))
4040
let envp = convertToCArray([])
41-
42-
print("Initializing REPRL context with argv: \(CommandLine.arguments[1...])")
4341
if reprl_initialize_context(ctx, argv, envp, /* capture_stdout: */ 1, /* capture stderr: */ 1) != 0 {
4442
print("Failed to initialize REPRL context: \(String(cString: reprl_get_last_error(ctx)))")
45-
printREPRLOutput(ctx)
46-
exit(1)
47-
} else {
48-
print("REPRL context initialized successfully.")
4943
}
5044

5145
func execute(_ script: String) -> (status: Int32, exec_time: UInt64) {
5246
var exec_time: UInt64 = 0
5347
var status: Int32 = 0
54-
print("Executing script: \(script)")
5548
script.withCString { ptr in
5649
status = reprl_execute(ctx, ptr, UInt64(script.utf8.count), 1_000_000, &exec_time, 0)
5750
}
58-
print("Execution result: status = \(status), exec_time = \(exec_time)")
59-
printREPRLOutput(ctx)
6051
return (status, exec_time)
6152
}
6253

@@ -65,32 +56,29 @@ func runREPRLTests() {
6556
var numFailures = 0
6657

6758
func expect_success(_ code: String) {
68-
print("Expecting success for code: \(code)")
6959
if execute(code).status != 0 {
7060
print("Execution of \"\(code)\" failed")
7161
numFailures += 1
72-
} else {
73-
print("Success for code: \(code)")
7462
}
7563
}
7664

7765
func expect_failure(_ code: String) {
78-
print("Expecting failure for code: \(code)")
7966
if execute(code).status == 0 {
8067
print("Execution of \"\(code)\" unexpectedly succeeded")
8168
numFailures += 1
82-
} else {
83-
print("Failure as expected for code: \(code)")
8469
}
8570
}
8671

8772
expect_success("42")
8873
expect_failure("throw 42")
8974

75+
// Verify that existing state is property reset between executions
9076
expect_success("globalProp = 42; Object.prototype.foo = \"bar\";")
9177
expect_success("if (typeof(globalProp) !== 'undefined') throw 'failure'")
9278
expect_success("if (typeof(({}).foo) !== 'undefined') throw 'failure'")
9379

80+
// Verify that rejected promises are properly reset between executions
81+
// Only if async functions are available
9482
if execute("async function foo() {}").status == 0 {
9583
expect_failure("async function fail() { throw 42; }; fail()")
9684
expect_success("42")
@@ -101,19 +89,17 @@ func runREPRLTests() {
10189
if numFailures == 0 {
10290
print("All tests passed!")
10391
} else {
104-
print("Not all tests passed. REPRL support may not be properly implemented.")
92+
print("Not all tests passed. That means REPRL support likely isn't properly implemented in the target engine")
10593
}
10694
}
10795

108-
print("Checking if REPRL works...")
96+
// Check whether REPRL works at all
10997
if execute("").status != 0 {
110-
print("Initial script execution failed, REPRL support does not appear to be working")
111-
printREPRLOutput(ctx)
98+
print("Script execution failed, REPRL support does not appear to be working")
11299
exit(1)
113-
} else {
114-
print("Initial REPRL check passed.")
115100
}
116101

102+
// Run a couple of tests now
117103
runREPRLTests()
118104

119105
print("Enter code to run, then hit enter to execute it")
@@ -124,15 +110,15 @@ while true {
124110
break
125111
}
126112

127-
print("Executing user input code...")
128113
let (status, exec_time) = execute(code)
129114

130115
if status < 0 {
131116
print("Error during script execution: \(String(cString: reprl_get_last_error(ctx))). REPRL support in the target probably isn't working correctly...")
132-
printREPRLOutput(ctx)
133117
continue
134118
}
135119

136120
print("Execution finished with status \(status) (signaled: \(RIFSIGNALED(status) != 0), timed out: \(RIFTIMEDOUT(status) != 0)) and took \(exec_time / 1000)ms")
121+
print("========== Fuzzout ==========\n\(String(cString: reprl_fetch_fuzzout(ctx)))")
122+
print("========== Stdout ==========\n\(String(cString: reprl_fetch_stdout(ctx)))")
123+
print("========== Stderr ==========\n\(String(cString: reprl_fetch_stderr(ctx)))")
137124
}
138-

Targets/workerd/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Target: workerd
2+
3+
To build workerd for fuzzing:
4+
5+
0. Clone [workerd](https://github.com/cloudflare/workerd/)
6+
1. Follow the instructions [here](https://github.com/cloudflare/workerd/blob/main/README.md#getting-started)
7+
2. Run the fuzzbuild.sh script in the workerd root directory to build workerd with the fuzzili configuration
8+

Targets/workerd/fuzzbuild.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
bazel --nohome_rc --nosystem_rc build --config=reprl-fuzzilli //src/workerd/server:workerd --action_env=CC=clang-19
2+
# test if REPRLRun works
3+
# swift run REPRLRun <path-to-workerd> fuzzilli <path-to-capnp-config> --experimental
4+

0 commit comments

Comments
 (0)