Skip to content

libtailscale: mark handed-out fds close-on-exec - #71

Merged
raggi merged 1 commit into
mainfrom
raggi/libtailscale-5ae05cb1
Oct 30, 2026
Merged

raggi merged 1 commit into
mainfrom
raggi/libtailscale-5ae05cb1

Conversation

@raggi

@raggi raggi commented Oct 29, 2026

Copy link
Copy Markdown
Member

The listener and connection socketpairs and the fds received over
SCM_RIGHTS were inheritable across fork/exec, so any process the host
spawned kept a copy alive after the host closed its own fd. Closing a
listener or connection then delivered no EOF until every such child
had exited.

Create every socketpair close-on-exec (SOCK_CLOEXEC on Linux,
CloseOnExec under ForkLock.RLock elsewhere), and receive connection
fds with MSG_CMSG_CLOEXEC on Linux or an immediate CloseOnExec on
platforms without it.

Fixes tailscale/tailscale#22054

Signed-off-by: James Tucker james@tailscale.com

@raggi
raggi marked this pull request as ready for review October 29, 2026 23:55
The listener and connection socketpairs and the fds received over
SCM_RIGHTS were inheritable across fork/exec, so any process the host
spawned kept a copy alive after the host closed its own fd. Closing a
listener or connection then delivered no EOF until every such child
had exited.

Create every socketpair close-on-exec (SOCK_CLOEXEC on Linux,
CloseOnExec under ForkLock.RLock elsewhere), and receive connection
fds with MSG_CMSG_CLOEXEC on Linux or an immediate CloseOnExec on
platforms without it.

Fixes tailscale/tailscale#22054

Signed-off-by: James Tucker <james@tailscale.com>
Change-Id: I5ae05cb18a7f5606f2492d9b2761770cf077f1a1
@raggi
raggi force-pushed the raggi/libtailscale-5ae05cb1 branch from 6f6d65d to 1892c0b Compare October 30, 2026 00:00
Comment thread fd_other.go
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause

//go:build !linux

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought a number of other unix OSes could do this too, but this is fine for now

@raggi
raggi merged commit ac7ed43 into main Oct 30, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libtailscale: listener and connection fds are not close-on-exec, so spawned processes inherit them

3 participants