banger/internal/imagepull
Thales Maciel 0a079277ef
imagepull: reject symlink ancestors during OCI flatten
safeJoin previously did textual cleaning + dest-prefix check only.
That's enough to catch `../escape`, but not the symlink-ancestor
attack: a malicious OCI layer plants `etc -> /tmp/probe`, a later
layer writes/deletes/hardlinks against `etc/anything`, and the kernel
silently dereferences the symlink so the operation lands at
`/tmp/probe/anything` on the host.

The daemon runs flatten as the owner UID, so anywhere that UID can
write becomes a write target; anywhere it can delete (e.g. its own
home) becomes a delete target. Whiteouts and hardlinks make this
worse — a whiteout for `etc/.wh.victim` would `RemoveAll` the host
file `/tmp/probe/victim`, and a TypeLink would expose host files
inside the extracted rootfs.

safeJoin now Lstat-walks every intermediate component of the joined
path against the already-extracted tree, refusing if any ancestor is
a symlink. Walking is race-free against the extraction loop because
we process tar entries serially. Leaf components stay caller-owned
(TypeSymlink writes legitimately want a symlink leaf; TypeReg
RemoveAll's any prior leaf before opening; etc.).

Three new tests pin the protection: write through a symlinked
ancestor, whiteout through a symlinked ancestor, and hardlink target
through a symlinked ancestor — each must fail and leave the host
probe path untouched.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 15:20:46 -03:00
..
assets Generic kernel + init= boot path for OCI-pulled images 2026-04-16 20:12:56 -03:00
ext4.go system: mkfs work disks with lazy_itable_init + lazy_journal_init 2026-04-26 21:32:57 -03:00
firstboot.go Phase B-3: first-boot sshd install 2026-04-16 18:20:33 -03:00
firstboot_test.go Generic kernel + init= boot path for OCI-pulled images 2026-04-16 20:12:56 -03:00
flatten.go imagepull: reject symlink ancestors during OCI flatten 2026-04-28 15:20:46 -03:00
imagepull.go daemon: persist teardown fallbacks and reject unsafe import paths 2026-04-23 16:21:59 -03:00
imagepull_test.go imagepull: reject symlink ancestors during OCI flatten 2026-04-28 15:20:46 -03:00
inject.go Phase B-3: first-boot sshd install 2026-04-16 18:20:33 -03:00
inject_test.go Phase B-3: first-boot sshd install 2026-04-16 18:20:33 -03:00
ownership.go daemon: persist teardown fallbacks and reject unsafe import paths 2026-04-23 16:21:59 -03:00