Skip to content

Commit

Permalink
ssh/tailssh: lock OS thread during incubator
Browse files Browse the repository at this point in the history
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
  • Loading branch information
andrew-d committed Mar 23, 2023
1 parent f13b8bf commit 97ff613
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ssh/tailssh/incubator.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ func parseIncubatorArgs(args []string) (a incubatorArgs) {
// OS, sets its UID and groups to the specified `--uid`, `--gid` and
// `--groups` and then launches the requested `--cmd`.
func beIncubator(args []string) error {
// To defend against issues like https://golang.org/issue/1435,
// defensively lock our current goroutine's thread to the current
// system thread before we start making any UID/GID/group changes.
//
// This shouldn't matter on Linux because syscall.AllThreadsSyscall is
// used to invoke syscalls on all OS threads, but (as of 2023-03-23)
// that function is not implemented on all platforms.
runtime.LockOSThread()
defer runtime.UnlockOSThread()

ia := parseIncubatorArgs(args)
if ia.isSFTP && ia.isShell {
return fmt.Errorf("--sftp and --shell are mutually exclusive")
Expand Down

0 comments on commit 97ff613

Please sign in to comment.