aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/osutil
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2021-10-18 16:50:28 +0000
committerAleksandr Nogikh <wp32pw@gmail.com>2021-10-20 16:18:51 +0200
commit781d9e3a15e989583296656d961b2330135129a5 (patch)
tree0226d5e369cf72fe1a30979b4174b7638efcc22e /pkg/osutil
parent9b928657d71ab257a23fd72877929c32b8f7a3f2 (diff)
tools/syz-testbed: do not send SIGKILL to syz-managers
Doing so can result in syz-manager leaking GCE instances. Set PDEATHSIG to SIGTERM instead, so that syz-manager has a change to exit gracefully.
Diffstat (limited to 'pkg/osutil')
-rw-r--r--pkg/osutil/osutil.go16
-rw-r--r--pkg/osutil/osutil_akaros.go2
-rw-r--r--pkg/osutil/osutil_bsd.go2
-rw-r--r--pkg/osutil/osutil_darwin.go2
-rw-r--r--pkg/osutil/osutil_fuchsia.go2
-rw-r--r--pkg/osutil/osutil_linux.go8
-rw-r--r--pkg/osutil/osutil_windows.go2
7 files changed, 24 insertions, 10 deletions
diff --git a/pkg/osutil/osutil.go b/pkg/osutil/osutil.go
index 82c356978..ae8ebc2fb 100644
--- a/pkg/osutil/osutil.go
+++ b/pkg/osutil/osutil.go
@@ -38,7 +38,7 @@ func Run(timeout time.Duration, cmd *exec.Cmd) ([]byte, error) {
if cmd.Stderr == nil {
cmd.Stderr = output
}
- setPdeathsig(cmd)
+ setPdeathsig(cmd, true)
if err := cmd.Start(); err != nil {
return nil, fmt.Errorf("failed to start %v %+v: %v", cmd.Path, cmd.Args, err)
}
@@ -78,10 +78,20 @@ func Run(timeout time.Duration, cmd *exec.Cmd) ([]byte, error) {
return output.Bytes(), nil
}
-// Command is similar to os/exec.Command, but also sets PDEATHSIG on linux.
+// Command is similar to os/exec.Command, but also sets PDEATHSIG to SIGKILL on linux,
+// i.e. the child will be killed immediately.
func Command(bin string, args ...string) *exec.Cmd {
cmd := exec.Command(bin, args...)
- setPdeathsig(cmd)
+ setPdeathsig(cmd, true)
+ return cmd
+}
+
+// Command is similar to os/exec.Command, but also sets PDEATHSIG to SIGTERM on linux,
+// i.e. the child has a chance to exit gracefully. This may be important when running
+// e.g. syz-manager. If it is killed immediately, it can leak GCE instances.
+func GraciousCommand(bin string, args ...string) *exec.Cmd {
+ cmd := exec.Command(bin, args...)
+ setPdeathsig(cmd, false)
return cmd
}
diff --git a/pkg/osutil/osutil_akaros.go b/pkg/osutil/osutil_akaros.go
index 210a208e8..1ef9f4538 100644
--- a/pkg/osutil/osutil_akaros.go
+++ b/pkg/osutil/osutil_akaros.go
@@ -33,7 +33,7 @@ func SandboxChown(file string) error {
return nil
}
-func setPdeathsig(cmd *exec.Cmd) {
+func setPdeathsig(cmd *exec.Cmd, hardKill bool) {
}
func killPgroup(cmd *exec.Cmd) {
diff --git a/pkg/osutil/osutil_bsd.go b/pkg/osutil/osutil_bsd.go
index 221f86054..d139b9a76 100644
--- a/pkg/osutil/osutil_bsd.go
+++ b/pkg/osutil/osutil_bsd.go
@@ -30,7 +30,7 @@ func SandboxChown(file string) error {
return nil
}
-func setPdeathsig(cmd *exec.Cmd) {
+func setPdeathsig(cmd *exec.Cmd, hardKill bool) {
}
func killPgroup(cmd *exec.Cmd) {
diff --git a/pkg/osutil/osutil_darwin.go b/pkg/osutil/osutil_darwin.go
index 016e692f7..22c667ed7 100644
--- a/pkg/osutil/osutil_darwin.go
+++ b/pkg/osutil/osutil_darwin.go
@@ -27,7 +27,7 @@ func SandboxChown(file string) error {
return nil
}
-func setPdeathsig(cmd *exec.Cmd) {
+func setPdeathsig(cmd *exec.Cmd, hardKill bool) {
}
func killPgroup(cmd *exec.Cmd) {
diff --git a/pkg/osutil/osutil_fuchsia.go b/pkg/osutil/osutil_fuchsia.go
index da596d47a..f1dad3aff 100644
--- a/pkg/osutil/osutil_fuchsia.go
+++ b/pkg/osutil/osutil_fuchsia.go
@@ -47,7 +47,7 @@ func SandboxChown(file string) error {
return nil
}
-func setPdeathsig(cmd *exec.Cmd) {
+func setPdeathsig(cmd *exec.Cmd, hardKill bool) {
}
func killPgroup(cmd *exec.Cmd) {
diff --git a/pkg/osutil/osutil_linux.go b/pkg/osutil/osutil_linux.go
index 768620d21..fb7a0670c 100644
--- a/pkg/osutil/osutil_linux.go
+++ b/pkg/osutil/osutil_linux.go
@@ -124,11 +124,15 @@ func usernameToID(what string) (uint32, error) {
return uint32(id), nil
}
-func setPdeathsig(cmd *exec.Cmd) {
+func setPdeathsig(cmd *exec.Cmd, hardKill bool) {
if cmd.SysProcAttr == nil {
cmd.SysProcAttr = new(syscall.SysProcAttr)
}
- cmd.SysProcAttr.Pdeathsig = syscall.SIGKILL
+ if hardKill {
+ cmd.SysProcAttr.Pdeathsig = syscall.SIGKILL
+ } else {
+ cmd.SysProcAttr.Pdeathsig = syscall.SIGTERM
+ }
// We will kill the whole process group.
cmd.SysProcAttr.Setpgid = true
}
diff --git a/pkg/osutil/osutil_windows.go b/pkg/osutil/osutil_windows.go
index 21649a8c3..8a0e8b77a 100644
--- a/pkg/osutil/osutil_windows.go
+++ b/pkg/osutil/osutil_windows.go
@@ -44,7 +44,7 @@ func SandboxChown(file string) error {
return nil
}
-func setPdeathsig(cmd *exec.Cmd) {
+func setPdeathsig(cmd *exec.Cmd, hardKill bool) {
}
func killPgroup(cmd *exec.Cmd) {