Skip to content

Commit f9f5b2d

Browse files
lifubangcyphar
authored andcommitted
integration: add some tests for bind mount through dangling symlinks
We intentionally broke this in commit d40b343 ("rootfs: switch to fd-based handling of mountpoint targets") under the assumption that most users do not need this feature. Sadly it turns out they do, and so commit 3f92552 ("rootfs: re-allow dangling symlinks in mount targets") added a hotfix to re-add this functionality. This patch adds some much-needed tests for this behaviour, since it seems we are going to need to keep this for compatibility reasons (at least until runc v2...). Co-developed-by: lifubang <[email protected]> Signed-off-by: Aleksa Sarai <[email protected]>
1 parent e3c7387 commit f9f5b2d

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tests/integration/mounts.bats

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,58 @@ function test_mount_order() {
343343
@test "runc run [mount order, container idmap source] (userns)" {
344344
test_mount_order userns,idmap
345345
}
346+
347+
test_mount_target() {
348+
src="$1"
349+
dst="$2"
350+
real_dst="${3:-$dst}"
351+
352+
echo "== $src -> $dst (=> $real_dst) =="
353+
354+
old_config="$(mktemp ./config.json.bak.XXXXXX)"
355+
cp ./config.json "$old_config"
356+
357+
update_config '.mounts += [{
358+
source: "'"$src"'",
359+
destination: "'"$dst"'",
360+
options: ["bind"]
361+
}]'
362+
363+
# Make sure the target path is at the right spot and is actually a
364+
# bind-mount of the correct inode.
365+
update_config '.process.args = ["stat", "-c", "%n %d:%i", "--", "'"$real_dst"'"]'
366+
runc run test_busybox
367+
[ "$status" -eq 0 ]
368+
[[ "$output" == "$real_dst $(stat -c "%d:%i" -- "$src")" ]]
369+
370+
# Make sure there is a mount entry for the target path.
371+
update_config '.process.args = ["awk", "-F", "PATH='"$real_dst"'", "$2 == PATH", "/proc/self/mounts"]'
372+
runc run test_busybox
373+
[ "$status" -eq 0 ]
374+
[[ "$output" == *"$real_dst"* ]]
375+
376+
# Switch back the old config so this function can be called multiple times.
377+
mv "$old_config" "./config.json"
378+
}
379+
380+
@test "runc run [bind mount through a dangling symlink component]" {
381+
rm -rf rootfs/etc/hosts
382+
ln -s /tmp/foo/bar rootfs/jump
383+
ln -s /jump/baz/hosts rootfs/etc/hosts
384+
385+
rm -rf rootfs/tmp/foo
386+
test_mount_target ./config.json /etc/hosts /tmp/foo/bar/baz/hosts
387+
}
388+
389+
@test "runc run [bind mount through a trailing dangling symlink]" {
390+
rm -rf rootfs/etc/hosts
391+
ln -s /tmp/hosts rootfs/etc/hosts
392+
393+
# File.
394+
rm -rf rootfs/tmp/hosts
395+
test_mount_target ./config.json /etc/hosts /tmp/hosts
396+
397+
# Directory.
398+
rm -rf rootfs/tmp/hosts
399+
test_mount_target . /etc/hosts /tmp/hosts
400+
}

0 commit comments

Comments
 (0)