Repository navigation
fix invalid overlay mounts - #11545
Merged
Merged
Conversation
sipsma
marked this pull request as draft
December 9, 2025 09:46
sipsma
force-pushed
the
fix-invalid-overlay-fresh
branch
3 times, most recently
from
December 9, 2025 20:49
c3aa5dd to
86ab327
Compare
Old code we picked up from buildkit had a bug where if a temporary mount was created and then a subpath was the target of the mount used, the root tempdir would never get removed. If you run a bunch of tests in an engine and then exec is and ls tmp you will see hundreds/thousands of empty dirs. This fixes the removal logic to always remove the actual root of the temp dir. Signed-off-by: Erik Sipsma <[email protected]>
This code had a release of a ref, which was then returned and used and then released again. Surprisingly this hasn't *obviously* caused issues yet but is incorrect. Fixes the ref to only be released once after its actually done being used. Signed-off-by: Erik Sipsma <[email protected]>
sipsma
force-pushed
the
fix-invalid-overlay-fresh
branch
from
December 10, 2025 01:41
86ab327 to
24e43ae
Compare
sipsma
marked this pull request as ready for review
December 10, 2025 01:41
vito
approved these changes
Dec 10, 2025
We need to avoid the following type of race condition, which can result in invalid overlapping overlay mounts: 1. Engine creates random (unrelated to this exec) overlay mount like upperdir=B,lowerdir=A 2. We hit this code and start runc, which gets to the point where it has unshared its mount namespace but not yet pivot_root'd. In this state, since mount namespaces are forks of their parent, the overlay mount from (1) is visible in the runc processes mount namespace. 3. Engine unmounts the overlay from (1), but that does NOT unmount it from the runc process's mount namespace 4. Engine creates a new overlay mount like upperdir=C,lowerdir=B:C (i.e. upperdir from (1) is now lowerdir). This mount is invalid and technically hitting "undefined behavior" since B is still an upperdir in mounts that exist on the system. We avoid this by starting the runc process in a clean mount namespace that was created during engine init before any mounts existed, guaranteeing none are leaked into it. We setns to that clean mount namespace and then unshare again to guarantee the namespace for the runc process is fully isolated. OpenTree+MoveMount are then used to bind the mounts actually needed by the container into that isolated namespace so that runc can see them. Signed-off-by: Erik Sipsma <[email protected]>
sipsma
force-pushed
the
fix-invalid-overlay-fresh
branch
from
December 10, 2025 17:11
49ef185 to
f5741cc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Been working on fixing #8265, which has been an issue since forever but seems to have become much easier to trigger recently (I'd highly suspect due to the boltdb fix making race conditions requiring tight time windows much easier to hit now).
Through eBPF tracing I've eventually figured out that at minimum the primary cause (hopefully the only one, but not confirmed) is a situation like:
AFAICT this is not a unique problem to dagger. There's a long and storied history of github issues about these invalid overlays and it seems to have become mostly ignored in the container ecosystem because everyone just forces
index=offnow-a-days so the errors "go away" and it just becomes a kernel warning message.The idea of the fix is to always spawn runc processes from a "clean" mount ns that was made during engine init and has no leaked unrelated mounts. Some
open_tree/move_mountmagic allows the mounts to selectively move into that namespace.Some other commits are for random problems I found along the way, e.g.
docker exec dagger-engine-v0.19.8 ls /tmpafter running some tests to see 😄TODOs (some will be spin-off PRs)
While I don't hit the invalid mount in the scenario I was hitting it before, it is still happening. I suspect it's just due to a flaw in my fix, but tbd.TestModule)bpftraceis not a wolfi package so there's quite a bit of shenanigans required to build it (especially on arm64 for obscure reasons)Fixes #8265