Skip to content

Commit 2e7f67a

Browse files
authored
check memory region permission on breakpoint/watchpoint creation (#166)
## Purpose When a `Z` packet it sent to set a breakpoint or watchpoint, check the access mask for the containing memory region and fail if it doesn't make sense for the requested breakpoint/watchpoint type. ## Overview * For hardware and software breakpoints, fail if the containing memory region is not executable * For read watchpoints, fail if the containing memory region is not readable * For write watchpoints, fail if the containing memory region is not writeable * For access watchpoints, fail if the containing memory region is not either readable or writable. * Enable the `TestBadAddressBreakpoints.BadAddressBreakpointTestCase.test_bad_address_breakpoints` lldb test case that was failing because of the missing checks ## Validation GitHub build & test job
1 parent fc833ca commit 2e7f67a

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

Sources/GDBRemote/DebugSessionImpl.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,30 +1093,48 @@ ErrorCode DebugSessionImplBase::onInsertBreakpoint(
10931093
StringCollection const &commands, bool persistentCommands) {
10941094
DS2ASSERT(conditions.empty() && commands.empty() && !persistentCommands);
10951095

1096+
MemoryRegionInfo info;
1097+
CHK(_process->getMemoryRegionInfo(address, info));
1098+
10961099
BreakpointManager *bpm = nullptr;
10971100
BreakpointManager::Mode mode;
10981101
switch (type) {
10991102
case kSoftwareBreakpoint:
1103+
if (!(info.protection & kProtectionExecute))
1104+
return kErrorInvalidAddress;
1105+
11001106
bpm = _process->softwareBreakpointManager();
11011107
mode = BreakpointManager::kModeExec;
11021108
break;
11031109

11041110
case kHardwareBreakpoint:
1111+
if (!(info.protection & kProtectionExecute))
1112+
return kErrorInvalidAddress;
1113+
11051114
bpm = _process->hardwareBreakpointManager();
11061115
mode = BreakpointManager::kModeExec;
11071116
break;
11081117

11091118
case kReadWatchpoint:
1119+
if (!(info.protection & kProtectionRead))
1120+
return kErrorInvalidAddress;
1121+
11101122
bpm = _process->hardwareBreakpointManager();
11111123
mode = BreakpointManager::kModeRead;
11121124
break;
11131125

11141126
case kWriteWatchpoint:
1127+
if (!(info.protection & kProtectionWrite))
1128+
return kErrorInvalidAddress;
1129+
11151130
bpm = _process->hardwareBreakpointManager();
11161131
mode = BreakpointManager::kModeWrite;
11171132
break;
11181133

11191134
case kAccessWatchpoint:
1135+
if (!(info.protection & (kProtectionRead | kProtectionWrite)))
1136+
return kErrorInvalidAddress;
1137+
11201138
bpm = _process->hardwareBreakpointManager();
11211139
mode = static_cast<BreakpointManager::Mode>(BreakpointManager::kModeRead |
11221140
BreakpointManager::kModeWrite);

Support/Testing/Excluded/ds2/android-x86_64.excluded

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
skip
2-
TestBadAddressBreakpoints.BadAddressBreakpointTestCase.test_bad_address_breakpoints
32
TestBreakpointSerialization.BreakpointSerialization.test_scripted_extra_args
43
TestBreakpointSetRestart.BreakpointSetRestart.test_breakpoint_set_restart_dwarf
54
TestBreakpointSetRestart.BreakpointSetRestart.test_breakpoint_set_restart_dwo

Support/Testing/Excluded/ds2/linux-x86_64.excluded

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
skip
22
lldbsuite.test.lldbtest.TestPrintf.test_dwarf
33
lldbsuite.test.lldbtest.TestPrintf.test_dwo
4-
TestBadAddressBreakpoints.BadAddressBreakpointTestCase.test_bad_address_breakpoints
54
TestBreakpointInGlobalConstructor.TestBreakpointInGlobalConstructors.test
65
TestBreakpointSerialization.BreakpointSerialization.test_scripted_extra_args
76
TestBreakpointSetRestart.BreakpointSetRestart.test_breakpoint_set_restart_dwo

0 commit comments

Comments
 (0)