Skip to content

Commit ae7b5af

Browse files
authored
[lldb] Remove ConnectionFileDescriptor::child_process_inherit (#115861)
It's never set to true. Inheritable FDs are also dangerous as they can end up processes which know nothing about them. It's better to explicitly pass a specific FD to a specific subprocess, which we already mostly can do using the ProcessLaunchInfo FileActions.
1 parent a4f3a10 commit ae7b5af

File tree

2 files changed

+9
-26
lines changed

2 files changed

+9
-26
lines changed

lldb/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ConnectionFileDescriptor : public Connection {
3131
typedef llvm::function_ref<void(llvm::StringRef local_socket_id)>
3232
socket_id_callback_type;
3333

34-
ConnectionFileDescriptor(bool child_processes_inherit = false);
34+
ConnectionFileDescriptor();
3535

3636
ConnectionFileDescriptor(int fd, bool owns_fd);
3737

@@ -65,9 +65,6 @@ class ConnectionFileDescriptor : public Connection {
6565

6666
lldb::IOObjectSP GetReadObject() override { return m_io_sp; }
6767

68-
bool GetChildProcessesInherit() const;
69-
void SetChildProcessesInherit(bool child_processes_inherit);
70-
7168
protected:
7269
void OpenCommandPipe();
7370

@@ -135,7 +132,6 @@ class ConnectionFileDescriptor : public Connection {
135132
std::atomic<bool> m_shutting_down; // This marks that we are shutting down so
136133
// if we get woken up from
137134
// BytesAvailable to disconnect, we won't try to read again.
138-
bool m_child_processes_inherit;
139135

140136
std::string m_uri;
141137

lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,15 @@
5252
using namespace lldb;
5353
using namespace lldb_private;
5454

55-
ConnectionFileDescriptor::ConnectionFileDescriptor(bool child_processes_inherit)
56-
: Connection(), m_pipe(), m_mutex(), m_shutting_down(false),
57-
58-
m_child_processes_inherit(child_processes_inherit) {
55+
ConnectionFileDescriptor::ConnectionFileDescriptor()
56+
: Connection(), m_pipe(), m_mutex(), m_shutting_down(false) {
5957
Log *log(GetLog(LLDBLog::Connection | LLDBLog::Object));
6058
LLDB_LOGF(log, "%p ConnectionFileDescriptor::ConnectionFileDescriptor ()",
6159
static_cast<void *>(this));
6260
}
6361

6462
ConnectionFileDescriptor::ConnectionFileDescriptor(int fd, bool owns_fd)
65-
: Connection(), m_pipe(), m_mutex(), m_shutting_down(false),
66-
m_child_processes_inherit(false) {
63+
: Connection(), m_pipe(), m_mutex(), m_shutting_down(false) {
6764
m_io_sp =
6865
std::make_shared<NativeFile>(fd, File::eOpenOptionReadWrite, owns_fd);
6966

@@ -76,8 +73,7 @@ ConnectionFileDescriptor::ConnectionFileDescriptor(int fd, bool owns_fd)
7673
}
7774

7875
ConnectionFileDescriptor::ConnectionFileDescriptor(Socket *socket)
79-
: Connection(), m_pipe(), m_mutex(), m_shutting_down(false),
80-
m_child_processes_inherit(false) {
76+
: Connection(), m_pipe(), m_mutex(), m_shutting_down(false) {
8177
InitializeSocket(socket);
8278
}
8379

@@ -94,7 +90,7 @@ void ConnectionFileDescriptor::OpenCommandPipe() {
9490

9591
Log *log = GetLog(LLDBLog::Connection);
9692
// Make the command file descriptor here:
97-
Status result = m_pipe.CreateNew(m_child_processes_inherit);
93+
Status result = m_pipe.CreateNew(/*child_processes_inherit=*/false);
9894
if (!result.Success()) {
9995
LLDB_LOGF(log,
10096
"%p ConnectionFileDescriptor::OpenCommandPipe () - could not "
@@ -539,7 +535,7 @@ lldb::ConnectionStatus ConnectionFileDescriptor::AcceptSocket(
539535
Status *error_ptr) {
540536
Status error;
541537
std::unique_ptr<Socket> listening_socket =
542-
Socket::Create(socket_protocol, m_child_processes_inherit, error);
538+
Socket::Create(socket_protocol, /*child_processes_inherit=*/false, error);
543539
Socket *accepted_socket;
544540

545541
if (!error.Fail())
@@ -567,7 +563,7 @@ ConnectionFileDescriptor::ConnectSocket(Socket::SocketProtocol socket_protocol,
567563
Status *error_ptr) {
568564
Status error;
569565
std::unique_ptr<Socket> socket =
570-
Socket::Create(socket_protocol, m_child_processes_inherit, error);
566+
Socket::Create(socket_protocol, /*child_processes_inherit=*/false, error);
571567

572568
if (!error.Fail())
573569
error = socket->Connect(socket_name);
@@ -649,7 +645,7 @@ ConnectionFileDescriptor::ConnectUDP(llvm::StringRef s,
649645
if (error_ptr)
650646
*error_ptr = Status();
651647
llvm::Expected<std::unique_ptr<UDPSocket>> socket =
652-
Socket::UdpConnect(s, m_child_processes_inherit);
648+
Socket::UdpConnect(s, /*child_processes_inherit=*/false);
653649
if (!socket) {
654650
if (error_ptr)
655651
*error_ptr = Status::FromError(socket.takeError());
@@ -798,15 +794,6 @@ ConnectionStatus ConnectionFileDescriptor::ConnectSerialPort(
798794
llvm_unreachable("this function should be only called w/ LLDB_ENABLE_POSIX");
799795
}
800796

801-
bool ConnectionFileDescriptor::GetChildProcessesInherit() const {
802-
return m_child_processes_inherit;
803-
}
804-
805-
void ConnectionFileDescriptor::SetChildProcessesInherit(
806-
bool child_processes_inherit) {
807-
m_child_processes_inherit = child_processes_inherit;
808-
}
809-
810797
void ConnectionFileDescriptor::InitializeSocket(Socket *socket) {
811798
m_io_sp.reset(socket);
812799
m_uri = socket->GetRemoteConnectionURI();

0 commit comments

Comments
 (0)