Skip to content

Commit 97ff613

Browse files
committed
ssh/tailssh: lock OS thread during incubator
This makes it less likely that we trip over bugs like golang/go#1435. Updates #7616 Signed-off-by: Andrew Dunham <[email protected]> Change-Id: Ic28c03c3ad8ed5274a795c766b767fa876029f0e
1 parent f13b8bf commit 97ff613

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

ssh/tailssh/incubator.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,16 @@ func parseIncubatorArgs(args []string) (a incubatorArgs) {
204204
// OS, sets its UID and groups to the specified `--uid`, `--gid` and
205205
// `--groups` and then launches the requested `--cmd`.
206206
func beIncubator(args []string) error {
207+
// To defend against issues like https://golang.org/issue/1435,
208+
// defensively lock our current goroutine's thread to the current
209+
// system thread before we start making any UID/GID/group changes.
210+
//
211+
// This shouldn't matter on Linux because syscall.AllThreadsSyscall is
212+
// used to invoke syscalls on all OS threads, but (as of 2023-03-23)
213+
// that function is not implemented on all platforms.
214+
runtime.LockOSThread()
215+
defer runtime.UnlockOSThread()
216+
207217
ia := parseIncubatorArgs(args)
208218
if ia.isSFTP && ia.isShell {
209219
return fmt.Errorf("--sftp and --shell are mutually exclusive")

0 commit comments

Comments
 (0)