Skip to content

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.

@danielnorberg danielnorberg marked this pull request as ready for review January 7, 2026 07:48
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
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.

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