Skip to content

overlay: don't override a configured index mount option - #13805

Merged
mxpv merged 1 commit into
containerd:mainfrom
AprilNEA:fix/overlay-mount-options-index-check
Jul 18, 2026
Merged

mxpv merged 1 commit into
containerd:mainfrom
AprilNEA:fix/overlay-mount-options-index-check

Conversation

@AprilNEA

@AprilNEA AprilNEA commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

The overlay snapshotter auto-appends index=off to its mount options unless the user configuration already carries an index option — but the guard can never fire:

if !hasOption(config.mountOptions, "index", false) && supportsIndex() {
    config.mountOptions = append(config.mountOptions, "index=off")
}

hasOption(..., hasValue=false) compares each option against the literal string "index". The index option is always valued (index=on / index=off), so no valid configuration ever matches, and index=off is appended unconditionally whenever /sys/module/overlay/parameters/index exists.

Mount options are last-wins in the kernel, so a configured index=on is silently overridden. The practical casualty is NFS export of overlay mounts: configuring

[plugins."io.containerd.snapshotter.v1.overlayfs"]
  mount_options = ["index=on", "nfs_export=on"]

produces index=on,nfs_export=on,index=off on every snapshot mount, which the kernel rejects with EINVAL — nfs_export=on conflicts with an explicit index=off (fs/overlayfs/params.c, "conflicting options: nfs_export=on,index=off"). The first casualty is image unpack:

failed to mount /tmp/containerd-mount2856290739: ...
data: "workdir=...,upperdir=...,lowerdir=...,index=on,nfs_export=on,index=off", err: invalid argument

(Reproduced on containerd 2.2.5 / kernel 6.12 with dockerd 29.6.1 using the containerd image store; the code is unchanged on main.)

This changes the check to hasValue=true (prefix index= match, the same helper the valued form exists for), so a configured index option suppresses the auto-append. The neighboring userxattr check keeps hasValue=false, which is correct for a bare flag option.

Also adds a regression test asserting that a snapshotter configured with WithMountOptions([]string{"index=on", "nfs_export=on"}) does not end up with index=off in its options.

Avoid overriding user-configured index mount option in overlayfs snapshotter

Copilot AI review requested due to automatic review settings July 17, 2026 07:21
@github-project-automation github-project-automation Bot moved this to Needs Triage in Pull Request Review Jul 17, 2026

Copilot AI left a comment

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.

Pull request overview

This PR fixes the overlay snapshotter’s handling of the index overlayfs mount option so that an explicit user configuration (index=on/index=off) is not silently overridden by the snapshotter’s default behavior. This prevents invalid option combinations (notably nfs_export=on with an appended index=off) that can cause overlay mounts to fail with EINVAL.

Changes:

  • Fixes the index option guard to treat index as a valued option by matching index= (instead of the bare index).
  • Adds a regression test asserting that configured index=on prevents auto-appending index=off.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
plugins/snapshots/overlay/overlay.go Corrects option-detection logic so configured index=... isn’t overridden by an appended index=off.
plugins/snapshots/overlay/overlay_test.go Adds a regression test ensuring index=off is not auto-appended when index=on is configured.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plugins/snapshots/overlay/overlay.go Outdated
Comment on lines 179 to 190

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.

I suggest we drop the hasValue argument entirely, because we're always looking for key in a key[=value] string. That way the caller doesn't have to be aware of the option requires (or does not require) a value.

While updating, I would also replace the manual splitting for a basic strings.Cut (we can keep a fast-path for a straight match);

func hasOption(options []string, key string) bool {
	for _, option := range options {
		if option == key {
			return true
		}
		optionKey, _, _ := strings.Cut(option, "=")
		if optionKey == key {
			return true
		}
	}
	return false
}

AFAICS, we're only interested "was option index (or userxattr ) used as part of the options (regardless of what value they have)"? So removing the boolean makes that much more fool-proof.

if !hasOption(config.mountOptions, "userxattr", false) {
// figure out whether "userxattr" option is recognized by the kernel && needed
userxattr, err := overlayutils.NeedsUserXAttr(root)
if err != nil {
log.L.WithError(err).Warnf("cannot detect whether \"userxattr\" option needs to be used, assuming to be %v", userxattr)
}
if userxattr {
config.mountOptions = append(config.mountOptions, "userxattr")
}
}
if !hasOption(config.mountOptions, "index", false) && supportsIndex() {
config.mountOptions = append(config.mountOptions, "index=off")
}

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.

Good call — done. Dropped the boolean entirely: hasOption now matches the key of a key[=value] option via strings.Cut (with the exact-match fast path kept), and both call sites just pass the key.

NewSnapshotter auto-appends "index=off" unless the configured
mount_options already carry an index option — but the check used
hasOption(..., "index", false), which compares against the literal
string "index". No valid mount option ever equals "index" (it is
always valued, "index=on"/"index=off"), so the append happened
unconditionally whenever the kernel exposes the overlay index
parameter.

Mount options are last-wins in the kernel, so a user-configured
"index=on" was silently overridden. Worse, configuring
mount_options = ["index=on", "nfs_export=on"] (the documented way to
make overlay mounts NFS-exportable) produced
"index=on,nfs_export=on,index=off", which the kernel rejects with
EINVAL (nfs_export=on conflicts with an explicit index=off) — breaking
every snapshot mount including image unpack.

Make hasOption match the key of a "key[=value]" option so callers need
not care whether the option takes a value, and add a regression test.

Signed-off-by: AprilNEA <[email protected]>
Copilot AI review requested due to automatic review settings July 17, 2026 08:04
@AprilNEA
AprilNEA force-pushed the fix/overlay-mount-options-index-check branch from 1f86bb1 to 5e25f36 Compare July 17, 2026 08:04
@kubernetes-prow kubernetes-prow Bot added size/M and removed size/S labels Jul 17, 2026

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@thaJeztah thaJeztah 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.

LGTM, thx!

@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review Jul 18, 2026
@mxpv
mxpv added this pull request to the merge queue Jul 18, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 18, 2026
@mxpv
mxpv added this pull request to the merge queue Jul 18, 2026
Merged via the queue into containerd:main with commit 820b8e7 Jul 18, 2026
51 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Jul 18, 2026
@AprilNEA

Copy link
Copy Markdown
Contributor Author

/cherry-pick release/2.2

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@AprilNEA: only containerd org members may request cherry picks. If you are already part of the org, make sure to change your membership to public. Otherwise you can still do the cherry-pick manually.

Details

In response to this:

/cherry-pick release/2.2

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@chrishenzie

Copy link
Copy Markdown
Member

Hi @AprilNEA, thank you for the fix and opening these backports.

Since these cherry-pick cleanly, I'm going to use Prow to land them instead, which is our preferred process. Manual backports are still appreciated, but we use them primarily when there's a conflict or needs changes to land in an older branch

/cherry-pick release/2.0
/cherry-pick release/2.2
/cherry-pick release/2.3

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@chrishenzie: new pull request created: #14490

Details

In response to this:

Hi @AprilNEA, thank you for the fix and opening these backports.

Since these cherry-pick cleanly, I'm going to use Prow to land them instead, which is our preferred process. Manual backports are still appreciated, but we use them primarily when there's a conflict or needs changes to land in an older branch

/cherry-pick release/2.0
/cherry-pick release/2.2
/cherry-pick release/2.3

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@chrishenzie chrishenzie added cherry-pick/2.0.x Change to be cherry picked to release/2.0 branch cherry-pick/2.2.x Change to be cherry picked to release/2.2 branch cherry-pick/2.3.x Change to be cherry picked to release/2.3 labels Oct 29, 2026
@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@chrishenzie: new pull request created: #14491

Details

In response to this:

Hi @AprilNEA, thank you for the fix and opening these backports.

Since these cherry-pick cleanly, I'm going to use Prow to land them instead, which is our preferred process. Manual backports are still appreciated, but we use them primarily when there's a conflict or needs changes to land in an older branch

/cherry-pick release/2.0
/cherry-pick release/2.2
/cherry-pick release/2.3

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@chrishenzie: new pull request created: #14492

Details

In response to this:

Hi @AprilNEA, thank you for the fix and opening these backports.

Since these cherry-pick cleanly, I'm going to use Prow to land them instead, which is our preferred process. Manual backports are still appreciated, but we use them primarily when there's a conflict or needs changes to land in an older branch

/cherry-pick release/2.0
/cherry-pick release/2.2
/cherry-pick release/2.3

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@chrishenzie chrishenzie added cherry-picked/2.0.x PR commits are cherry picked into the release/2.0 branch cherry-picked/2.2.x PR commits are cherry-picked into release/2.2 branch cherry-picked/2.3.x PR commits are cherry picked into release/2.3 branch and removed cherry-pick/2.0.x Change to be cherry picked to release/2.0 branch cherry-pick/2.2.x Change to be cherry picked to release/2.2 branch cherry-pick/2.3.x Change to be cherry picked to release/2.3 labels Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/snapshotters Snapshotters cherry-picked/2.0.x PR commits are cherry picked into the release/2.0 branch cherry-picked/2.2.x PR commits are cherry-picked into release/2.2 branch cherry-picked/2.3.x PR commits are cherry picked into release/2.3 branch size/M

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

7 participants