Skip to content

Commit f31b7b9

Browse files
mengzhuotklauser
authored andcommitted
syscall: skip test if unprivileged_userns_clone sysctl is missing
The original test (CL 166460) didn't check the existence of /proc/sys/kernel/unprivileged_userns_clone and continue the test if the file doesn't exist. Fixes #32459 Change-Id: Iab4938252fcaded32b61e17edf68f966c2565582 Reviewed-on: https://go-review.googlesource.com/c/go/+/180877 Run-TryBot: Tobias Klauser <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Tobias Klauser <[email protected]>
1 parent 064ce85 commit f31b7b9

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/syscall/exec_linux_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ func skipInContainer(t *testing.T) {
4242
}
4343
}
4444

45+
func skipUnprivilegedUserClone(t *testing.T) {
46+
// Skip the test if the sysctl that prevents unprivileged user
47+
// from creating user namespaces is enabled.
48+
data, errRead := ioutil.ReadFile("/proc/sys/kernel/unprivileged_userns_clone")
49+
if errRead != nil || len(data) < 1 && data[0] == '0' {
50+
t.Skip("kernel prohibits user namespace in unprivileged process")
51+
}
52+
}
53+
4554
// Check if we are in a chroot by checking if the inode of / is
4655
// different from 2 (there is no better test available to non-root on
4756
// linux).
@@ -72,10 +81,7 @@ func checkUserNS(t *testing.T) {
7281
}
7382
// On some systems, there is a sysctl setting.
7483
if os.Getuid() != 0 {
75-
data, errRead := ioutil.ReadFile("/proc/sys/kernel/unprivileged_userns_clone")
76-
if errRead == nil && data[0] == '0' {
77-
t.Skip("kernel prohibits user namespace in unprivileged process")
78-
}
84+
skipUnprivilegedUserClone(t)
7985
}
8086
// On Centos 7 make sure they set the kernel parameter user_namespace=1
8187
// See issue 16283 and 20796.
@@ -582,12 +588,7 @@ func testAmbientCaps(t *testing.T, userns bool) {
582588
t.Skip("skipping test on Kubernetes-based builders; see Issue 12815")
583589
}
584590

585-
// Skip the test if the sysctl that prevents unprivileged user
586-
// from creating user namespaces is enabled.
587-
data, errRead := ioutil.ReadFile("/proc/sys/kernel/unprivileged_userns_clone")
588-
if errRead == nil && data[0] == '0' {
589-
t.Skip("kernel prohibits user namespace in unprivileged process")
590-
}
591+
skipUnprivilegedUserClone(t)
591592

592593
// skip on android, due to lack of lookup support
593594
if runtime.GOOS == "android" {

0 commit comments

Comments
 (0)