Skip to content

libct: simplify setReadonly, fix losing rootfs flags - #5588

Merged
AkihiroSuda merged 1 commit into
opencontainers:mainfrom
kolyshkin:ro-rootfs-keep-flags
Nov 1, 2026
Merged

AkihiroSuda merged 1 commit into
opencontainers:mainfrom
kolyshkin:ro-rootfs-keep-flags

Conversation

@kolyshkin

Copy link
Copy Markdown
Contributor

setReadonly remounts / with MS_BIND|MS_REMOUNT|MS_RDONLY. A bind remount sets the per-mount flags to exactly the ones given, so when not in a user namespace it silently clears nosuid, nodev, noexec and nosymfollow which may be set on the rootfs mount.

This does not happen in a user namespace, where these flags are locked, so the remount fails, and the fallback keeps them.

The fix is to always use the existing flags, not only on fallback. In other words, the fallback is no longer needed.

While at it

  • use statfsToMountFlags to convert, since ST_* and MS_* values may differ (e.g. ST_NOSYMFOLLOW != MS_NOSYMFOLLOW);
  • do not take other flags (e.g ATIME) as the kernel preserves those on remount.

Add an integration test.

setReadonly remounts / with MS_BIND|MS_REMOUNT|MS_RDONLY. A bind
remount sets the per-mount flags to exactly the ones given, so when
not in a user namespace it silently clears nosuid, nodev, noexec and
nosymfollow which may be set on the rootfs mount.

This does not happen in a user namespace, where these flags are locked,
so the remount fails, and the fallback keeps them.

The fix is to always use the existing flags, not only on fallback.
In other words, the fallback is no longer needed.

While at it
 - use statfsToMountFlags to convert, since ST_* and MS_*
   values may differ (e.g. ST_NOSYMFOLLOW != MS_NOSYMFOLLOW);
 - do not take other flags (e.g *ATIME*) as the kernel preserves
   those on remount.

Add an integration test.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin kolyshkin added this to the 1.6.0-rc.2 milestone Oct 28, 2026
@kolyshkin kolyshkin added the backport/1.5-todo A PR in main branch which needs to be backported to release-1.5 label Oct 28, 2026
@kolyshkin
kolyshkin requested review from AkihiroSuda, cyphar, lifubang and rata and removed request for lifubang October 28, 2026 02:00
@kolyshkin

Copy link
Copy Markdown
Contributor Author

@opencontainers/runc-maintainers PTAL; this one is easy to review and fixes a real bug (for a change). I'd like to port it to 1.5 branch as well.

@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 changed the title libct: simplify setReadonly, keep rootfs flags libct: simplify setReadonly, fix losing rootfs flags Oct 28, 2026
@kolyshkin kolyshkin modified the milestones: 1.6.0-rc.2, 1.5.3 Oct 29, 2026
@kolyshkin

Copy link
Copy Markdown
Contributor Author

@opencontainers/runc-maintainers this needs a second LGTM

@kolyshkin

Copy link
Copy Markdown
Contributor Author

NB: backporting this to 1.5 requires #5590!

@kolyshkin

Copy link
Copy Markdown
Contributor Author

This is a real bug fix; PTAL @opencontainers/runc-maintainers 🙏🏻

@AkihiroSuda
AkihiroSuda enabled auto-merge November 1, 2026 07:10
@AkihiroSuda
AkihiroSuda added this pull request to the merge queue Nov 1, 2026
Merged via the queue into opencontainers:main with commit ff9a0c1 Nov 1, 2026
96 of 97 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/1.5-todo A PR in main branch which needs to be backported to release-1.5

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants