Skip to content

Do not clone unmounted child mounts in cloneMountTree. - #14420

Open
copybara-service[bot] wants to merge 1 commit into
masterfrom
test/cl970865845
Open

Do not clone unmounted child mounts in cloneMountTree.#14420
copybara-service[bot] wants to merge 1 commit into
masterfrom
test/cl970865845

Conversation

@copybara-service

Copy link
Copy Markdown

Do not clone unmounted child mounts in cloneMountTree.

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.

@copybara-service copybara-service Bot added the exported Issue was exported automatically label Aug 25, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

exported Issue was exported automatically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant