Skip to content

Commit e2feca7

Browse files
Merge pull request #5794 from dashea/1.26-cve-2024-9675
[release-1.26] Properly validate cache IDs and sources
2 parents 2399bbf + 60b40b9 commit e2feca7

File tree

6 files changed

+66
-6
lines changed

6 files changed

+66
-6
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
# Changelog
44

5+
## v1.26.8 (2024-10-21)
6+
7+
Properly validate cache IDs and sources
8+
59
## v1.26.7 (2024-04-01)
610

711
[release-1.26] conformance tests: don't break on trailing zeroes

changelog.txt

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
- Changelog for v1.26.8 (2024-10-21)
2+
* Properly validate cache IDs and sources
3+
14
- Changelog for v1.26.7 (2024-04-01)
25
* [release-1.26] conformance tests: don't break on trailing zeroes
36
* [release-1.26] CVE-2024-1753 container escape fix

contrib/rpm/buildah.spec

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
Name: buildah
2828
# Bump version in define/types.go too
29-
Version: 1.26.7
29+
Version: 1.26.8
3030
Release: 1.git%{shortcommit}%{?dist}
3131
Summary: A command line tool used to creating OCI Images
3232
License: ASL 2.0
@@ -100,6 +100,9 @@ make DESTDIR=%{buildroot} PREFIX=%{_prefix} install install.completions
100100
%{_datadir}/bash-completion/completions/*
101101

102102
%changelog
103+
* Mon Oct 21 2024 David Shea <[email protected]> 1.26.8-1
104+
- Properly validate cache IDs and sources
105+
103106
* Mon Apr 1 2024 Tom Sweeney <[email protected]> 1.26.7-1
104107
- [release-1.26] conformance tests: don't break on trailing zeroes
105108
- [release-1.26] CVE-2024-1753 container escape fix

define/types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const (
2929
Package = "buildah"
3030
// Version for the Package. Bump version in contrib/rpm/buildah.spec
3131
// too.
32-
Version = "1.26.7"
32+
Version = "1.26.8"
3333

3434
// DefaultRuntime if containers.conf fails.
3535
DefaultRuntime = "runc"

internal/parse/parse.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/containers/storage"
1717
"github.com/containers/storage/pkg/idtools"
1818
"github.com/containers/storage/pkg/lockfile"
19+
digest "github.com/opencontainers/go-digest"
1920
specs "github.com/opencontainers/runtime-spec/specs-go"
2021
"github.com/pkg/errors"
2122
)
@@ -305,7 +306,11 @@ func GetCacheMount(args []string, store storage.Store, imageMountLabel string, a
305306
return newMount, lockedTargets, fmt.Errorf("no stage found with name %s", fromStage)
306307
}
307308
// path should be /contextDir/specified path
308-
newMount.Source = filepath.Join(mountPoint, filepath.Clean(string(filepath.Separator)+newMount.Source))
309+
evaluated, err := copier.Eval(mountPoint, string(filepath.Separator)+newMount.Source, copier.EvalOptions{})
310+
if err != nil {
311+
return newMount, nil, err
312+
}
313+
newMount.Source = evaluated
309314
} else {
310315
// we need to create cache on host if no image is being used
311316

@@ -322,9 +327,13 @@ func GetCacheMount(args []string, store storage.Store, imageMountLabel string, a
322327
}
323328

324329
if id != "" {
325-
newMount.Source = filepath.Join(cacheParent, filepath.Clean(id))
330+
// Don't let the user control where we place the directory.
331+
dirID := digest.FromString(id).Encoded()[:16]
332+
newMount.Source = filepath.Join(cacheParent, dirID)
326333
} else {
327-
newMount.Source = filepath.Join(cacheParent, filepath.Clean(newMount.Destination))
334+
// Don't let the user control where we place the directory.
335+
dirID := digest.FromString(newMount.Destination).Encoded()[:16]
336+
newMount.Source = filepath.Join(cacheParent, dirID)
328337
}
329338
idPair := idtools.IDPair{
330339
UID: uid,

tests/bud.bats

+42-1
Original file line numberDiff line numberDiff line change
@@ -3113,7 +3113,7 @@ EOM
31133113
skip_if_no_runtime
31143114

31153115
${OCI} --version
3116-
_prefetch alpine
3116+
_prefetch alpine busybox
31173117
_prefetch debian
31183118

31193119
run_buildah build --build-arg base=alpine --build-arg toolchainname=busybox --build-arg destinationpath=/tmp --pull=false $WITH_POLICY_JSON -f $BUDFILES/from-with-arg/Containerfile .
@@ -4621,3 +4621,44 @@ _EOF
46214621
assert "$status" -eq 2 "exit code from ls"
46224622
expect_output --substring "No such file or directory"
46234623
}
4624+
4625+
@test "build-check-cve-2024-9675" {
4626+
_prefetch alpine
4627+
4628+
# SELinux can successfully block this exploit.
4629+
if ! which selinuxenabled > /dev/null 2> /dev/null ; then
4630+
searg=""
4631+
elif selinuxenabled ; then
4632+
searg="--security-opt=label=disable"
4633+
fi
4634+
4635+
touch ${TEST_SCRATCH_DIR}/file.txt
4636+
4637+
cat > ${TEST_SCRATCH_DIR}/Containerfile <<EOF
4638+
FROM alpine
4639+
RUN --mount=type=cache,id=../../../../../../../../../../../$TEST_SCRATCH_DIR,target=/var/tmp \
4640+
ls -l /var/tmp && cat /var/tmp/file.txt
4641+
EOF
4642+
4643+
run_buildah 1 build --no-cache $searg ${TEST_SCRATCH_DIR}
4644+
expect_output --substring "cat: can't open '/var/tmp/file.txt': No such file or directory"
4645+
4646+
cat > ${TEST_SCRATCH_DIR}/Containerfile <<EOF
4647+
FROM alpine
4648+
RUN --mount=type=cache,source=../../../../../../../../../../../$TEST_SCRATCH_DIR,target=/var/tmp \
4649+
ls -l /var/tmp && cat /var/tmp/file.txt
4650+
EOF
4651+
4652+
run_buildah 1 build --no-cache $searg ${TEST_SCRATCH_DIR}
4653+
expect_output --substring "cat: can't open '/var/tmp/file.txt': No such file or directory"
4654+
4655+
mkdir ${TEST_SCRATCH_DIR}/cve20249675
4656+
cat > ${TEST_SCRATCH_DIR}/cve20249675/Containerfile <<EOF
4657+
FROM alpine
4658+
RUN --mount=type=cache,from=testbuild,source=../,target=/var/tmp \
4659+
ls -l /var/tmp && cat /var/tmp/file.txt
4660+
EOF
4661+
4662+
run_buildah 1 build --no-cache $searg --build-context testbuild=${TEST_SCRATCH_DIR}/cve20249675/ ${TEST_SCRATCH_DIR}/cve20249675/
4663+
expect_output --substring "cat: can't open '/var/tmp/file.txt': No such file or directory"
4664+
}

0 commit comments

Comments
 (0)