Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syscall: add mechanism to steal the controlling terminal from a different session group on Linux #20454

Closed
devimc opened this issue May 22, 2017 · 8 comments

Comments

@devimc
Copy link
Contributor

@devimc devimc commented May 22, 2017

What version of Go are you using (go version)?

go version devel +5e79787 Mon May 22 13:44:12 2017 +0000 linux/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/X/gopath/"
GORACE=""
GOROOT="/home/X/gopath/src/github.com/golang/go-linux-amd64-bootstrap"
GOTOOLDIR="/home/X/gopath/src/github.com/golang/go-linux-amd64-bootstrap/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build111441286=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

cmd := exec.Command(config.Path)
cmd.Env = os.Environ()
f, err = os.OpenFile(params.Console, os.O_RDWR, 0660)
if err != nil {
	return -1, err
}
cmd.Stdin = f
cmd.Stdout = f
cmd.Stderr = f
cmd.SysProcAttr = &syscall.SysProcAttr{
	// Create Session
	Setsid: true,
	// Set Controlling terminal to Ctty
	Setctty: true,
	Ctty:    int(f.Fd()),
}
if err := cmd.Start(); err != nil {
	return -1, err
}

What did you expect to see?

A processes running using the assigned terminal

What did you see instead?

fork/exec X: operation not permitted

Solution

Allow spawned processes steal the terminal

@devimc
Copy link
Contributor Author

@devimc devimc commented May 22, 2017

proposed fix devimc@559e40c

@bradfitz bradfitz changed the title fork/exec operation not permitted syscall: add mechanism to steal the controlling terminal from a different session group on Linux May 22, 2017
@bradfitz bradfitz added this to the Go1.10 milestone May 22, 2017
@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented May 22, 2017

To @ianlancetaylor for decision.

@devimc, we can't review code outside of Gerrit, which enforces that a CLA has been submitted. See https://golang.org/doc/contribute.html

But you can wait until Ian decides whether this is something we want.

@devimc
Copy link
Contributor Author

@devimc devimc commented May 22, 2017

@bradfitz great! thanks

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented May 24, 2017

Being able to steal the controlling TTY makes sense.

I think the only thing that really needs to be decided is whether we should always steal the TTY, or whether we should have a new field in syscall.SysProcAttr saying whether to steal the TTY. My inclination is to always steal the TTY if possible--that is, always pass 1 as the argument to TIOCSCTTY.

@devimc
Copy link
Contributor Author

@devimc devimc commented May 26, 2017

I think we can't always pass 1 as the argument to TIOCSCTTY because if the process has not the capability to steal the tty (CAP_SYS_ADMIN) this call will fail, for that reason I think the best way to address this is allowing user/developer to decide when steal or not a tty

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented May 26, 2017

As far as I can see in the Linux kernel sources, the argument to TIOCSCTTY is only checked if the tty is already the controlling terminal of some other session. Do you see something else?

@gopherbot
Copy link

@gopherbot gopherbot commented May 30, 2017

CL https://golang.org/cl/44343 mentions this issue.

@devimc
Copy link
Contributor Author

@devimc devimc commented May 30, 2017

Hi @ianlancetaylor you're right, I sent a PR https://golang.org/cl/44343
thanks

@gopherbot gopherbot closed this in 673fdea May 31, 2017
@golang golang locked and limited conversation to collaborators May 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.