Whiteout is not recursive: a deleted directory's contents stay readable and can be republished by commit()
is_deleted is an exact string match on the whiteout set (cow/seccomp.rs:384-386), so a whiteout covers the path it was recorded for and nothing beneath it. After a directory is marked deleted, its children are still resolved against the workdir: they stay readable, they stay listable, and a write-open of one copies the deleted file's bytes into the upper, where commit() republishes them into the workdir.
Reproducer:
fs::create_dir(workdir.path().join("d")).unwrap();
fs::write(workdir.path().join("d/secret.txt"), "SECRET").unwrap();
let mut b = SeccompCowBranch::create(workdir.path(), Some(storage.path()), 0).unwrap();
b.mark_deleted("d");
b.is_deleted("d") // true
b.is_deleted("d/secret.txt") // false
b.list_merged_dir("d") // ["secret.txt"]
b.handle_open("d/secret.txt", 0) // Ok(None) -> resolves to the workdir path
Ok(None) from handle_open means the syscall is not intercepted and the child reads the workdir file directly, so the contents of a directory the child deleted remain fully accessible under it.
This diverges from the overlay semantics the branch models elsewhere: handle_open on a whiteouted path itself is careful to return BranchError::Deleted rather than fall through to the lower file, and its comment explains why ("the lower file still physically exists with its pre-delete bytes"). The same reasoning applies one level down, but the lookup never gets there.
Two consequences worth separating:
- Visibility — a deleted directory's contents are readable and listable. The child deleted them itself, so this is a correctness divergence from
rm -rfsemantics rather than a boundary crossing. - Integrity — this is the one that surprised me. A write-open under the deleted directory copies the file up, and the merge then writes it back into the workdir, so a file the transaction deleted reappears in the committed result. That is a silently wrong commit, not just a stale read.
The narrow fix is to make the whiteout check prefix-aware (a path is deleted if it or any ancestor is in the set), with the usual care that d must not shadow d2. The broader question is whether mark_deleted on a directory should record an opaque marker instead, which is what overlayfs does and what a future recovery sweep would need in order to replay a deletion correctly.
Found while writing COW merge tests for #148; unrelated to that PR's subject, hence a separate report. Reproduced on main at 44b1c65.