From f1b650c4348297bcc3f76b6e422d28ebf7d8e1f9 Mon Sep 17 00:00:00 2001 From: Andrew Rogers Date: Mon, 28 Oct 2024 14:43:40 -0700 Subject: [PATCH 1/2] check memory region permission on breakpoint/watchpoint creation --- Sources/GDBRemote/DebugSessionImpl.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Sources/GDBRemote/DebugSessionImpl.cpp b/Sources/GDBRemote/DebugSessionImpl.cpp index b509d70c..cdd3c4b7 100644 --- a/Sources/GDBRemote/DebugSessionImpl.cpp +++ b/Sources/GDBRemote/DebugSessionImpl.cpp @@ -1093,30 +1093,48 @@ ErrorCode DebugSessionImplBase::onInsertBreakpoint( StringCollection const &commands, bool persistentCommands) { DS2ASSERT(conditions.empty() && commands.empty() && !persistentCommands); + MemoryRegionInfo info; + CHK(_process->getMemoryRegionInfo(address, info)); + BreakpointManager *bpm = nullptr; BreakpointManager::Mode mode; switch (type) { case kSoftwareBreakpoint: + if (!(info.protection & kProtectionExecute)) + return kErrorInvalidAddress; + bpm = _process->softwareBreakpointManager(); mode = BreakpointManager::kModeExec; break; case kHardwareBreakpoint: + if (!(info.protection & kProtectionExecute)) + return kErrorInvalidAddress; + bpm = _process->hardwareBreakpointManager(); mode = BreakpointManager::kModeExec; break; case kReadWatchpoint: + if (!(info.protection & kProtectionRead)) + return kErrorInvalidAddress; + bpm = _process->hardwareBreakpointManager(); mode = BreakpointManager::kModeRead; break; case kWriteWatchpoint: + if (!(info.protection & kProtectionWrite)) + return kErrorInvalidAddress; + bpm = _process->hardwareBreakpointManager(); mode = BreakpointManager::kModeWrite; break; case kAccessWatchpoint: + if (!(info.protection & (kProtectionRead | kProtectionWrite))) + return kErrorInvalidAddress; + bpm = _process->hardwareBreakpointManager(); mode = static_cast(BreakpointManager::kModeRead | BreakpointManager::kModeWrite); From 53f0beee333498abfc13336cd0879ab1084637cb Mon Sep 17 00:00:00 2001 From: Andrew Rogers Date: Mon, 28 Oct 2024 15:42:08 -0700 Subject: [PATCH 2/2] enable bad address breakpoint test --- Support/Testing/Excluded/ds2/android-x86_64.excluded | 1 - Support/Testing/Excluded/ds2/linux-x86_64.excluded | 1 - 2 files changed, 2 deletions(-) diff --git a/Support/Testing/Excluded/ds2/android-x86_64.excluded b/Support/Testing/Excluded/ds2/android-x86_64.excluded index 40780334..9030e37e 100644 --- a/Support/Testing/Excluded/ds2/android-x86_64.excluded +++ b/Support/Testing/Excluded/ds2/android-x86_64.excluded @@ -1,5 +1,4 @@ skip -TestBadAddressBreakpoints.BadAddressBreakpointTestCase.test_bad_address_breakpoints TestBreakpointSerialization.BreakpointSerialization.test_scripted_extra_args TestBreakpointSetRestart.BreakpointSetRestart.test_breakpoint_set_restart_dwarf TestBreakpointSetRestart.BreakpointSetRestart.test_breakpoint_set_restart_dwo diff --git a/Support/Testing/Excluded/ds2/linux-x86_64.excluded b/Support/Testing/Excluded/ds2/linux-x86_64.excluded index 1bd0602f..2acdd0d8 100644 --- a/Support/Testing/Excluded/ds2/linux-x86_64.excluded +++ b/Support/Testing/Excluded/ds2/linux-x86_64.excluded @@ -1,7 +1,6 @@ skip lldbsuite.test.lldbtest.TestPrintf.test_dwarf lldbsuite.test.lldbtest.TestPrintf.test_dwo -TestBadAddressBreakpoints.BadAddressBreakpointTestCase.test_bad_address_breakpoints TestBreakpointInGlobalConstructor.TestBreakpointInGlobalConstructors.test TestBreakpointSerialization.BreakpointSerialization.test_scripted_extra_args TestBreakpointSetRestart.BreakpointSetRestart.test_breakpoint_set_restart_dwo