Skip to content

Commit d5ee7a5

Browse files
authored
Merge pull request #4400 from cyphar/mkdirall-suidsgid-bits
utils: mkdirall: fix handling of suid/sgid bits
2 parents 7c2e69f + d8844e2 commit d5ee7a5

File tree

9 files changed

+90
-6
lines changed

9 files changed

+90
-6
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/cilium/ebpf v0.12.3
88
github.com/containerd/console v1.0.4
99
github.com/coreos/go-systemd/v22 v22.5.0
10-
github.com/cyphar/filepath-securejoin v0.3.1
10+
github.com/cyphar/filepath-securejoin v0.3.2
1111
github.com/docker/go-units v0.5.0
1212
github.com/godbus/dbus/v5 v5.1.0
1313
github.com/moby/sys/mountinfo v0.7.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8
99
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
1010
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
1111
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
12-
github.com/cyphar/filepath-securejoin v0.3.1 h1:1V7cHiaW+C+39wEfpH6XlLBQo3j/PciWFrgfCLS8XrE=
13-
github.com/cyphar/filepath-securejoin v0.3.1/go.mod h1:F7i41x/9cBF7lzCrVsYs9fuzwRZm4NQsGTBdpp6mETc=
12+
github.com/cyphar/filepath-securejoin v0.3.2 h1:QhZu5AxQ+o1XZH0Ye05YzvJ0kAdK6VQc0z9NNMek7gc=
13+
github.com/cyphar/filepath-securejoin v0.3.2/go.mod h1:F7i41x/9cBF7lzCrVsYs9fuzwRZm4NQsGTBdpp6mETc=
1414
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1515
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1616
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

libcontainer/utils/utils_unix.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,14 @@ func MkdirAllInRootOpen(root, unsafePath string, mode uint32) (_ *os.File, Err e
319319
if mode&^0o7777 != 0 {
320320
return nil, fmt.Errorf("tried to include non-mode bits in MkdirAll mode: 0o%.3o", mode)
321321
}
322+
// Linux (and thus os.MkdirAll) silently ignores the suid and sgid bits if
323+
// passed. While it would make sense to return an error in that case (since
324+
// the user has asked for a mode that won't be applied), for compatibility
325+
// reasons we have to ignore these bits.
326+
if ignoredBits := mode &^ 0o1777; ignoredBits != 0 {
327+
logrus.Warnf("MkdirAll called with no-op mode bits that are ignored by Linux: 0o%.3o", ignoredBits)
328+
mode &= 0o1777
329+
}
322330

323331
rootDir, err := os.OpenFile(root, unix.O_DIRECTORY|unix.O_CLOEXEC, 0)
324332
if err != nil {

tests/integration/mounts.bats

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,41 @@ function test_mount_order() {
199199
[ "$status" -eq 0 ]
200200
}
201201

202+
# CVE-2023-27561 CVE-2019-19921
203+
@test "runc run [/proc is a symlink]" {
204+
# Make /proc in the container a symlink.
205+
rm -rf rootfs/proc
206+
mkdir -p rootfs/bad-proc
207+
ln -sf /bad-proc rootfs/proc
208+
# This should fail.
209+
runc run test_busybox
210+
[ "$status" -ne 0 ]
211+
[[ "$output" == *"must be mounted on ordinary directory"* ]]
212+
}
213+
214+
# https://github.com/opencontainers/runc/issues/4401
215+
@test "runc run [setgid / + mkdirall]" {
216+
mkdir rootfs/setgid
217+
chmod '=7755' rootfs/setgid
218+
219+
update_config '.mounts += [{
220+
type: "tmpfs",
221+
source: "tmpfs",
222+
destination: "/setgid/a/b/c",
223+
options: ["ro", "nodev", "nosuid"]
224+
}]'
225+
update_config '.process.args |= ["true"]'
226+
227+
runc run test_busybox
228+
[ "$status" -eq 0 ]
229+
230+
# Verify that the setgid bit is inherited.
231+
[[ "$(stat -c %a rootfs/setgid)" == 7755 ]]
232+
[[ "$(stat -c %a rootfs/setgid/a)" == 2755 ]]
233+
[[ "$(stat -c %a rootfs/setgid/a/b)" == 2755 ]]
234+
[[ "$(stat -c %a rootfs/setgid/a/b/c)" == 2755 ]]
235+
}
236+
202237
@test "runc run [ro /sys/fs/cgroup mounts]" {
203238
# Without cgroup namespace.
204239
update_config '.linux.namespaces -= [{"type": "cgroup"}]'

vendor/github.com/cyphar/filepath-securejoin/CHANGELOG.md

Lines changed: 20 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/cyphar/filepath-securejoin/VERSION

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/cyphar/filepath-securejoin/mkdir_linux.go

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/cyphar/filepath-securejoin/openat_linux.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ github.com/coreos/go-systemd/v22/dbus
2424
# github.com/cpuguy83/go-md2man/v2 v2.0.2
2525
## explicit; go 1.11
2626
github.com/cpuguy83/go-md2man/v2/md2man
27-
# github.com/cyphar/filepath-securejoin v0.3.1
27+
# github.com/cyphar/filepath-securejoin v0.3.2
2828
## explicit; go 1.20
2929
github.com/cyphar/filepath-securejoin
3030
# github.com/docker/go-units v0.5.0

0 commit comments

Comments
 (0)