Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable single stepping once we've stepped over the breakpoint (fix #223) #224

Merged
merged 4 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/wtf/fuzzer_hevd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,24 @@ bool InsertTestcase(const uint8_t *Buffer, const size_t BufferSize) {
bool Init(const Options_t &Opts, const CpuState_t &) {

//
// Stop the test-case once we return back from the call [DeviceIoControl]
// Set a breakpoint on the first instruction just for fun. Also, that type of
// breakpoint would have caught this bug:
// `https://github.com/0vercl0k/wtf/issues/223`
//

const Gva_t Rip = Gva_t(g_Backend->Rip());
if (!g_Backend->SetBreakpoint(Rip, [](Backend_t *Backend) {
DebugPrint(
"This is a breakpoint executed before the first instruction :)\n");
})) {
DebugPrint("Failed to SetBreakpoint on first instruction\n");
return false;
}

//
// Stop the test-case once we return back from the call [DeviceIoControl]
//

const Gva_t AfterCall = Rip + Gva_t(6);
if (!g_Backend->SetBreakpoint(AfterCall, [](Backend_t *Backend) {
DebugPrint("Back from kernel!\n");
Expand Down
19 changes: 8 additions & 11 deletions src/wtf/kvm_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,8 @@ bool KvmBackend_t::OnExitDebug(struct kvm_debug_exit_arch &Debug) {
// fault.
//

KvmDebugPrint("Disarming bp and turning on RFLAGS.TF (rip={:#x})\n", Rip);
KvmDebugPrint("Disarming bp and will turn on single step (rip={:#x})\n",
Rip);
LastBreakpointGpa_ = Breakpoint.Gpa;

Ram_.RemoveBreakpoint(Breakpoint.Gpa);
Expand All @@ -1558,7 +1559,7 @@ bool KvmBackend_t::OnExitDebug(struct kvm_debug_exit_arch &Debug) {
//

if (TraceType_ != TraceType_t::Rip && !LastBreakpointGpa_) {
fmt::print("Got into OnDebugTrap with LastBreakpointGpa_ = none");
fmt::print("Got into OnDebugTrap with LastBreakpointGpa_ = none\n");
return false;
}

Expand All @@ -1568,7 +1569,7 @@ bool KvmBackend_t::OnExitDebug(struct kvm_debug_exit_arch &Debug) {
//

if (LastBreakpointGpa_) {
KvmDebugPrint("Resetting breakpoint @ {:#x}", *LastBreakpointGpa_);
KvmDebugPrint("Resetting breakpoint @ {:#x}\n", *LastBreakpointGpa_);

//
// Remember if we get there, it is because we hit a breakpoint, turned on
Expand All @@ -1580,12 +1581,7 @@ bool KvmBackend_t::OnExitDebug(struct kvm_debug_exit_arch &Debug) {
LastBreakpointGpa_.reset();
}

if (TraceType_ == TraceType_t::Rip) {
TrapFlag(true);
} else {
KvmDebugPrint("Turning off RFLAGS.TF\n");
}

TrapFlag(TraceType_ == TraceType_t::Rip ? true : false);
return true;
} else {
std::abort();
Expand Down Expand Up @@ -2651,13 +2647,14 @@ void KvmBackend_t::StaticSignalAlarm(int, siginfo_t *, void *) {
}

void KvmBackend_t::TrapFlag(const bool Arm) {
KvmDebugPrint("Turning on RFLAGS.TF\n");

struct kvm_guest_debug Dreg = {0};
Dreg.control = KVM_GUESTDBG_USE_SW_BP | KVM_GUESTDBG_ENABLE;

if (Arm) {
KvmDebugPrint("Turning on SINGLESTEP\n");
Dreg.control |= KVM_GUESTDBG_SINGLESTEP;
} else {
KvmDebugPrint("Turning off SINGLESTEP\n");
}

if (!SetDreg(Dreg)) {
Expand Down
Loading
Loading