Skip to content

[release/2.3] Fix input mutation in mount option helpers - #14192

Merged
mxpv merged 6 commits into
containerd:release/2.3from
vvoland:13433-release/2.3
Sep 24, 2026
Merged

mxpv merged 6 commits into
containerd:release/2.3from
vvoland:13433-release/2.3

Conversation

@vvoland

@vvoland vvoland commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

readonlyMounts, RemoveVolatileOption, RemoveIDMapOption helpers operated on their input slices directly, unexpectedly mutating the caller's data.

The existing no-mutation test assertions also suffered from the same shallow-copy problem, so they could not detect the corruption.

Avoid unexpected mutation of mount options in mount helpers

The custom copyMounts helper is equivalent to stdlib's slices.Clone.

Signed-off-by: Paweł Gronowski <[email protected]>
(cherry picked from commit 35e919f)
Signed-off-by: Paweł Gronowski <[email protected]>
readonlyMounts was modifying the caller's mounts slice in place by
writing directly to mounts[i].Options.
This caused WithReadonlyTempMount to mutate the caller's mount data.

Clone the mounts slice before modification so the original is preserved.

Signed-off-by: Paweł Gronowski <[email protected]>
(cherry picked from commit 70cfd77)
Signed-off-by: Paweł Gronowski <[email protected]>
…IDMapOption

slices.Clone only shallow-copies the []Mount slice, so cloned entries
still share their Options backing arrays with the originals.

Clone each mount's Options slice before modifying it.

Also fix the tests: the previous no-mutation assertions used
slices.Clone for the "original" snapshot, which has the same shallow
copy problem.

Signed-off-by: Paweł Gronowski <[email protected]>
(cherry picked from commit b73b82f)
Signed-off-by: Paweł Gronowski <[email protected]>
RemoveVolatileOption and RemoveIDMapOption both need to drop selected
mount options without mutating caller input.

Extract the lazy copy and filtering loop into a shared helper so both
paths keep the same behavior and future fixes apply consistently.

Signed-off-by: Paweł Gronowski <[email protected]>
(cherry picked from commit 79455dd)
Signed-off-by: Paweł Gronowski <[email protected]>
The filtered mount helpers documented copy semantics, but no-op inputs
could return the original mount and option slices. That made the
caller observe different aliasing behavior depending on whether an
option was removed.

Always build a copied result for filtered mount options and cover the
no-alias contract in the mount helper tests.

Signed-off-by: Paweł Gronowski <[email protected]>
(cherry picked from commit 674c3a1)
Signed-off-by: Paweł Gronowski <[email protected]>
Filtered mount option helpers only need to allocate when they remove
an option. No-op inputs can safely return the original slices because
the observable contract is that inputs are not mutated.

Document that behavior and keep the no-alias assertions scoped to
cases where the returned mounts differ from the input.

Signed-off-by: Paweł Gronowski <[email protected]>
(cherry picked from commit 165abaf)
Signed-off-by: Paweł Gronowski <[email protected]>
@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review Sep 24, 2026
@mxpv
mxpv merged commit 92e6694 into containerd:release/2.3 Sep 24, 2026
85 of 88 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants