summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2022-02-02 08:52:42 -0500
committerGitHub <noreply@github.com>2022-02-02 08:52:42 -0500
commitc2d0011b723428c622b99cf633439f84c4bf901a (patch)
tree814fa33be901babc6e5f180763ea54471af0fdfe
parent681f76e8b0e6388e0b4c7426deccf0b31d12b75b (diff)
parentc4dfd004ad7efedb48ffa239e65bc9cdcfa31ed2 (diff)
downloadpodman-c2d0011b723428c622b99cf633439f84c4bf901a.tar.gz
podman-c2d0011b723428c622b99cf633439f84c4bf901a.tar.bz2
podman-c2d0011b723428c622b99cf633439f84c4bf901a.zip
Merge pull request #13110 from giuseppe/enforce-dev-shm-with-noexec-nosuid-nodev
libpod: enforce noexec,nosuid,nodev for /dev/shm
-rw-r--r--libpod/container_internal_linux.go6
-rw-r--r--test/e2e/run_test.go10
2 files changed, 16 insertions, 0 deletions
diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go
index 5cc2a78fc..86d8586d0 100644
--- a/libpod/container_internal_linux.go
+++ b/libpod/container_internal_linux.go
@@ -510,6 +510,9 @@ func (c *Container) generateSpec(ctx context.Context) (*spec.Spec, error) {
if c.IsReadOnly() && dstPath != "/dev/shm" {
newMount.Options = append(newMount.Options, "ro", "nosuid", "noexec", "nodev")
}
+ if dstPath == "/dev/shm" && c.state.BindMounts["/dev/shm"] == c.config.ShmDir {
+ newMount.Options = append(newMount.Options, "nosuid", "noexec", "nodev")
+ }
if !MountExists(g.Mounts(), dstPath) {
g.AddMount(newMount)
} else {
@@ -1570,6 +1573,9 @@ func (c *Container) restore(ctx context.Context, options ContainerCheckpointOpti
if c.IsReadOnly() && dstPath != "/dev/shm" {
newMount.Options = append(newMount.Options, "ro", "nosuid", "noexec", "nodev")
}
+ if dstPath == "/dev/shm" && c.state.BindMounts["/dev/shm"] == c.config.ShmDir {
+ newMount.Options = append(newMount.Options, "nosuid", "noexec", "nodev")
+ }
if !MountExists(g.Mounts(), dstPath) {
g.AddMount(newMount)
}
diff --git a/test/e2e/run_test.go b/test/e2e/run_test.go
index 62a454e29..91a2eddad 100644
--- a/test/e2e/run_test.go
+++ b/test/e2e/run_test.go
@@ -1926,4 +1926,14 @@ WORKDIR /madethis`, BB)
Expect(session).Should(Exit(0))
Expect(session.OutputToString()).To(ContainSubstring("i686"))
})
+
+ It("podman run /dev/shm has nosuid,noexec,nodev", func() {
+ session := podmanTest.Podman([]string{"run", ALPINE, "grep", "/dev/shm", "/proc/self/mountinfo"})
+ session.WaitWithDefaultTimeout()
+ Expect(session).Should(Exit(0))
+ output := session.OutputToString()
+ Expect(output).To(ContainSubstring("nosuid"))
+ Expect(output).To(ContainSubstring("noexec"))
+ Expect(output).To(ContainSubstring("nodev"))
+ })
})