Skip to content

fuzz(flatbuf): add fuzz harness for FunctionCall/FunctionCallResult decode - #1878

Open
Devendrakumarsinha wants to merge 1 commit into
hyperlight-dev:mainfrom
Devendrakumarsinha:fuzz/flatbuf-decode-harness
Open

Devendrakumarsinha wants to merge 1 commit into
hyperlight-dev:mainfrom
Devendrakumarsinha:fuzz/flatbuf-decode-harness

Conversation

@Devendrakumarsinha

Copy link
Copy Markdown

Summary

Adds a libfuzzer-based fuzz target that directly exercises the FlatBuffers
decode path for FunctionCall and FunctionCallResult — the host-side
parsing of guest-controlled wire data arriving via the G2H virtqueue.

Motivation

Existing fuzzers (guest_call, host_call) exercise these decode paths
only indirectly through a full sandbox with a running hypervisor. This
harness isolates the parsing logic without requiring KVM or Hyper-V,
enabling faster iteration and broader input coverage.

Design

BoundedSource mirrors RecvChain semantics: take_bytes/take_chunks
reject reads beyond available data, matching production behavior and
avoiding false OOM positives from unbounded test allocators.

Results

  • Coverage: ~960 branch points
  • exec/s: ~110,000 (no hypervisor overhead)
  • No crashes found

Testing

cargo +nightly fuzz run flatbuf_decode -- -max_len=65536

…ecode

Add a libfuzzer-based fuzz target that directly exercises the FlatBuffers
decode path for FunctionCall and FunctionCallResult — the host-side parsing
of guest-controlled wire data arriving via the G2H virtqueue.

Previously these decode paths had no direct fuzz coverage; existing fuzzers
(guest_call, host_call) exercise them only indirectly through a full sandbox.
This harness isolates the parsing logic without requiring a hypervisor.

Uses a BoundedSource that mirrors RecvChain semantics: take_bytes/take_chunks
reject reads beyond available data, matching production behavior.

Initial run (~1M iterations):
- Coverage: ~960 branch points
- exec/s: ~110,000
- No crashes found

Signed-off-by: Devendra Kumar Sinha <devendrasinha.me@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The harness does not currently reproduce production control and external-payload boundaries or trailing-byte validation.

3 open findings
What changed in this PR

Adds a fast fuzz target for FlatBuffers function call decoding without a hypervisor.

Changes:

  • Adds bounded external-value fuzzing.
  • Registers the fuzz target and dependencies.
  • Updates fuzz-generated file exclusions.
File Description
fuzz/​fuzz_targets/​flatbuf_decode.rs Implements the decode harness.
fuzz/​Cargo.toml Registers the target and dependencies.
fuzz/​.gitignore Updates fuzz output exclusions.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +40 to +41
fn finish(&mut self) -> anyhow::Result<()> {
Ok(())
Comment on lines +45 to +48
fuzz_target!(|data: &[u8]| {
let _ = FunctionCall::decode(data, &mut BoundedSource::new(data));
let _ = FunctionCallResult::decode(data, &mut BoundedSource::new(data));
});
Comment thread fuzz/.gitignore
coverage
corpus/
artifacts/
*.log
@andreiltd

andreiltd commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Hey @Devendrakumarsinha , thanks for the contribution! This looks very reasonable although those few comments from copilot about mirroring production code is worth addressing 🙂

@hyperlight-gh-bot

Copy link
Copy Markdown

Benchmark Results

Measured commit: 4c0441d2aba0
Baseline commit: 7d244de79713

kvm / amd (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 756.28 ns (➖ 1.04x faster)
vec_bytes 607.48 ns (➖ 1.04x slower)
373.94 µs (➖ 1.04x faster)

payload_allocation

slot_pool_segmented
262144 526.85 ns (➖ 1.01x slower)
65536 141.57 ns (➖ 1.00x faster)

sandboxes

create_initialized_and_drop
medium 79.91 ms (➖ 1.03x slower)

slot_pool

alloc_dealloc_1500 alloc_dealloc_4096 alloc_dealloc_128
7.75 ns (➖ 1.00x faster) 7.71 ns (➖ 1.00x faster) 7.77 ns (➖ 1.01x faster)

snapshot_files

load_snapshot_unverified
small 92.83 µs (➖ 1.01x slower)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
262144 7.40 µs (➖ 1.02x faster) 6.63 µs (➖ 1.13x faster)
65536 1.94 µs (➖ 1.08x faster) 2.06 µs (➖ 1.07x slower)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 6.19 µs (➖ 1.00x faster) 6.28 µs (➖ 1.01x faster)
8192 1.07 µs (➖ 1.09x faster) 1.04 µs (➖ 1.02x faster)
262144 27.28 µs (➖ 1.02x slower)
kvm / intel (Linux) (❌ 2.05x)

Top regressions

  • payload_allocation/slot_pool_segmented/65536 — ❌ 2.05x slower

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 815.18 ns (➖ 1.16x slower)
vec_bytes 620.70 ns (➖ 1.20x slower)
771.85 µs (➖ 1.14x slower)

payload_allocation

slot_pool_segmented
262144 596.05 ns (➖ 1.17x slower)
65536 301.35 ns (❌ 2.05x slower)

sandboxes

create_initialized_and_drop
medium 81.08 ms (➖ 1.06x slower)

slot_pool

alloc_dealloc_1500 alloc_dealloc_4096 alloc_dealloc_128
8.11 ns (➖ 1.17x slower) 8.13 ns (➖ 1.17x slower) 8.14 ns (➖ 1.17x slower)

snapshot_files

load_snapshot_unverified
small 53.66 µs (➖ 1.19x slower)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
262144 8.87 µs (➖ 1.18x slower) 8.94 µs (➖ 1.18x slower)
65536 2.55 µs (➖ 1.18x slower) 2.53 µs (➖ 1.18x slower)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 8.40 µs (➖ 1.18x slower) 8.36 µs (➖ 1.17x slower)
8192 869.59 ns (➖ 1.19x slower) 847.77 ns (➖ 1.17x slower)
262144 34.25 µs (➖ 1.17x slower)
mshv3 / amd (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 958.35 ns (➖ 1.01x slower)
vec_bytes 719.91 ns (➖ 1.02x slower)
326.76 µs (➖ 1.05x slower)

payload_allocation

slot_pool_segmented
262144 676.34 ns (➖ 1.09x faster)
65536 191.08 ns (➖ 1.04x faster)

sandboxes

create_initialized_and_drop
medium 57.92 ms (➖ 1.01x faster)

slot_pool

alloc_dealloc_1500 alloc_dealloc_4096 alloc_dealloc_128
9.97 ns (➖ 1.03x slower) 10.00 ns (➖ 1.03x slower) 9.92 ns (➖ 1.02x slower)

snapshot_files

load_snapshot_unverified
small 86.93 µs (➖ 1.03x slower)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
262144 9.11 µs (➖ 1.04x faster) 9.59 µs (➖ 1.04x slower)
65536 2.66 µs (➖ 1.17x slower) 2.49 µs (➖ 1.09x slower)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 8.04 µs (➖ 1.01x faster) 8.22 µs (➖ 1.02x faster)
8192 1.47 µs (➖ 1.14x slower) 1.54 µs (➖ 1.14x slower)
262144 34.79 µs (➖ 1.04x faster)
mshv3 / intel (Linux) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 939.91 ns (➖ 1.14x slower)
vec_bytes 675.93 ns (➖ 1.13x slower)
692.79 µs (➖ 1.08x faster)

payload_allocation

slot_pool_segmented
262144 1.04 µs (➖ 1.38x slower)
65536 167.55 ns (➖ 1.03x slower)

sandboxes

create_initialized_and_drop
medium 67.92 ms (➖ 1.15x slower)

slot_pool

alloc_dealloc_1500 alloc_dealloc_4096 alloc_dealloc_128
8.77 ns (➖ 1.05x slower) 8.79 ns (➖ 1.07x slower) 8.88 ns (➖ 1.08x slower)

snapshot_files

load_snapshot_unverified
small 44.48 µs (➖ 1.01x slower)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
262144 8.05 µs (➖ 1.11x faster) 7.99 µs (➖ 1.12x faster)
65536 2.29 µs (➖ 1.10x faster) 2.28 µs (➖ 1.10x faster)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 7.51 µs (➖ 1.12x faster) 7.53 µs (➖ 1.12x faster)
8192 882.78 ns (➖ 1.01x slower) 872.34 ns (➖ 1.00x slower)
262144 37.14 µs (➖ 1.02x faster)
hyperv-ws2025 / amd (Windows) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 1.39 µs (➖ 1.22x slower)
vec_bytes 1.04 µs (➖ 1.16x slower)
2.00 ms (➖ 1.08x faster)

payload_allocation

slot_pool_segmented
262144 782.43 ns (➖ 1.01x faster)
65536 229.50 ns (➖ 1.01x faster)

sandboxes

create_initialized_and_drop
medium 84.54 ms (➖ 1.04x faster)

slot_pool

alloc_dealloc_1500 alloc_dealloc_4096 alloc_dealloc_128
10.55 ns (➖ 1.06x slower) 10.68 ns (➖ 1.10x slower) 10.54 ns (➖ 1.04x slower)

snapshot_files

load_snapshot_unverified
small 606.79 µs (➖ 1.25x faster)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
262144 8.72 µs (➖ 1.12x faster) 8.70 µs (➖ 1.13x faster)
65536 2.54 µs (➖ 1.06x slower) 2.56 µs (➖ 1.07x slower)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 8.96 µs (➖ 1.04x faster) 9.13 µs (➖ 1.00x slower)
8192 1.35 µs (➖ 1.01x faster) 1.35 µs (➖ 1.06x slower)
262144 44.84 µs (➖ 1.22x slower)
hyperv-ws2025 / intel (Windows) (➖ stable)

No benchmark improved or regressed.

Benchmark Results

function_call_codec

encode_control decode_vec_bytes_copy
byte_chunks 1.22 µs (➖ 1.02x slower)
vec_bytes 799.91 ns (➖ 1.01x slower)
2.94 ms (➖ 1.06x faster)

payload_allocation

slot_pool_segmented
262144 732.60 ns (➖ 1.06x faster)
65536 213.58 ns (➖ 1.00x slower)

sandboxes

create_initialized_and_drop
medium 111.76 ms (➖ 1.03x slower)

slot_pool

alloc_dealloc_1500 alloc_dealloc_4096 alloc_dealloc_128
9.99 ns (➖ 1.01x faster) 10.05 ns (➖ 1.01x faster) 10.57 ns (➖ 1.01x faster)

snapshot_files

load_snapshot_unverified
small 586.82 µs (➖ 1.03x faster)

virtq_readonly

slot_pool_segmented_fragmented slot_pool_segmented
262144 7.83 µs (➖ 1.02x slower) 7.76 µs (➖ 1.02x faster)
65536 2.33 µs (➖ 1.03x slower) 2.33 µs (➖ 1.00x slower)

virtq_readwrite

slot_pool_segmented_fragmented slot_pool_segmented
65536 8.51 µs (➖ 1.01x faster) 8.53 µs (➖ 1.03x faster)
8192 1.16 µs (➖ 1.10x faster) 1.19 µs (➖ 1.06x slower)
262144 41.20 µs (➖ 1.05x faster)

Reported by cargo ci bench-report --candidate run:37181799341 --baseline run:37247276888 --config-file bench_report.toml.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants