Skip to content

libct: don't strip rootfs prefix from mount destinations - #5556

Merged
kolyshkin merged 2 commits into
opencontainers:mainfrom
kolyshkin:mount-dst-rootfs-deprecate
Oct 26, 2026
Merged

kolyshkin merged 2 commits into
opencontainers:mainfrom
kolyshkin:mount-dst-rootfs-deprecate

Conversation

@kolyshkin

@kolyshkin kolyshkin commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

For legacy reasons (see commit 087caf6, from the times when Docker used libcontainer directly), runc accepts a mount destination prefixed with the container rootfs path, and strips the prefix. This is not described by the runtime spec (which says the destination is a path inside the container), is not supported by other runtimes (e.g. crun), and is ambiguous, as such a path may legitimately exist inside the container.

I looked at the current code of moby, containerd (CRI), CRI-O, podman, buildah, buildkit, nerdctl, nomad, and garden (guardian), and none of them rely on this.

Remove it, so such a destination is used as is, i.e. as a path inside the container. Most of the stripping was done by hallucinateUnsafePath (used by pathrs.MkdirAllInRoot and friends), so device node paths are no longer stripped either. Add an integration test.

While at it, remove the duplicate relative mount destination warning from specconv, together with the stale TODO saying it is to be changed to an error (the runtime spec now allows relative mount destinations on Linux, see opencontainers/runtime-spec#1225 and #4013).

A follow-up to #5503.

@kolyshkin
kolyshkin force-pushed the mount-dst-rootfs-deprecate branch from 422bcf1 to 8c1d9e5 Compare October 16, 2026 06:05
@kolyshkin
kolyshkin force-pushed the mount-dst-rootfs-deprecate branch 2 times, most recently from 93cd7e8 to dc314eb Compare October 16, 2026 06:17
@kolyshkin
kolyshkin requested a review from rata October 16, 2026 06:17
Comment on lines +435 to +437
if config.Rootfs != "/" && pathrs.IsLexicallyInRoot(config.Rootfs, filepath.Clean(m.Destination)) {
return fmt.Errorf("mount %+v: destination path prefixed with rootfs is **deprecated** and will be removed in runc 1.8, stripping the prefix", m)
}

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.

We should kill this behaviour but I'm not really sure what we should do about it in the long term -- ideally we would treat it as a subpath but that will break things in other ways. Do we really want these paths to become cursed in runc 1.8?

Maybe we'll need to reconsider the idea of having annotations that indicate "enable the non-insane behaviour"? Idk.

(Also the , stripping the prefix feels like it should be -- stripping the prefix or ; stripping the prefix to indicate the action a little better.)

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.

Do we really want these paths to become cursed in runc 1.8?

No, I think in 1.8 we'll just remove the code which strips host path prefix (as well as this check). Sorry the comment says otherwise; this is now fixed. I've also fixed the warning message.

OR, we can just remove the host path stripping and add a CHANGELOG entry for it.

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'd not go the annotation route. I'd either deprecate or remove it.

Commits 1f1e91b and 2192670 (PR 2917) added a check that a mount
destination is absolute (as the runtime spec required back then) to
both libcontainer/specconv and libcontainer/configs/validate.

This broke Moby, which used relative destinations for swarm configs
(issue 2928), so commit b31a934 (PR 3004) turned both errors into
warnings, with TODOs to make them errors again in a future release.
As a result, runc prints two warnings for the same relative mount
destination, for example:

  level=warning msg="mount destination tmp/bind is not absolute. Support for non-absolute mount destinations will be removed in a future release."
  level=warning msg=configuration error="mount &{... Destination:tmp/bind ...}: relative destination path is **deprecated**, using it as relative to /"

Later, the runtime spec was amended to allow relative mount
destinations on Linux, treating them as relative to "/" (see
opencontainers/runtime-spec PR 1225), and commit b17c6f2 (PR 4013)
updated the validator accordingly, removing the TODO and changing the
warning text. The specconv part was left as is, still having the stale
TODO and the "will be removed" text.

Remove the warning from specconv altogether, as the one from the
validator is sufficient (and is also seen by libcontainer users who
do not use specconv).

Fixes: b31a934 ("libcontainer: relax validation for absolute paths")
Fixes: b17c6f2 ("validator: Relax warning for not abs mount dst path")
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin
kolyshkin force-pushed the mount-dst-rootfs-deprecate branch 2 times, most recently from 474a988 to 9199eeb Compare October 21, 2026 06:14

@kolyshkin kolyshkin left a comment

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.

So, we either have to have a bunch of ugly TODOs added, and a warning that will go away, or be bold and brave and just implement those TODOs now (i.e remove host path prefix stripping).

crun never supported host path prefixed destinations and no one ever complained. I dunno

@kolyshkin
kolyshkin requested a review from cyphar October 21, 2026 06:17

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

Kubernetes users can't rely on this either, as they don't know where the rootfs will be located. With all the checks that you've done @kolyshkin , I'm fine with removing it and having the rc release be tested in several projects.

I wonder if we have to revert, if it might be simpler for us to disable the code but keep it for one release. Then, we can revert easily if needed or we can remove it after the next release.

@kolyshkin

Copy link
Copy Markdown
Contributor Author

@rata agreed; let's just remove this and release rc.2 with this so we can catch this early.

As a side note, I'd like to cut rc.2 from the main branch, and then create release-1.6 branch from rc.2 (not rc.1) -- to avoid porting every PR merged to main after rc.1 release to release-1.6.

For legacy reasons (see commit 087caf6), runc accepts a mount
destination prefixed with the container rootfs path, and strips the
prefix. This is not described by the runtime spec, which says the
destination is a path inside the container, and is not supported by
other runtimes (e.g. crun). It is also ambiguous, as such a path may
legitimately exist inside the container.

Remove the prefix stripping, so such a destination is used as is,
i.e. as a path inside the container.

Most of the stripping was done by hallucinateUnsafePath, used by
pathrs.MkdirAllInRoot and friends, so device node paths are no
longer stripped either.

Add an integration test.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin
kolyshkin force-pushed the mount-dst-rootfs-deprecate branch from 9199eeb to 2096461 Compare October 23, 2026 20:48
@kolyshkin kolyshkin changed the title libct: deprecate rootfs-prefixed mount destinations libct: don't strip rootfs prefix from mount destinations Oct 23, 2026
@kolyshkin

Copy link
Copy Markdown
Contributor Author

I wonder if we have to revert, if it might be simpler for us to disable the code but keep it for one release.

I tried implementing that, alas it's not as easy as say a bunch of #ifdef STRIP_ROOT_PREFIX in C. Here we have to do something like this:

  1. add const StripRootPrefix = false to say internal/pathrs
  2. add a bunch of if pathrs.StripRootPrefix (and a few ... else).

and the result would look ugly and (I guess) some linters will say something about dead code etc.

So I think what is here right now is the optimal way. If anything, we can git revert (it's not that we change this code frequently).

WDYT @rata?

@kolyshkin kolyshkin added this to the 1.6.0-rc.2 milestone Oct 24, 2026
@kolyshkin
kolyshkin requested a review from rata October 25, 2026 01:49
@rata

rata commented Oct 26, 2026

Copy link
Copy Markdown
Member

@kolyshkin yeap, sounds good! The disable was useful if this will ship in April to users, as a revert might be hard. If we ship it now, this seems the best path for me too :)

@rata rata 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, thanks!

@kolyshkin
kolyshkin enabled auto-merge October 26, 2026 09:32
@kolyshkin
kolyshkin added this pull request to the merge queue Oct 26, 2026
Merged via the queue into opencontainers:main with commit e997894 Oct 26, 2026
169 of 170 checks passed
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.

3 participants