Skip to content

mountutil: apply default propagation to shorthand bind mounts - #5366

Merged
AkihiroSuda merged 1 commit into
containerd:mainfrom
qwe962:fix/bind-mount-default-propagation
Nov 26, 2026
Merged

AkihiroSuda merged 1 commit into
containerd:mainfrom
qwe962:fix/bind-mount-default-propagation

Conversation

@qwe962

@qwe962 qwe962 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Fixes #5349

Summary

nerdctl run -v SRC:DST skips volume option parsing when the mode is omitted. On Linux, this can cause the bind mount to inherit shared propagation when another mount in the same container requests rshared.

Use the existing option parser for shorthand bind mounts so they get the default rprivate propagation. Cover both absolute and relative source paths in TestProcessFlagV.

Testing

  • Both shorthand regression cases failed on the baseline and passed with this change.
  • Unit tests for pkg/mountutil and pkg/cmd/container passed on Linux.
  • All five end-to-end checks passed on openEuler 24.03 LTS SP3 and Ubuntu 22.04 LTS, both with containerd v2.2.1 and runc 1.1.8. In /proc/self/mountinfo, the shorthand mount was shared on the baseline and private with this patch. The mount explicitly configured with rshared remained shared in all five cases.

Comment thread pkg/mountutil/mountutil.go Outdated

options, res.Opts, err = getVolumeOptions(src, res.Type, rawOpts, ociRuntime)
// Bind mounts need default options even when the mode is omitted.
if res.Type == Bind || len(split) == 3 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can remove the if condition. The getVolumeOptions has a default which gets applied.

@@ -128,13 +128,13 @@ func ProcessFlagV(s string, volStore volumestore.VolumeStore, createDir bool, oc
AnonymousVolume: volSpec.AnonymousVolume,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we add the failed case as integ test.


func TestRunShorthandBindMountPropagation(t *testing.T) {
testCase := nerdtest.Setup()
testCase.Require = require.All(nerdtest.Rootful, require.Not(nerdtest.Docker))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The test creates a shared bind mount on the host, so I’ll keep the rootful requirement. Linux Docker Engine supports the propagation modes this test checks. I’ll remove the Docker exclusion and verify the test against the Docker target.

Comment thread go.mod Outdated
github.com/moby/moby/api v1.57.0 // indirect
//gomodjail:unconfined
github.com/moby/sys/mountinfo v0.7.3 // indirect
github.com/moby/sys/mountinfo v0.7.3

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Direct dependencies have to be moved to the first require() block

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I’ll move github.com/moby/sys/mountinfo to the first require block, next to github.com/moby/sys/mount, and keep the existing gomodjail:unconfined annotation.

@AkihiroSuda

Copy link
Copy Markdown
Member

Please squash the commits

@AkihiroSuda AkihiroSuda added this to the v2.5.0 milestone Nov 25, 2026
Parse bind mount options even when the mode is omitted so two-field volume specs use the same default propagation as other bind mount forms.

Cover shorthand bind mounts with absolute and relative source paths.

Signed-off-by: qwe962 <1903740562@qq.com>
@qwe962
qwe962 force-pushed the fix/bind-mount-default-propagation branch from 8b549d8 to ff4b45a Compare November 25, 2026 15:36
@qwe962

qwe962 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Please squash the commits
Squashed the four commits into one. Thanks! @AkihiroSuda

@AkihiroSuda AkihiroSuda left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks

@AkihiroSuda
AkihiroSuda merged commit 3a1a5e3 into containerd:main Nov 26, 2026
140 of 158 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unqualified bind mounts inherit shared propagation when a sibling volume requests rshared

3 participants