From bd01c413cf772bc0dc0b13d1fa0abececb6e9ee0 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Wed, 3 Dec 2025 16:57:15 +0100 Subject: [PATCH] [v5.6-rhel] libpod: fix workdir MkdirAll() all check MkdirAll can fail with EEXIST when the path is a symlink and the target doesn't exist. As such we should ignore the error. Note there is something fundemantal wrong here with the path access as it is following the symlink to the host, however it is only for a stat() so it is not an security issue here. Fixes: 637c264e2e ("fix issues found by nilness") Signed-off-by: Paul Holzinger (cherry picked from commit 7b1be7f17723c89a636a65bb6f06456bfb8e5156) Signed-off-by: tomsweeneyredhat --- libpod/container_internal_common.go | 5 ++++- test/e2e/run_working_dir_test.go | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libpod/container_internal_common.go b/libpod/container_internal_common.go index 86b45a92b3..0ce0f46792 100644 --- a/libpod/container_internal_common.go +++ b/libpod/container_internal_common.go @@ -932,7 +932,10 @@ func (c *Container) resolveWorkDir() error { // we need to return the full error. return fmt.Errorf("detecting workdir %q on container %s: %w", workdir, c.ID(), err) } - if err := os.MkdirAll(resolvedWorkdir, 0755); err != nil { + if err := os.MkdirAll(resolvedWorkdir, 0o755); err != nil { + if errors.Is(err, fs.ErrExist) { + return nil + } return fmt.Errorf("creating container %s workdir: %w", c.ID(), err) } diff --git a/test/e2e/run_working_dir_test.go b/test/e2e/run_working_dir_test.go index b002af7885..dd6b29c22e 100644 --- a/test/e2e/run_working_dir_test.go +++ b/test/e2e/run_working_dir_test.go @@ -57,4 +57,14 @@ WORKDIR /etc/foobar`, ALPINE) Expect(session).Should(ExitCleanly()) Expect(session.OutputToString()).To(Equal("/home/foobar")) }) + + It("podman run on an image with a symlinked workdir", func() { + dockerfile := fmt.Sprintf(`FROM %s +RUN mkdir /A && ln -s /A /B +WORKDIR /B`, ALPINE) + podmanTest.BuildImage(dockerfile, "test", "false") + + session := podmanTest.PodmanExitCleanly("run", "test", "pwd") + Expect(session.OutputToString()).To(Equal("/A")) + }) })