summaryrefslogtreecommitdiff
path: root/src/syscall/exec_linux.go
Commit message (Collapse)AuthorAgeFilesLines
* syscall: gofmt after CL 412114Tobias Klauser2022-07-111-2/+2
| | | | | | | | | | | | Change-Id: Ie51545eaebd22a31379bf8814a2c62b91d1d105b Reviewed-on: https://go-review.googlesource.com/c/go/+/416934 Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
* syscall: clarify Pdeathsig documentation on LinuxVojtěch Boček2022-06-151-1/+5
| | | | | | | | | | | | | | | | This is a rather large footgun, so let's mention that it sends the signal on thread termination and not process termination in the documentation. Updates #27505 Change-Id: I489cf7136e34a1a7896067ae24187b0d523d987e GitHub-Last-Rev: c8722b25d1fb8b0b3696257ec7e955eb421f15a6 GitHub-Pull-Request: golang/go#53365 Reviewed-on: https://go-review.googlesource.com/c/go/+/412114 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
* all: separate doc comment from //go: directivesRuss Cox2022-04-051-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | A future change to gofmt will rewrite // Doc comment. //go:foo to // Doc comment. // //go:foo Apply that change preemptively to all comments (not necessarily just doc comments). For #51082. Change-Id: Iffe0285418d1e79d34526af3520b415a12203ca9 Reviewed-on: https://go-review.googlesource.com/c/go/+/384260 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor)Russ Cox2021-10-281-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | When these packages are released as part of Go 1.18, Go 1.16 will no longer be supported, so we can remove the +build tags in these files. Ran go fix -fix=buildtag std cmd and then reverted the bootstrapDirs as defined in src/cmd/dist/buildtool.go, which need to continue to build with Go 1.4 for now. Also reverted src/vendor and src/cmd/vendor, which will need to be updated in their own repos first. Manual changes in runtime/pprof/mprof_test.go to adjust line numbers. For #41184. Change-Id: Ic0f93f7091295b6abc76ed5cd6e6746e1280861e Reviewed-on: https://go-review.googlesource.com/c/go/+/344955 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
* syscall: add support for SysProcAttr.Pdeathsig on FreeBSDTobias Klauser2021-10-141-1/+1
| | | | | | | | | | | Fixes #46258 Change-Id: I63f70e67274a9df39c757243b99b12e50a9e4784 Reviewed-on: https://go-review.googlesource.com/c/go/+/355570 Trust: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* syscall: use dup3 in forkAndExecInChild1 on all Linux platformsTobias Klauser2021-09-061-15/+3
| | | | | | | | | | | | | | | | The minimum required Linux kernel version for Go 1.18 will be changed to 2.6.32, see #45964. The dup3 syscall was added in 2.6.27, so the fallback to use the dup2 syscall in forkAndExecInChild1 on some platforms can be removed. For #45964 Change-Id: I8e04d7b5b2488990a061a080ed64ea303ad048b8 Reviewed-on: https://go-review.googlesource.com/c/go/+/347350 Trust: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
* os, syscall: remove fallback to pipe syscall on LinuxTobias Klauser2021-09-021-13/+1
| | | | | | | | | | | | | | | | The minimum required Linux kernel version for Go 1.18 will be changed to 2.6.32, see #45964. The pipe2 syscall was added in 2.6.27, so the fallback to use the pipe syscall in os.Pipe and syscall.forkExecPipe on Linux can be removed. For #45964 Change-Id: I033a534f2b39e9bafc9980c9ce980e92f1e3a136 Reviewed-on: https://go-review.googlesource.com/c/go/+/346789 Trust: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* syscall: restore signal mask after setting foreground process groupIan Lance Taylor2021-04-271-2/+4
| | | | | | | | | | | Fixes #37217 Change-Id: I0151bb77fc4c4552d1b19c31d784943b72f84b80 Reviewed-on: https://go-review.googlesource.com/c/go/+/313653 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
* all: add internal/itoa packageJosh Bleecher Snyder2021-03-141-4/+5
| | | | | | | | | | | | | This replaces five implementations scattered across low level packages. (And I plan to use it in a sixth soon.) Three of the five were byte-for-byte identical. Change-Id: I3bbbeeac63723a487986c912b604e10ad1e042f4 Reviewed-on: https://go-review.googlesource.com/c/go/+/301549 Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
* syscall: implement rawVforkSyscall for remaining linux platformsJoel Sing2021-03-031-7/+1
| | | | | | | | | | | | | | | This allows the use of CLONE_VFORK and CLONE_VM for fork/exec, preventing 'fork/exec ...: cannot allocate memory' failures from occuring when attempting to execute commands from a Go process that has a large memory footprint. Additionally, this should reduce the latency of fork/exec on these platforms. Fixes #31936 Change-Id: I4e28cf0763173145cacaa5340680dca9ff449305 Reviewed-on: https://go-review.googlesource.com/c/go/+/295849 Trust: Joel Sing <joel@sing.id.au> Run-TryBot: Joel Sing <joel@sing.id.au> Reviewed-by: Cherry Zhang <cherryyz@google.com>
* all: go fmt std cmd (but revert vendor)Russ Cox2021-02-201-0/+1
| | | | | | | | | | | | | | | | Make all our package sources use Go 1.17 gofmt format (adding //go:build lines). Part of //go:build change (#41184). See https://golang.org/design/draft-gobuild Change-Id: Ia0534360e4957e58cd9a18429c39d0e32a6addb4 Reviewed-on: https://go-review.googlesource.com/c/go/+/294430 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* syscall: support rawVforkSyscall on linux/riscv64Joel Sing2020-08-161-1/+5
| | | | | | | | | | Updates #31936 Change-Id: I7dcb8987d4c306ccc97704b9c1b12313ba8bf242 Reviewed-on: https://go-review.googlesource.com/c/go/+/234960 Reviewed-by: Cherry Zhang <cherryyz@google.com> Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
* syscall: use correct file descriptor in dup2 fallback pathIan Lance Taylor2020-07-251-1/+1
| | | | | | | | | | | This fixes a mistake in CL 220422. This changes code that is only executed on Linux kernel versions earlier than 2.6.27. Change-Id: I01280184f4d7b75e06387c38f1891e8f0a81f793 Reviewed-on: https://go-review.googlesource.com/c/go/+/244630 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
* syscall: document exact meaning of Ctty fieldIan Lance Taylor2020-05-011-7/+18
| | | | | | | | | | | | | | | | The Ctty field is a child descriptor number when Setctty is set, but a parent descriptor when Foreground is set. This is absurd but changing either behavior breaks existing programs. With this change we at least document how it works. For #29458 Change-Id: If9cf0a1a1e6ed0d4a4edae5043016d5b4ee3308b Reviewed-on: https://go-review.googlesource.com/c/go/+/229768 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
* syscall: use dup3 in forkAndExecInChild1 if availableTobias Klauser2020-02-241-6/+16
| | | | | | | | | | | | | | The dup3 syscall is available since Linux 2.6.27. Fall back to dup2 (if available) if dup3 returns ENOSYS. This allows to omit the additional fcntl call to mark the dup'ed fd as close-on-exec. Change-Id: If318b593edd783f2aa988534c6062498e7119ddb Reviewed-on: https://go-review.googlesource.com/c/go/+/220422 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* syscall: use fcntl64 on 32-bit GNU/Linux systemsTobias Klauser2019-12-301-3/+3
| | | | | | | | | | | | | Use fcntl64Syscall in forkAndExecInChild1 to get fcntl64 on 32-bit Linux systems. Updates #36211 Change-Id: Id0e34359256beace970e72102fdace7a987ff2b0 Reviewed-on: https://go-review.googlesource.com/c/go/+/212598 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* syscall: implement rawVforkSyscall for linux/arm64Howard Zhang2019-09-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This allows the use of CLONE_VFORK and CLONE_VM for fork/exec, preventing "fork/exec ...: cannot allocate memory" failures from occuring when attempting to execute commands from a Go process that has a large memory footprint. Additionally, this should reduce the latency of fork/exec on linux/arm64. With CLONE_VM the child process shares the same memory with the parent process. On its own this would lead to conflicting use of the same memory, so CLONE_VFORK is used to suspend the parent process until the child releases the memory when switching to the new program binary via the exec syscall. When the parent process continues to run, one has to consider the changes to memory that the child process did, namely the return address of the syscall function needs to be restored from a register. exec.Command() callers can start in a faster manner, as child process who do exec commands job can be cloned faster via vfork than via fork on arm64. The same problem was addressed on linux/amd64 via issue #5838. Updates #31936 Contributed by Howard Zhang <howard.zhang@arm.com> and Bin Lu <bin.lu@arm.com> Change-Id: Ia99d81d877f564ec60d19f17e596276836576eaf Reviewed-on: https://go-review.googlesource.com/c/go/+/189418 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Cherry Zhang <cherryyz@google.com>
* Revert "syscall: use Ctty before fd shuffle"Damien Neil2019-06-271-16/+16
| | | | | | | | | | | | | | | This reverts commit 103b5b66921b351f8db4fc6e83bf147b1a0d7580. Reason for revert: Breaks valid existing programs. Updates #29458 Change-Id: I7ace4ae404cf2a8b0e15e646663c50115f74b758 Reviewed-on: https://go-review.googlesource.com/c/go/+/183939 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Greg Thelen <gthelen@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* syscall: use Ctty before fd shuffleGreg Thelen2019-05-301-16/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On unix if exec.Command() is given both ExtraFiles and Ctty, and the Ctty file descriptor overlaps the range of FDs intended for the child, then cmd.Start() the ioctl(fd,TIOCSCTTY) call fails with an "inappropriate ioctl for device" error. When child file descriptors overlap the new child's ctty the ctty will be closed in the fd shuffle before the TIOCSCTTY. Thus TIOCSCTTY is used on one of the ExtraFiles rather than the intended Ctty file. Thus the error. exec.Command() callers can workaround this by ensuring the Ctty fd is larger than any ExtraFiles destined for the child. Fix this by doing the ctty ioctl before the fd shuffle. Test for this issue by modifying TestTerminalSignal to use more ExtraFiles. The test fails on linux and freebsd without this change's syscall/*.go changes. Other platforms (e.g. darwin, aix, solaris) have the same fd shuffle logic, so the same fix is applied to them. However, I was only able to test on linux (32 and 64 bit) and freebsd (64 bit). Manual runs of the test in https://golang.org/issue/29458 start passing with this patch: Before: % /tmp/src/go/bin/go run t successfully ran child process with ParentExtraFileFdNum=5, ChildExtraFileFd=6, ParentPtyFd=7 panic: failed to run child process with ParentExtraFileFdNum=10, ChildExtraFileFd=11, ParentPtyFd=11: fork/exec /bin/true: inappropriate ioctl for device After: % /tmp/src/go/bin/go run t successfully ran child process with ParentExtraFileFdNum=5, ChildExtraFileFd=6, ParentPtyFd=7 successfully ran child process with ParentExtraFileFdNum=10, ChildExtraFileFd=11, ParentPtyFd=11 Fixes #29458 Change-Id: I99513de7b6073c7eb855f1eeb4d1f9dc0454ef8b Reviewed-on: https://go-review.googlesource.com/c/go/+/178919 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* syscall: implement rawVforkSyscall for linux/ppc64x and linux/s390xJoel Sing2019-05-151-1/+3
| | | | | | | | | | | | | | | | | This allows the use of CLONE_VFORK and CLONE_VM for fork/exec, preventing "fork/exec ...: cannot allocate memory" failures from occuring when attempting to execute commands from a Go process that has a large memory footprint. Additionally, this should reduce the latency of fork/exec on these platforms. The same problem was addressed on linux/amd64 via issue #5838. Updates #31936 Change-Id: I7ae0fbbeaa29cab944a49a11272a380d497eb2d0 Reviewed-on: https://go-review.googlesource.com/c/go/+/175697 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* syscall: correctly set up uid/gid mappings in user namespacesMichael Stapelberg2019-03-121-19/+79
| | | | | | | | | | | | | | | | | Before this CL, uid/gid mapping was always set up from the parent process, which is a privileged operation. When using unprivileged user namespaces, a process can modify its uid/gid mapping after the unshare(2) call (but setting the uid/gid mapping from another process is NOT possible). Fixes #29789 Change-Id: I8c96a03f5da23fe80bbb83ef051ad89cf185d750 Reviewed-on: https://go-review.googlesource.com/c/go/+/158298 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* syscall: add all ambient capabilities into permitted and inheritable setsAndrei Vagin2019-03-081-3/+48
| | | | | | | | | | | | | | | | | | | | | | According to the prctl man page, each capability from the ambient set must already be present in both the permitted and the inheritable sets of the process. exec_linux_test suggests configuring the capabilities in the parent process. This doesn't look nice, because: * Capabilities are a per-thread attribute, so we need to use LockOSThread. * Need to restore capabilities after creating a process. * Doesn't work with user namespaces, because a process gets capabilities when a namespace is created. Fixes #23152 Change-Id: Iba23e530fc7b9f5182d602fe855f82218f354219 Reviewed-on: https://go-review.googlesource.com/c/go/+/156577 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* syscall: fix hang when using Unshareflags: CLONE_NEWUSER with uid/gid ↵Michael Stapelberg2019-03-061-1/+1
| | | | | | | | | | | | | | | mapping (linux) Note that this particular combination of properties still fails (EPERM), but it no longer hangs. Updates #29789 Change-Id: I29b15b85a25a7acd7ae89ffc5fed074bcdfe0a12 Reviewed-on: https://go-review.googlesource.com/c/go/+/158297 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* syscall: document LockOSThread with GNU/Linux SysProcAttr.PtraceIan Lance Taylor2018-12-271-3/+6
| | | | | | | | Fixes #28315 Change-Id: Ie02c72d02ad2f66c9cdbbba579a304641f327672 Reviewed-on: https://go-review.googlesource.com/c/155138 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* syscall: support syscalls without error return on LinuxTobias Klauser2018-02-131-7/+4
| | | | | | | | | | | | | | Add the rawSyscallNoError wrapper function which is used for Linux syscalls that don't return an error and convert all applicable occurences of RawSyscall to use it instead. Fixes #22924 Change-Id: Iff1eddb54573d459faa01471f10398b3d38528dd Reviewed-on: https://go-review.googlesource.com/84485 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* syscall: move ptrace setup to right before execJess Frazelle2017-08-231-8/+10
| | | | | | | | | | | | | | This will prevent any ptrace calls from getting trace output from the runtime itself setting up after fork. Fixes #21428. Change-Id: I9d835bd5a8f404394eb6237679f2111a72e5bc17 Reviewed-on: https://go-review.googlesource.com/55811 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Avelino <t@avelino.xxx>
* syscall: add AmbientCaps to linux SysProcAttrMichael Stapelberg2017-06-281-0/+22
| | | | | | | | Fixes #19713 Change-Id: Id1ca61b35bca2a4bea23dd64c7fb001a3a14fd88 Reviewed-on: https://go-review.googlesource.com/43512 Reviewed-by: Ian Lance Taylor <iant@golang.org>
* syscall: mark forkAndExecInChild1 noinlineAustin Clements2017-06-201-0/+9
| | | | | | | | | | | | | | | This certainly won't get inlined right now, but in the spirit of making this more robust, we have to disable inlining because inlining would defeat the purpose of separating forkAndExecInChild1 into a separate function. Updates #20732. Change-Id: I736c3f909cc42c5f5783740c2e19ba4827c7c2ec Reviewed-on: https://go-review.googlesource.com/46174 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* syscall: use CLONE_VFORK safelyAustin Clements2017-06-201-25/+45
| | | | | | | | | | | | | | | | | | | | | | | | | Currently, CLONE_VFORK is used without much regard to the stack. This is dangerous, because anything the child does to the stack is visible to the parent. For example, if the compiler were to reuse named stack slots (which it currently doesn't do), it would be easy for the child running in the same stack frame as the parent to corrupt local variables that the parent then depended on. We're not sure of anything specific going wrong in this code right now, but it is at best a ticking time bomb. CLONE_VFORK can only safely be used if we ensure the child does not execute in any of the active stack frames of the parent. This commit implements this by arranging for the parent to return immediately from the frame the child will operate in, and for the child to never return to the frame the parent will operate in. Fixes #20732. Change-Id: Iad5b4ddc2b994c082bd278bfd52ef53bd38c037f Reviewed-on: https://go-review.googlesource.com/46173 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* runtime, syscall: reset signal handlers to default in childIan Lance Taylor2017-06-141-0/+3
| | | | | | | | | | | | | | | | | | | | | | | Block all signals during a fork. In the parent process, after the fork, restore the signal mask. In the child process, reset all currently handled signals to the default handler, and then restore the signal mask. The effect of this is that the child will be operating using the same signal regime as the program it is about to exec, as exec resets all non-ignored signals to the default, and preserves the signal mask. We do this so that in the case of a signal sent to the process group, the child process will not try to run a signal handler while in the precarious state after a fork. Fixes #18600. Change-Id: I9f39aaa3884035908d687ee323c975f349d5faaa Reviewed-on: https://go-review.googlesource.com/45471 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
* syscall: allow processes steal a controlling terminal on LinuxJulio Montes2017-05-311-1/+1
| | | | | | | | | | | | | | The current implementation of forkAndExecInChild for Linux does not allow spawned processes steal the controlling terminal from a different session group. This patch passes 1 as the argument to TIOCSCTTY in order to allow spawned processes steal controlling terminals. Fixes #20454 Change-Id: I171b8981509d648b07f89bddc1e9d45cb70e00e6 Reviewed-on: https://go-review.googlesource.com/44343 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org>
* syscall: fix ordering of Unshare and chroot on LinuxRonald G. Minnich2017-04-251-8/+8
| | | | | | | | | | | | | | | | | | | | | When unshare specifies a new namespace, the syscall package changes / to make namespace changes private. If a chroot is specified, the unshare must be done first. If the chroot is done first then the unshare will not specify the correct /. A new test is included which test combining chroot and CLONE_NEWNS; it fails without the patch and works with it. Fixes #20103 Change-Id: I86022803c784bd418a30383321f3d64103d95c62 Reviewed-on: https://go-review.googlesource.com/41626 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* os/exec: handle Unshareflags with CLONE_NEWNSRonald G. Minnich2017-03-231-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In some newer Linux distros, systemd forces all mount namespaces to be shared, starting at /. This disables the CLONE_NEWNS flag in unshare(2) and clone(2). While this problem is most commonly seen on systems with systemd, it can happen anywhere, due to how Linux namespaces now work. Hence, to create a private mount namespace, it is not sufficient to just set CLONE_NEWS; you have to call mount(2) to change the behavior of namespaces, i.e. mount("none", "/", NULL, MS_REC|MS_PRIVATE, NULL) This is tested and working and we can now correctly start child process with private namespaces on Linux distros that use systemd. The new test works correctly on Ubuntu 16.04.2 LTS. It fails if I comment out the new Mount, and succeeds otherwise. In each case it correctly cleans up after itself. Fixes #19661 Change-Id: I52240b59628e3772b529d9bbef7166606b0c157d Reviewed-on: https://go-review.googlesource.com/38471 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* syscall: use CLONE_VFORK and CLONE_VMRichard Musiol2017-03-221-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This greatly improves the latency of starting a child process when the Go process is using a lot of memory. Even though the kernel uses copy-on-write, preparation for that can take up to several 100ms under certain conditions. All other goroutines are suspended while starting a subprocess so this latency directly affects total throughput. With CLONE_VM the child process shares the same memory with the parent process. On its own this would lead to conflicting use of the same memory, so CLONE_VFORK is used to suspend the parent process until the child releases the memory when switching to to the new program binary via the exec syscall. When the parent process continues to run, one has to consider the changes to memory that the child process did, namely the return address of the syscall function needs to be restored from a register. A simple benchmark has shown a difference in latency of 16ms vs. 0.5ms at 10GB memory usage. However, much higher latencies of several 100ms have been observed in real world scenarios. For more information see comments on #5838. Fixes #5838 Change-Id: I6377d7bd8dcd00c85ca0c52b6683e70ce2174ba6 Reviewed-on: https://go-review.googlesource.com/37439 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* syscall: only call setgroups if we need toWander Lairson Costa2017-02-171-4/+1
| | | | | | | | | | | | | | | | | | | | | If the caller set ups a Credential in os/exec.Command, os/exec.Command.Start will end up calling setgroups(2), even if no supplementary groups were given. Only root can call setgroups(2) on BSD kernels, which causes Start to fail for non-root users when they try to set uid and gid for the new process. We fix by introducing a new field to syscall.Credential named NoSetGroups, and setgroups(2) is only called if it is false. We make this field with inverted logic to preserve backward compatibility. RELNOTES=yes Change-Id: I3cff1f21c117a1430834f640ef21fd4e87e06804 Reviewed-on: https://go-review.googlesource.com/36697 Reviewed-by: Ian Lance Taylor <iant@golang.org>
* syscall: use 32-bit setuid/setgid syscalls on linux/{386,arm}Brad Fitzpatrick2016-11-091-2/+2
| | | | | | | | | | Fixes #17092 Change-Id: Ib14e4db13116ebbe4d72c414fb979d27a06d6174 Reviewed-on: https://go-review.googlesource.com/33011 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* syscall: for ForkExec on Linux, always use 32-bit setgroups system callRuss Cox2016-10-191-1/+1
| | | | | | | | Fixes #17092. Change-Id: If203d802a919e00594ddc1282782fc59a083fd63 Reviewed-on: https://go-review.googlesource.com/31458 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* syscall: call setgroups for no groups on GNU/LinuxAlexander Morozov2016-06-021-2/+8
| | | | | | | | | | | | | | Skip setgroups only for one particular case: GidMappings != nil and GidMappingsEnableSetgroup == false and list of supplementary groups is empty. This patch returns pre-1.5 behavior for simple exec and still allows to use GidMappings with non-empty Credential. Change-Id: Ia91c77e76ec5efab7a7f78134ffb529910108fc1 Reviewed-on: https://go-review.googlesource.com/23524 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* syscall: rename SysProcAttr.Unshare to UnshareflagsAlexander Morozov2016-06-011-17/+17
| | | | | | | | | | | | For symmetry with Cloneflags and it looks slightly weird because there is syscall.Unshare method. Change-Id: I3d710177ca8f27c05b344407f212cbbe3435094b Reviewed-on: https://go-review.googlesource.com/23612 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
* syscall: add Unshare flags to SysProcAttr on LinuxJess Frazelle2016-05-201-0/+9
| | | | | | | | | | | | This patch adds Unshare flags to SysProcAttr for Linux systems. Fixes #1954 Change-Id: Id819c3f92b1474e5a06dd8d55f89d74a43eb770c Reviewed-on: https://go-review.googlesource.com/23233 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* syscall: fix accidental close of exec status pipe in StartProcessRichard Miller2016-03-291-3/+3
| | | | | | | | | | | | | | | | | | | | | In syscall.forkAndExecInChild, blocks of code labelled Pass 1 and Pass 2 permute the file descriptors (if necessary) which are passed to the child process. If Pass 1 begins with fds = {0,2,1}, nextfd = 4 and pipe = 4, then the statement labelled "don't stomp on pipe" is too late -- the pipe (which will be needed to pass exec status back to the parent) will have been closed by the preceding DUP call. Moving the "don't stomp" test earlier ensures that the pipe is protected. Fixes #14979 Change-Id: I890c311527f6aa255be48b3277c1e84e2049ee22 Reviewed-on: https://go-review.googlesource.com/21184 Run-TryBot: David du Colombier <0intro@gmail.com> Reviewed-by: David du Colombier <0intro@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
* syscall: change clone argument order on s390xMichael Munday2016-03-211-1/+6
| | | | | | | | | | The Linux ABI takes arguments in a different order on s390x. Change-Id: Ic9cfcc22a5ea3d8ef77d4dd0b915fc266ff3e5f7 Reviewed-on: https://go-review.googlesource.com/20960 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
* all: single space after period.Brad Fitzpatrick2016-03-021-1/+1
| | | | | | | | | | | | | | | | | | | | The tree's pretty inconsistent about single space vs double space after a period in documentation. Make it consistently a single space, per earlier decisions. This means contributors won't be confused by misleading precedence. This CL doesn't use go/doc to parse. It only addresses // comments. It was generated with: $ perl -i -npe 's,^(\s*// .+[a-z]\.) +([A-Z]),$1 $2,' $(git grep -l -E '^\s*//(.+\.) +([A-Z])') $ go test go/doc -update Change-Id: Iccdb99c37c797ef1f804a94b22ba5ee4b500c4f7 Reviewed-on: https://go-review.googlesource.com/20022 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Dave Day <djd@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* cmd/compile, syscall: use go:norace comment for forkAndExecInChildIan Lance Taylor2015-10-201-0/+1
| | | | | | | | | Use a go:norace comment rather than having the compiler know the special name syscall.forkAndExecInChild. Change-Id: I69bc6aa6fc40feb2148d23f269ff32453696fb28 Reviewed-on: https://go-review.googlesource.com/16097 Reviewed-by: Minux Ma <minux@golang.org>
* syscall: don't call Setgroups if Credential.Groups is emptyAlexander Morozov2015-08-271-6/+5
| | | | | | | | | | | | | Setgroups with zero-length groups is no-op for changing groups and supposed to be used only for determining curent groups length. Also because we deny setgroups by default if use GidMappings we have unnecessary error from that no-op syscall. Change-Id: I8f74fbca9190a3dcbbef1d886c518e01fa05eb62 Reviewed-on: https://go-review.googlesource.com/13938 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* syscall: add GidMappingsEnableSetgroups to Linux SysProcAttrAlexander Morozov2015-06-121-0/+35
| | | | | | | | | | | | | | | | | | Linux 3.19 made a change in the handling of setgroups and the 'gid_map' file to address a security issue. The upshot of the 3.19 changes is that in order to update the 'gid_maps' file, use of the setgroups() system call in this user namespace must first be disabled by writing "deny" to one of the /proc/PID/setgroups files for this namespace. Also added tests for remapping uid_map and gid_map inside new user namespace. Fixes #10626 Change-Id: I4d2539acbab741a37092d277e10f31fc39a8feb7 Reviewed-on: https://go-review.googlesource.com/10670 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* syscall: relocate linux death signal codeAndrew Williams2015-05-121-20/+20
| | | | | | | | | | | | | | | | | Fix bug on Linux SysProcAttr handling: setting both Pdeathsig and Credential caused Pdeathsig to be ignored. This is because the kernel clears the deathsignal field when performing a setuid/setgid system call. Avoid this by moving Pdeathsig handling after Credential handling. Fixes #9686 Change-Id: Id01896ad4e979b8c448e0061f00aa8762ca0ac94 Reviewed-on: https://go-review.googlesource.com/3290 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* syscall: fix little-endian assumptionsShenghou Ma2015-05-031-2/+2
| | | | | | | | Change-Id: Ia38256998e544d620a342dabedd9289d61fb0551 Reviewed-on: https://go-review.googlesource.com/9672 Reviewed-by: Dave Cheney <dave@cheney.net> Run-TryBot: Minux Ma <minux@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* syscall: Add Foreground and Pgid to SysProcAttrMichael MacInnis2015-03-231-5/+26
| | | | | | | | | | | | | | | | On Unix, when placing a child in a new process group, allow that group to become the foreground process group. Also, allow a child process to join a specific process group. When setting the foreground process group, Ctty is used as the file descriptor of the controlling terminal. Ctty has been added to the BSD and Solaris SysProcAttr structures and the handling of Setctty changed to match Linux. Change-Id: I18d169a6c5ab8a6a90708c4ff52eb4aded50bc8c Reviewed-on: https://go-review.googlesource.com/5130 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* syscall: exec_linux.go: support platforms without SYS_DUP2Dave Cheney2015-03-101-3/+3
| | | | | | | | | | | | | | | | | Updates #9974 This change is in preparation for merging the arm64 platform. Arm64 does not support SYS_DUP2 at all, so define a new constant to be the minimum dup(2) version supported. This constant defaults to SYS_DUP2 on all existing platforms. Change-Id: If405878105082c7c880f8541c1491970124c9ce4 Reviewed-on: https://go-review.googlesource.com/7123 Reviewed-by: Minux Ma <minux@golang.org> Run-TryBot: Minux Ma <minux@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Dave Cheney <dave@cheney.net>