Do not clone unmounted child mounts in cloneMountTree. - #14420
Open
copybara-service[bot] wants to merge 1 commit into
Open
Do not clone unmounted child mounts in cloneMountTree.#14420copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
copybara-service
Bot
requested review from
manninglucas and
nixprime
as code owners
August 25, 2026 23:39
When a mount is unmounted, it may temporarily remain linked in its parent's `children` map pending deferred cleanup (e.g. during dead mount point removal via forgetDeadMountpoint or across user mount namespace boundaries). Previously, `cloneMountTree` traversed all mounts in `parent.children` without checking whether they had been marked unmounted (`c.umounted`). As a result, cloning an active parent mount could recursively clone and resurrect destroyed descendant mounts and dentries. In overlayfs, resurrecting a destroyed dentry bypassed its reference-counting, which could lead to use-after-free and premature release of the underlying MemoryFile while guest VMAs were still referencing it. This change fixes the issue by: - Skipping unmounted child mounts during `cloneMountTree`. - Ensuring `BindAt` rejects recursive bind-mounts when the source mount is not valid in a mount namespace (`!vfs.validInMountNS`). - Updated `overlay.dentry.IncRef` to panic if incrementing a destroyed dentry (`refs < 0`). - Added a test to ensure unmounted children are not cloned. PiperOrigin-RevId: 970865845
copybara-service
Bot
force-pushed
the
test/cl970865845
branch
from
August 27, 2026 18:21
dc059b3 to
74de98c
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.
Do not clone unmounted child mounts in cloneMountTree.
When a mount is unmounted, it may temporarily remain linked in its parent's
childrenmap pending deferred cleanup (e.g. during dead mount point removalvia forgetDeadMountpoint or across user mount namespace boundaries).
Previously,
cloneMountTreetraversed all mounts inparent.childrenwithoutchecking whether they had been marked unmounted (
c.umounted). As a result,cloning an active parent mount could recursively clone and resurrect destroyed
descendant mounts and dentries. In overlayfs, resurrecting a destroyed dentry
bypassed its reference-counting, which could lead to use-after-free and
premature release of the underlying MemoryFile while guest VMAs were still
referencing it.
This change fixes the issue by:
cloneMountTree.BindAtrejects recursive bind-mounts when the source mount is notvalid in a mount namespace (
!vfs.validInMountNS).overlay.dentry.IncRefto panic if incrementing a destroyed dentry(
refs < 0).