Skip to content

fuzz: fix kernel_params fuzzer crash on validation panics - #201

Merged
zvonkok merged 3 commits into
NVIDIA:mainfrom
zvonkok:fix/fuzz-kernel-params-result
Jul 15, 2026
Merged

fuzz: fix kernel_params fuzzer crash on validation panics#201
zvonkok merged 3 commits into
NVIDIA:mainfrom
zvonkok:fix/fuzz-kernel-params-result

Conversation

@zvonkok

@zvonkok zvonkok commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

cargo-fuzz forces -C panic=abort via RUSTFLAGS. With that flag set,
catch_unwind is silently a no-op: every .expect() in the numeric
parsers aborts the process and libFuzzer records it as a crash.

Introduce try_process_kernel_params() returning Result<(), String>.
The production API is unchanged: process_kernel_params() delegates to
the try_ variant and .unwrap_or_else(|e| panic!("{e}")) preserves
fail-fast behavior. The fuzz target calls try_process_kernel_params()
so validation errors (invalid freq/wattage) surface as Err and are
ignored; genuine parser bugs still abort and are caught by libFuzzer.

std::process::exit flushes stdio and runs atexit handlers, which acquire
locks. In a forked child of the multi-threaded test harness, a parallel
test thread may hold the stderr mutex at fork time, leaving it permanently
locked in the child. eprintln! and std::process::exit then deadlock, causing
test_fork_agent_with_timeout to hang indefinitely.

Replace with libc::write(2, ...) and libc::_exit, which are
async-signal-safe and bypass all stdio/atexit locks.

Signed-off-by: Zvonko Kaiser <zkaiser@nvidia.com>
Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 15, 2026 15:01

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@zvonkok zvonkok added the ok-to-test Ok to test label Jul 15, 2026
@zvonkok
zvonkok requested a review from Copilot July 15, 2026 18:10

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@zvonkok
zvonkok force-pushed the fix/fuzz-kernel-params-result branch from 627e405 to f3f240e Compare July 15, 2026 22:51
Copilot AI review requested due to automatic review settings July 15, 2026 22:51

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot removed the ok-to-test Ok to test label Jul 15, 2026
zvonkok added 2 commits July 15, 2026 22:57
libc::_exit skips atexit handlers, which is where the LLVM profile
runtime writes .profraw files. The forked children that panic in the
kata_agent tests exited without recording coverage, dropping
kata_agent.rs below the 90% per-file gate.

Under cfg(coverage) call __llvm_profile_write_file() explicitly before
_exit. The profraw pattern contains %p, so each child writes its own
file without clobbering the parent's.

Signed-off-by: Zvonko Kaiser <zkaiser@nvidia.com>
Assisted-By: Claude Fable 5 <noreply@anthropic.com>
cargo-fuzz forces -C panic=abort via RUSTFLAGS, so catch_unwind is
silently a no-op: every .expect() call in the numeric parsers aborts
the process and libFuzzer records it as a crash.

Introduce try_process_kernel_params() returning Result<(), String> as
the Result-based twin of process_kernel_params(). The production API
is unchanged: process_kernel_params() delegates to the try_ variant
and unwrap_or_else(|e| panic!("{e}")) preserves fail-fast behavior.
The fuzz target calls try_process_kernel_params() so validation errors
(invalid freq/wattage) surface as Err and are ignored; any unexpected
panic from a genuine parser bug still aborts and is caught by libFuzzer.

Signed-off-by: Zvonko Kaiser <zkaiser@nvidia.com>
Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@zvonkok
zvonkok force-pushed the fix/fuzz-kernel-params-result branch from f3f240e to 1d27728 Compare July 15, 2026 23:01
Copilot AI review requested due to automatic review settings July 15, 2026 23:01

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@zvonkok zvonkok added the ok-to-test Ok to test label Jul 15, 2026
@zvonkok
zvonkok enabled auto-merge July 15, 2026 23:23
@zvonkok
zvonkok merged commit 8139d4c into NVIDIA:main Jul 15, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Ok to test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants