Skip to content

Commit

Permalink
[release-1.35] CVE-2024-1753 container escape fix
Browse files Browse the repository at this point in the history
Addresses CVE-2024-1753 which allowed a user to write files to the
`/` directory of the host machine if selinux was not enabled.

Signed-off-by: tomsweeneyredhat <tsweeney@redhat.com>
  • Loading branch information
TomSweeneyRedHat committed Mar 18, 2024
1 parent fedbd79 commit 9de9c20
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/volumes/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"errors"

"github.com/containers/buildah/copier"
"github.com/containers/buildah/define"
"github.com/containers/buildah/internal"
internalParse "github.com/containers/buildah/internal/parse"
Expand Down Expand Up @@ -189,7 +190,11 @@ func GetBindMount(ctx *types.SystemContext, args []string, contextDir string, st
// buildkit parity: support absolute path for sources from current build context
if contextDir != "" {
// path should be /contextDir/specified path
newMount.Source = filepath.Join(contextDir, filepath.Clean(string(filepath.Separator)+newMount.Source))
evaluated, err := copier.Eval(contextDir, newMount.Source, copier.EvalOptions{})
if err != nil {
return newMount, "", err
}
newMount.Source = evaluated
} else {
// looks like its coming from `build run --mount=type=bind` allow using absolute path
// error out if no source is set
Expand Down
23 changes: 23 additions & 0 deletions tests/bud.bats
Original file line number Diff line number Diff line change
Expand Up @@ -6628,3 +6628,26 @@ _EOF
expect_output --substring "$podman_files"
expect_output --substring "$podman_processes"
}

@test "build no write file on host - CVE-2024-1753" {
_prefetch alpine
cat > ${TEST_SCRATCH_DIR}/Containerfile << _EOF
FROM alpine as base
RUN ln -s / /rootdir
FROM alpine
# With exploit show host root, not the container's root, and create /BIND_BREAKOUT in / on the host
RUN --mount=type=bind,from=base,source=/rootdir,destination=/exploit,rw ls -l /exploit; touch /exploit/BIND_BREAKOUT; ls -l /exploit
_EOF

run_buildah build $WITH_POLICY_JSON ${TEST_SCRATCH_DIR}
expect_output --substring "/BIND_BREAKOUT"

run ls /BIND_BREAKOUT
rm -f /BIND_BREAKOUT
assert "$status" -eq 2 "exit code from ls"
expect_output --substring "No such file or directory"
}

0 comments on commit 9de9c20

Please sign in to comment.