<div dir="ltr">Hello,<div><br></div><div>I was playing with LLDB remote debugging and stumbled upon a few network issues. Presumably, such issues may prevent lldb from connecting to debugserver:</div><div><br></div><div>1. qLaunchGDBServer takes host's local hostname (like $qLaunchGDBServer;host:ovyalov-linux...;#..), so lldb-platform may pass this hostname to debugserver via command line. As I can see, debugserver uses this hostname for authentication purposes - only incoming connection from this host is allowed. There are a few possible problems here:</div><div><ul><li>Host's hostname may be just a local network name and in case of debugging over the Internet target cannot resolve it.</li><li>If host has multiple IPs there is no way to figure out which IP will be chosen by host to connect to debugserver (unless lldb has option to specify a local bind address). So, there is a likelihood that such connection will be rejected by debugserver.</li><li>As a variation of previous issue - host and target are on the same machine and connected via remote-* platform as "connect://localhost:some_port". If host binds a socket to any local address excluding 127.0.0.1 - connection is rejected by debugserver.</li><li>If host cannot get his own host name(<a href="https://github.com/llvm-mirror/lldb/blob/ba1d944f0e761c277e6caba23a818b9d2083c40b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp#L2838">https://github.com/llvm-mirror/lldb/blob/ba1d944f0e761c277e6caba23a818b9d2083c40b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp#L2838</a>) LLDB allows any inbound connection to debugserver. This affects debugging security allowing anybody to connect  debugserver and maybe even broken right now - when platform parses "$qLaunchGDBServer;host:*;"  it treats * as a beginning of RLE sequence and eventually starts debugserver allowing only connections from localhost.</li></ul><div>Potentially, we may use hash authentication instead of using IP address:</div><div> - lldb may generate a random hash which will be sent along with qLaunchGDBServer (instead of host parameter). </div><div> - lldb-platform passes auth hash to debugserver via command line.</div><div> - debugserver expects to receive new packet with auth hash and verifies that received hash matches the hash provided by platform.</div><div>Such change will definitely complicates interaction between lldb and debugserver but on other hand will make LLDB networking more robust.</div><div><br></div><div>As an easier workaround lldb can take local IP address (as a setting option or command line flag) which will be used for outgoing TCP connections (i.e. Socket::TcpConnect will bind to it) and will be sent as a host option of qLaunchGDBServer request. It's still not perfect and won't work in case of debugging over Internet, since most likely remote target will get incoming connection from host's gateway/NAT IP. </div><div><br></div><div>2. Another problem that I found that once qLaunchGDBServer succeeded, lldb tries to establish connection to debugserver, but instead of platform connect address a target's host name is used - <a href="https://github.com/llvm-mirror/lldb/blob/f06d448a750ebf88851791237077bb2a665f9784/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp#L486">https://github.com/llvm-mirror/lldb/blob/f06d448a750ebf88851791237077bb2a665f9784/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp#L486</a>. In case of debugging over the Internet, this may not work and it might be a safer option to re-use the platform's address when connecting to debugserver.</div><div><br></div><div>Please let me know your opinion and whether it sounds reasonable to you.</div><div><br></div><div>Thank you.  </div></div><div><br></div><div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><span style="color:rgb(85,85,85);font-family:sans-serif;line-height:20px;border-width:2px 0px 0px;border-style:solid;border-color:rgb(213,15,37);padding-top:2px;margin-top:2px;background-color:rgb(255,255,255)">Oleksiy Vyalov |</span><span style="color:rgb(85,85,85);font-family:sans-serif;line-height:20px;border-width:2px 0px 0px;border-style:solid;border-color:rgb(51,105,232);padding-top:2px;margin-top:2px;background-color:rgb(255,255,255)"> Software Engineer |</span><span style="color:rgb(85,85,85);font-family:sans-serif;line-height:20px;border-width:2px 0px 0px;border-style:solid;border-color:rgb(0,153,57);padding-top:2px;margin-top:2px;background-color:rgb(255,255,255)"> <a href="mailto:ovyalov@google.com" target="_blank">ovyalov<font color="#1155cc">@google.com</font></a></span></div></div>
</div></div>