Skip to content

gofer, overlay: Fail directory opens of bind-mounted files and magic links - #17520

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

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

Conversation

@copybara-service

Copy link
Copy Markdown

gofer, overlay: Fail directory opens of bind-mounted files and magic links

Linux fails open(2) with ENOTDIR when the path ends at a file and has O_DIRECTORY or a trailing slash. Gofer and overlay skipped that check when the walk ended at its starting dentry, which happens at the root of a file bind mount and after a magic link like /proc/self/fd/N, so those opens succeeded. OpenAt now checks MustBeDir there too, as tmpfs, kernfs and erofs already do.

I don't know of anything that hits this in practice, but container runtimes bind mount files like /etc/hostname into every container.

Tested: the new mount and open tests fail on runsc without the fix and pass with it on native, ptrace, systrap, systrap_directfs and systrap_overlay, and make lint passes.
Auto-fixed-by: [🤖] @EtiennePerot
FUTURE_COPYBARA_INTEGRATE_REVIEW=#17249 from edaniels:gofer-overlay-mount-root-mustbedir 61027b3

@copybara-service copybara-service Bot added the exported Issue was exported automatically label Nov 12, 2026
@copybara-service
copybara-service Bot force-pushed the test/cl1019703700 branch 6 times, most recently from 65203e3 to 96f7222 Compare November 15, 2026 13:45
…links

Linux fails open(2) with ENOTDIR when the path ends at a file and has O_DIRECTORY or a trailing slash. Gofer and overlay skipped that check when the walk ended at its starting dentry, which happens at the root of a file bind mount and after a magic link like /proc/self/fd/N, so those opens succeeded. OpenAt now checks MustBeDir there too, as tmpfs, kernfs and erofs already do.

I don't know of anything that hits this in practice, but container runtimes bind mount files like /etc/hostname into every container.

Tested: the new mount and open tests fail on runsc without the fix and pass with it on native, ptrace, systrap, systrap_directfs and systrap_overlay, and make lint passes.
Auto-fixed-by: [🤖] @EtiennePerot
FUTURE_COPYBARA_INTEGRATE_REVIEW=#17249 from edaniels:gofer-overlay-mount-root-mustbedir 61027b3
PiperOrigin-RevId: 1019703700
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