Skip to content

Commit 1c2d4da

Browse files
ALTreebradfitz
authored andcommitted
syscall: skip non-root user namespace test if kernel forbids
The unprivileged_userns_clone sysctl prevents unpriviledged users from creating namespaces, which the AmbientCaps test does. It's set to 0 by default in a few Linux distributions (Debian and Arch, possibly others), so we need to check it before running the test. I've verified that setting echo 1 > /proc/sys/kernel/unprivileged_userns_clone and then running the test *without this patch* makes it pass, which proves that checking unprivileged_userns_clone is indeed sufficient. Fixes #30698 Change-Id: Ib2079b5e714d7f2440ddf979c3e7cfda9a9c5005 Reviewed-on: https://go-review.googlesource.com/c/go/+/166460 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent e2dc41b commit 1c2d4da

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/syscall/exec_linux_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,13 @@ func testAmbientCaps(t *testing.T, userns bool) {
539539
t.Skip("skipping test on Kubernetes-based builders; see Issue 12815")
540540
}
541541

542+
// Skip the test if the sysctl that prevents unprivileged user
543+
// from creating user namespaces is enabled.
544+
data, errRead := ioutil.ReadFile("/proc/sys/kernel/unprivileged_userns_clone")
545+
if errRead == nil && data[0] == '0' {
546+
t.Skip("kernel prohibits user namespace in unprivileged process")
547+
}
548+
542549
// skip on android, due to lack of lookup support
543550
if runtime.GOOS == "android" {
544551
t.Skip("skipping test on android; see Issue 27327")

0 commit comments

Comments
 (0)