Fix: Prevent DoS from Malformed ELF Binaries #2480
Open
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.
Fix: Prevent DoS from Malformed ELF Binaries
Summary
This PR addresses a critical security vulnerability where malformed ELF binaries could cause the SP1 prover to panic, resulting in a Denial of Service (DoS) condition. This issue was discovered during a security audit where the SP1 library was causing DoS on a client's node.
Problem
The
setup()method and related functions were using.unwrap()calls when parsing ELF binaries and setting up the prover. When a malformed ELF binary was provided, these unwrap calls would cause the application to panic and crash entirely.Reproduction
The following code demonstrates the vulnerability with a malformed ELF binary:
Changes
1. Core Changes - Proper Error Propagation
crates/prover/src/lib.rs: ModifiedSP1Prover::setup()to returnResultinstead of panicking on invalid ELFeyre::Result<(...)>Program::from(elf)calls with descriptive error messagescrates/prover/src/build.rs: Updateddummy_proof()to handle setup errors gracefully with panic message2. SDK Layer - Result Type Updates
Updated all SDK prover implementations to propagate errors properly:
crates/sdk/src/prover.rs: Changed trait definition ofProver::setup()to returnResult<(SP1ProvingKey, SP1VerifyingKey), Error>crates/sdk/src/cpu/mod.rs: UpdatedCpuProver::setup()implementationcrates/sdk/src/cuda/mod.rs: UpdatedCudaProver::setup()implementationcrates/sdk/src/env/mod.rs: UpdatedEnvProver::setup()implementationcrates/sdk/src/network/prover.rs: UpdatedNetworkProver::setup()implementation3. Build Tools
crates/build/src/lib.rs: Updatedvkey()andvkeys()functions to returnResultand handle setup errorsError Messages
The error messages in this PR are functional but may not be ideal for your use case. Error messages currently use generic formats like:
Feel free to modify these error messages to be more specific, user-friendly, or aligned with your project's error handling conventions. The important fix is the proper error propagation rather than panicking.
Breaking Changes
This is a breaking change for any code that calls the
setup()method, as it now returns aResultinstead of a tuple. Callers will need to handle the potential error case:Before:
After:
Security Impact
This fix prevents malicious or malformed ELF binaries from crashing applications that use the SP1 SDK. Instead of a panic that brings down the entire process, errors are now properly propagated and can be handled by the calling code, allowing for graceful degradation and proper error logging.
This PR was created based on findings from a security audit where SP1 was integrated into a client's system.
Made by FuzzingLabs