[release-1.32] CVE-2024-1753 container escape fix
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>
This commit is contained in:
parent
7904c37a10
commit
ae50fd85ef
|
|
@ -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"
|
||||
|
|
@ -188,7 +189,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
|
||||
|
|
|
|||
|
|
@ -6368,3 +6368,26 @@ _EOF
|
|||
expect_output --substring "localhost/foo/bar"
|
||||
expect_output --substring "localhost/bar"
|
||||
}
|
||||
|
||||
@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"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue