From bb4d269087d11623e15d1aa3c8cb197f29a601d1 Mon Sep 17 00:00:00 2001
From: Daniel J Walsh <dwalsh@redhat.com>
Date: Tue, 28 Jul 2020 09:18:21 -0400
Subject: Specifying --ipc=host --pid=host is broken

For some reason we were overwriting memory when handling both
--pid=host and --ipc=host.  Simplified the code to handle this
correctly, and add test to make sure it does not happen again.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
---
 test/e2e/run_ns_test.go | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

(limited to 'test/e2e')

diff --git a/test/e2e/run_ns_test.go b/test/e2e/run_ns_test.go
index 2b6da2888..5242e04d2 100644
--- a/test/e2e/run_ns_test.go
+++ b/test/e2e/run_ns_test.go
@@ -2,6 +2,7 @@ package integration
 
 import (
 	"os"
+	"os/exec"
 	"strings"
 
 	. "github.com/containers/podman/v2/test/utils"
@@ -102,4 +103,34 @@ var _ = Describe("Podman run ns", func() {
 		session.WaitWithDefaultTimeout()
 		Expect(session).To(ExitWithError())
 	})
+
+	It("podman run --ipc=host --pid=host", func() {
+		cmd := exec.Command("ls", "-l", "/proc/self/ns/pid")
+		res, err := cmd.Output()
+		Expect(err).To(BeNil())
+		fields := strings.Split(string(res), " ")
+		hostPidNS := strings.TrimSuffix(fields[len(fields)-1], "\n")
+
+		cmd = exec.Command("ls", "-l", "/proc/self/ns/ipc")
+		res, err = cmd.Output()
+		Expect(err).To(BeNil())
+		fields = strings.Split(string(res), " ")
+		hostIpcNS := strings.TrimSuffix(fields[len(fields)-1], "\n")
+
+		session := podmanTest.Podman([]string{"run", "--ipc=host", "--pid=host", ALPINE, "ls", "-l", "/proc/self/ns/pid"})
+		session.WaitWithDefaultTimeout()
+		Expect(session.ExitCode()).To(Equal(0))
+		fields = strings.Split(session.OutputToString(), " ")
+		ctrPidNS := strings.TrimSuffix(fields[len(fields)-1], "\n")
+
+		session = podmanTest.Podman([]string{"run", "--ipc=host", "--pid=host", ALPINE, "ls", "-l", "/proc/self/ns/ipc"})
+		session.WaitWithDefaultTimeout()
+		Expect(session.ExitCode()).To(Equal(0))
+		fields = strings.Split(session.OutputToString(), " ")
+		ctrIpcNS := strings.TrimSuffix(fields[len(fields)-1], "\n")
+
+		Expect(hostPidNS).To(Equal(ctrPidNS))
+		Expect(hostIpcNS).To(Equal(ctrIpcNS))
+	})
+
 })
-- 
cgit v1.2.3-54-g00ecf