Skip to content

Commit

Permalink
More diagnostics
Browse files Browse the repository at this point in the history
Signed-off-by: Alan Jowett <[email protected]>
  • Loading branch information
Alan Jowett committed Oct 17, 2024
1 parent 85dc99a commit f7df350
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion libfuzzer/libfuzz_harness.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ extern "C"
#include "test_helpers.h"
#include <cassert>

std::string g_verifier_report;

/**
* @brief Context structure passed to the BPF program. Modeled after the context structure used by XDP.
*/
Expand Down Expand Up @@ -304,6 +306,8 @@ try {

// Enable termination checking and pre-invariant storage.
options.check_termination = true;
options.assume_assertions = true;
options.print_invariants = true;
#if defined(UBPF_ENABLE_LIBFUZZER_CONSTRAINT_CHECK)
options.store_pre_invariants = true;
#endif
Expand All @@ -317,7 +321,10 @@ try {
std::ostringstream error_stream;

// Verify the program. This will return false or throw an exception if the program is invalid.
return ebpf_verify_program(error_stream, prog, raw_prog.info, &options, &stats);
bool result = ebpf_verify_program(error_stream, prog, raw_prog.info, &options, &stats);
g_verifier_report = error_stream.str();

return result;
} catch (const std::exception& ex) {
return false;
}
Expand Down Expand Up @@ -450,6 +457,7 @@ ubpf_debug_function(
ubpf_context_t* ubpf_context = reinterpret_cast<ubpf_context_t*>(context);
UNREFERENCED_PARAMETER(stack_start);
UNREFERENCED_PARAMETER(stack_length);
UNREFERENCED_PARAMETER(stack_mask);

std::string label = std::to_string(program_counter) + ":-1";

Expand Down Expand Up @@ -493,6 +501,9 @@ ubpf_debug_function(
constraints.insert(
"r" + std::to_string(i) + ".svalue=" + std::to_string(static_cast<int64_t>(registers[i])));
break;
case address_type_t::Map:
constraints.insert(register_name + ".type=shared");
break;
}
}

Expand Down Expand Up @@ -591,6 +602,7 @@ call_ubpf_interpreter(

// Execute the program using the input memory.
if (ubpf_exec_ex(vm.get(), &context, sizeof(context), &interpreter_result, ubpf_stack.data(), ubpf_stack.size()) != 0) {
std::cerr << g_verifier_report << std::endl;
throw std::runtime_error("Failed to execute program with error: " + g_error_message);
}

Expand Down

0 comments on commit f7df350

Please sign in to comment.