Skip to content

Comments

vfs: validate source/target type match in BindAt#12447

Open
danielnorberg wants to merge 1 commit intogoogle:masterfrom
danielnorberg:fix-bind-mount-type-validation
Open

vfs: validate source/target type match in BindAt#12447
danielnorberg wants to merge 1 commit intogoogle:masterfrom
danielnorberg:fix-bind-mount-type-validation

Conversation

@danielnorberg
Copy link

@danielnorberg danielnorberg commented Jan 6, 2026

Fix a bug where gVisor allows bind mounting a directory at a regular file mount point (and vice versa). Linux's mount fails with ENOTDIR in this case, but gVisor was not performing this validation.

Add IsDir() method to DentryImpl interface to check if a dentry represents a directory. BindAt now validates that source and target have matching types (both directories or both non-directories) after resolving the paths with GetDentryAt.

Fixes #12444

@google-cla
Copy link

google-cla bot commented Jan 6, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Collaborator

@ayushr2 ayushr2 left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

Comment on lines 141 to 143

// IsDir returns true if the file represented by this dentry is a directory.
IsDir() bool
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't need to extend DentryImpl. The information about whether an Dentry is a Dir or not is available via vfsObj.StatAt. You can find an example here:

stat, err := vfs.StatAt(ctx, creds, &PathOperation{
Root: vd,
Start: vd,
}, &StatOptions{
Mask: linux.STATX_MODE,
})
if err != nil {
return nil, err
}
if stat.Mode&linux.S_IFDIR == 0 {
return nil, linuxerr.ENOTDIR
}

In vfs.BindAt, we already have the VDs from GetDentryAt, so should be easy to call vfs.StatAt() with that directly, as shown above.

@danielnorberg danielnorberg force-pushed the fix-bind-mount-type-validation branch 2 times, most recently from 1b989ba to 7a10415 Compare February 22, 2026 20:55
Fix a bug where gVisor allows bind mounting a directory at a regular
file mount point (and vice versa). Linux's mount fails with ENOTDIR
in this case, but gVisor was not performing this validation.

Add IsDir() method to DentryImpl interface to check if a dentry
represents a directory. BindAt now validates that source and target
have matching types (both directories or both non-directories) after
resolving the paths with GetDentryAt.
Fixes google#12444
@danielnorberg danielnorberg force-pushed the fix-bind-mount-type-validation branch from 7a10415 to ad1babc Compare February 22, 2026 21:05
@danielnorberg
Copy link
Author

@ayushr2 ptal again 🙏

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gVisor allows bind mounting directories at a regular file mount point

2 participants