fix: set default 30s timeout on guest-created sockets - #65
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens the host-proxied networking tools by bounding how long host threads can block on guest-initiated socket operations, mitigating a single-call DoS vector from indefinite blocking.
Changes:
- Introduces a 30s default socket read/write timeout for sockets created via
net_socket. - Switches
net_connecttoconnect_timeoutto cap TCP connect duration. - Adds a unit test intended to validate the default timeout behavior.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
1204
to
1205
| let tbl = t.lock().unwrap(); | ||
| let sock = tbl.get_socket(fd)?; |
Comment on lines
+3233
to
+3235
| let fd = v["result"]["fd"].as_u64().unwrap(); | ||
|
|
||
| // Verify the socket was created successfully |
Comment on lines
+3227
to
+3239
| register_internal_tools(&mut tools, &exit_code, Some(&NetworkPolicy::AllowAll), None); | ||
|
|
||
| let req = br#"{"name":"net_socket","args":{"family":2,"type":1}}"#; | ||
| let resp = tools.dispatch(req); | ||
| let s = std::str::from_utf8(&resp).unwrap(); | ||
| let v: serde_json::Value = serde_json::from_str(s).unwrap(); | ||
| let fd = v["result"]["fd"].as_u64().unwrap(); | ||
|
|
||
| // Verify the socket was created successfully | ||
| assert!(fd > 0); | ||
| // The timeout is set internally; we verify it works by checking | ||
| // that the response is valid (no error from set_read_timeout) | ||
| assert!(!s.contains("error"), "socket creation should succeed: {s}"); |
Contributor
There was a problem hiding this comment.
Linux Benchmarks
Details
| Benchmark suite | Current: 5af8e1f | Previous: 5198570 | Ratio |
|---|---|---|---|
hello_world (median) |
20 ms |
20 ms |
1 |
pandas (median) |
110 ms |
110 ms |
1 |
density (per VM) |
7 MB |
7 MB |
1 |
snapshot (disk) |
385 MiB |
385 MiB |
1 |
This comment was automatically generated by workflow using github-action-benchmark.
danbugs
force-pushed
the
fix/socket-timeouts
branch
from
May 17, 2026 06:59
c0082a6 to
1b28cbd
Compare
Contributor
There was a problem hiding this comment.
Windows Benchmarks
Details
| Benchmark suite | Current: 5af8e1f | Previous: 5198570 | Ratio |
|---|---|---|---|
hello_world (median) |
310 ms |
191 ms |
1.62 |
pandas (median) |
982 ms |
540 ms |
1.82 |
density (per VM) |
6 MB |
6 MB |
1 |
snapshot (disk) |
392 MiB |
392 MiB |
1 |
This comment was automatically generated by workflow using github-action-benchmark.
Adds SOCKET_TIMEOUT (30s) applied to all sockets at creation time via set_read_timeout/set_write_timeout. Also uses connect_timeout in handle_net_connect, releasing the SocketTable lock before the blocking connect call to avoid stalling concurrent socket operations. Includes a unit test that verifies the timeout is actually set. Signed-off-by: danbugs <danilochiarlone@gmail.com>
danbugs
force-pushed
the
fix/socket-timeouts
branch
from
May 17, 2026 07:11
206e878 to
2eb4c8b
Compare
Signed-off-by: danbugs <danilochiarlone@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
net_socket, preventing indefinite host-thread blockingsock.connect(&sa)?withsock.connect_timeout(&sa, SOCKET_TIMEOUT)?innet_connectto bound TCP connect timenet_recv,net_accept, andnet_connectcould block the host thread forever — a reliable single-call DoS against the sandboxnet_socket_has_default_timeouttestTest plan
cargo test --libpasses (54 tests)cargo clippycleancargo fmtclean