This is an archive of the discontinued LLVM Phabricator instance.

Verify memory address range validity in GDBRemoteCommunicationClient
ClosedPublic

Authored by xiaobai on Mar 29 2017, 5:12 PM.

Details

Summary

This aims to verify the validity of the response from the debugging
server in GDBRemoteCommunicationClient::GetMemoryRegionInfo. I was
working with ds2 (https://github.com/facebook/ds2) and encountered a bug
that caused the server's response to have a 'size' value of 0, which
caused lldb to behave incorrectly.

Diff Detail

Repository
rL LLVM

Event Timeline

xiaobai created this revision.Mar 29 2017, 5:12 PM
sas added a subscriber: clayborg.

Doing additional checking on the packets returned over the wire seems decent to me. CC'ing @clayborg to see what he thinks about it also.

labath edited edge metadata.Mar 30 2017, 8:43 AM

The additional check sounds fine. There's a test for this class in unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp where you can add a test for this behavior.

clayborg requested changes to this revision.Mar 30 2017, 2:19 PM

Simple logic change so we don't check the range validity more than once.

source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
1506–1510 ↗(On Diff #93427)

Logic is fine, but I would work this into the if statement below. Something like:

if (region_info.GetRange().IsValid()) {
  if (!saw_permissions) {
    region_info.SetReadable(MemoryRegionInfo::eNo);
    region_info.SetWritable(MemoryRegionInfo::eNo);
    region_info.SetExecutable(MemoryRegionInfo::eNo);
    region_info.SetMapped(MemoryRegionInfo::eNo);
  }
} else {
  // We got an invalid address range back
  error.SetErrorString("Server returned invalid range");
}
This revision now requires changes to proceed.Mar 30 2017, 2:19 PM
xiaobai updated this revision to Diff 93566.Mar 30 2017, 4:51 PM
xiaobai edited edge metadata.

Added unit tests for the method and changed the logic according to clayborg's suggestion.

xiaobai marked an inline comment as done.Mar 30 2017, 4:52 PM
xiaobai added inline comments.
source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
1506–1510 ↗(On Diff #93427)

Thanks for pointing that out!

clayborg accepted this revision.Mar 30 2017, 6:31 PM

Looks good.

This revision is now accepted and ready to land.Mar 30 2017, 6:31 PM
labath accepted this revision.Mar 31 2017, 3:00 AM

Thank you for adding the test. Lgtm, assuming the second getmemoryregioninfo call is accidental.

unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
373 ↗(On Diff #93566)

This seems out of place. Should we delete it?

xiaobai marked an inline comment as done.Mar 31 2017, 9:34 AM

I'll resubmit after removing the extra code in the test and get somebody to commit for me.

unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
373 ↗(On Diff #93566)

Whoops! I was going to extend this test further but I decided not to in the end and forgot to remove this. Thanks for pointing it out.

xiaobai updated this revision to Diff 93674.Mar 31 2017, 9:40 AM

Removed extra code in unit test

This revision was automatically updated to reflect the committed changes.