Open Bug 2084916 Opened 25 days ago Updated 25 days ago

SocketProcessHost leaks when the socket process crashes unexpectedly (OnChannelClosed listener branch never queues Destroy)

Categories

(Core :: Networking, defect, P5)

defect

Tracking

()

UNCONFIRMED

People

(Reporter: jeon1691, Unassigned)

References

Details

(Whiteboard: [necko-triaged])

When the socket process dies uncleanly, the parent-side SocketProcessHost object is leaked: no path reaches GeckoChildProcessHost::Destroy(), which is the only code that deletes the host (delete this, ipc/glue/GeckoChildProcessHost.cpp:490-518).

Chain (all line numbers verified on mozilla-central tip 4cc8cf47):

  1. Socket process crashes -> SocketProcessParent::ActorDestroy (netwerk/ipc/SocketProcessParent.cpp:74) -> SocketProcessHost::OnChannelClosed() (netwerk/ipc/SocketProcessHost.cpp:219). It sets mChannelClosed = true (:228); since mShutdownRequested is false and mListener is set, it takes the listener branch and calls mListener->OnProcessUnexpectedShutdown(this) (:230-232). Unlike the UtilityProcessHost twin (below), this branch does not fall through to DestroyProcess() - only the else branch does (:233-235).

  2. The listener (nsIOService via SocketProcessListenerProxy, netwerk/base/nsIOService.cpp:576-582) -> nsIOService::OnProcessUnexpectedShutdown (:769) -> DestroySocketProcess() (:773), which runs mSocketProcess->Shutdown(); mSocketProcess = nullptr; (:652-653). nsIOService holds the host through a raw pointer (nsIOService.h:264), so the sole owner has now forgotten the object.

  3. The re-entrant Shutdown() (SocketProcessHost.cpp:197-217) cannot schedule destruction either: the actor is still alive (mSocketProcessParent is released only later, at OnChannelClosed:238) and mChannelClosed was already set at :228, so Shutdown() takes the early return at :213 without calling DestroyProcess(). This also violates the documented contract in SocketProcessHost.h:56-58: "When Shutdown() returns, it is safe for the caller to forget its pointer to the SocketProcessHost."

  4. Back in OnChannelClosed, the actor is released (:238) and the function returns. Nothing queued the [this] { Destroy(); } lambda from DestroyProcess() (:242-250), so delete this never runs. The leaked host also keeps its entry in the sGeckoChildProcessHosts list, since RemoveFromProcessList() only happens inside Destroy() (:493).

  5. nsIOService then relaunches a fresh host (nsIOService.cpp:795-798 -> LaunchSocketProcess :629), so every unclean crash leaks exactly one SocketProcessHost. Default builds are bounded by network.max_socket_process_failed_count (default 1, modules/libpref/init/StaticPrefList.yaml:17575-17577), which stops using the socket process after repeated crashes; with the pref raised (fuzzing/automation configs) this accumulates leak-per-crash.

Contrast with the utility-process twin: UtilityProcessHost::OnChannelClosed (ipc/glue/UtilityProcessHost.cpp:314-332) notifies its listener (:323-326) and then calls DestroyProcess() unconditionally (:328), so a Destroy is always queued and no leak occurs.

Suggested fix: mirror the twin - have SocketProcessHost::OnChannelClosed call DestroyProcess() after the listener notification as well. The re-entrant Shutdown() from the listener is harmless in that case: with the actor present and the channel already closed it just returns.

Not security-sensitive: this is a plain leak, no dangling pointer is involved (the owner nulls its raw pointer synchronously and nothing re-touches the host afterwards).

Reproduction context: found while fuzzing the socket process IPC (frequent deliberate socket-process crashes); each crash-and-relaunch cycle leaves one more unreachable host allocation in the parent process.

We're removing SocketProcess, so this won't be relevant soon.

Severity: -- → S4
Depends on: 2077172
Priority: -- → P5
Whiteboard: [necko-triaged]
You need to log in before you can comment on or make changes to this bug.