Skip to content

Prefer WithReadonlyTempMount for diff reads#6787

Open
vvoland wants to merge 1 commit into
moby:masterfrom
vvoland:mount-readonly
Open

Prefer WithReadonlyTempMount for diff reads#6787
vvoland wants to merge 1 commit into
moby:masterfrom
vvoland:mount-readonly

Conversation

@vvoland

@vvoland vvoland commented May 19, 2026

Copy link
Copy Markdown
Collaborator

WriteUpperdir and winDiffer.Compare nest two WithTempMount calls. If the inner mount shares any backing directory with the outer one (e.g. the inner mount's lower is a subset of the outer's lowers), mounting the same upperdir read-write twice concurrently is undefined behavior on overlayfs.

WithReadonlyTempMount strips upperdir/workdir from overlay mounts, so the kernel never sets up the writable side and the two mounts cannot collide.

Also, mounting them read-only better expresses intent and prevents accidental writes from inside the callback.

WriteUpperdir and winDiffer.Compare nest two WithTempMount calls. If the
inner mount shares any backing directory with the outer one (e.g. the
inner mount's lower is a subset of the outer's lowers), mounting the
same upperdir read-write twice concurrently is undefined behavior on
overlayfs.

WithReadonlyTempMount strips upperdir/workdir from overlay mounts, so
the kernel never sets up the writable side and the two mounts cannot
collide.

Also, mounting them read-only better expresses intent and prevents
accidental writes from inside the callback.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
@vvoland vvoland marked this pull request as ready for review May 19, 2026 17:42
}
return mount.WithTempMount(ctx, lower, func(lowerRoot string) error {
return mount.WithTempMount(ctx, upperView, func(upperViewRoot string) error {
return mount.WithReadonlyTempMount(ctx, lower, func(lowerRoot string) error {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mounting the same upperdir read-write twice concurrently is undefined behavior on overlayfs.

But this mount only sets lowerdir, so there is no upperdir defined at all and already readonly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants