[pkg-golang-devel] [PATCH 2/4] Fix build on new kernel

Michael Hudson-Doyle michael.hudson at canonical.com
Thu Nov 26 00:48:45 UTC 2015


Kernels since 3.mumble fail the syscall tests in a chroot. skip them instead
(patch backported from Go tip).
---
 debian/patches/series                              |  1 +
 .../patches/skip-userns-tests-when-chrooted.patch  | 37 ++++++++++++++++++++++
 2 files changed, 38 insertions(+)
 create mode 100644 debian/patches/skip-userns-tests-when-chrooted.patch

diff --git a/debian/patches/series b/debian/patches/series
index e7c92b7..e189b35 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1 +1,2 @@
 support-new-relocations.patch
+skip-userns-tests-when-chrooted.patch
diff --git a/debian/patches/skip-userns-tests-when-chrooted.patch b/debian/patches/skip-userns-tests-when-chrooted.patch
new file mode 100644
index 0000000..15bd724
--- /dev/null
+++ b/debian/patches/skip-userns-tests-when-chrooted.patch
@@ -0,0 +1,37 @@
+Description: skip tests that create a user namespace when chrooted
+Origin: https://go.googlesource.com/go/+/21efa7b2bc872958bcb252f5ab4dc52b2b0abeae
+Applied-Upstream: commit:21efa7b2bc872958bcb252f5ab4dc52b2b0abeae
+
+--- a/src/syscall/exec_linux_test.go
++++ b/src/syscall/exec_linux_test.go
+@@ -17,6 +17,17 @@
+ 	"testing"
+ )
+ 
++// Check if we are in a chroot by checking if the inode of / is
++// different from 2 (there is no better test available to non-root on
++// linux).
++func isChrooted(t *testing.T) bool {
++	root, err := os.Stat("/")
++	if err != nil {
++		t.Fatalf("cannot stat /: %v", err)
++	}
++	return root.Sys().(*syscall.Stat_t).Ino != 2
++}
++
+ func whoamiCmd(t *testing.T, uid, gid int, setgroups bool) *exec.Cmd {
+ 	if _, err := os.Stat("/proc/self/ns/user"); err != nil {
+ 		if os.IsNotExist(err) {
+@@ -24,6 +35,12 @@
+ 		}
+ 		t.Fatalf("Failed to stat /proc/self/ns/user: %v", err)
+ 	}
++	if isChrooted(t) {
++		// create_user_ns in the kernel (see
++		// https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/kernel/user_namespace.c)
++		// forbids the creation of user namespaces when chrooted.
++		t.Skip("cannot create user namespaces when chrooted")
++	}
+ 	cmd := exec.Command("whoami")
+ 	cmd.SysProcAttr = &syscall.SysProcAttr{
+ 		Cloneflags: syscall.CLONE_NEWUSER,
-- 
2.5.0




More information about the pkg-golang-devel mailing list