From: Alexander Morozov Date: Mon, 31 Aug 2015 15:41:43 +0000 (-0700) Subject: syscall: move check of unprivileged_userns_clone to whoamiCmd X-Git-Tag: go1.6beta1~1219 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ae82315b82672ca95c2b5365d7d18283981a40af;p=gostls13.git syscall: move check of unprivileged_userns_clone to whoamiCmd This is basic validation and should be performed early Fixes #12412 Change-Id: I903f7eeafdc22376704985a53d649698cf9d8ef4 Reviewed-on: https://go-review.googlesource.com/14110 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/src/syscall/exec_linux_test.go b/src/syscall/exec_linux_test.go index 8c8773629d..bbfd6d03df 100644 --- a/src/syscall/exec_linux_test.go +++ b/src/syscall/exec_linux_test.go @@ -24,6 +24,13 @@ func whoamiCmd(t *testing.T, uid, gid int, setgroups bool) *exec.Cmd { } t.Fatalf("Failed to stat /proc/self/ns/user: %v", err) } + // On some systems, there is a sysctl setting. + if os.Getuid() != 0 { + data, errRead := ioutil.ReadFile("/proc/sys/kernel/unprivileged_userns_clone") + if errRead == nil && data[0] == '0' { + t.Skip("kernel prohibits user namespace in unprivileged process") + } + } cmd := exec.Command("whoami") cmd.SysProcAttr = &syscall.SysProcAttr{ Cloneflags: syscall.CLONE_NEWUSER, @@ -42,14 +49,6 @@ func testNEWUSERRemap(t *testing.T, uid, gid int, setgroups bool) { cmd := whoamiCmd(t, uid, gid, setgroups) out, err := cmd.CombinedOutput() if err != nil { - // On some systems, there is a sysctl setting. - if os.IsPermission(err) && os.Getuid() != 0 { - data, errRead := ioutil.ReadFile("/proc/sys/kernel/unprivileged_userns_clone") - if errRead == nil && data[0] == '0' { - t.Skip("kernel prohibits user namespace in unprivileged process") - } - } - t.Fatalf("Cmd failed with err %v, output: %s", err, out) } sout := strings.TrimSpace(string(out))