Repository navigation
[Carry #5262] libct: reuse tmpfs for directory masks - #5275
Merged
thaJeztah merged 4 commits intoMay 13, 2026
Merged
Conversation
lifubang
force-pushed
the
maskdir-with-shared-tmpfs
branch
2 times, most recently
from
May 12, 2026 08:58
70ed75d to
76a00f8
Compare
Contributor
|
LGTM thanks @lifubang |
thaJeztah
reviewed
May 12, 2026
Member
|
@dims thanks for the (other) PR! This only happens with old kernels and new kernels don't suffer from this? In that case, if you can find more or less when that changed in Linux upstream, it would be great. That way we can put it in the comment and, if this got too complex or something, we can drop it when the distros are unsupported. |
Contributor
|
@rata whatever data/issues we know have ... are here:
After digging into it for a while, it does not seem like it's about kernel versions, but rather about |
Member
|
@dims Cool. Then, we want to keep this and it's not just on old kernels. Thanks again! |
lifubang
force-pushed
the
maskdir-with-shared-tmpfs
branch
2 times, most recently
from
May 13, 2026 01:29
e96103c to
3c5ced7
Compare
lifubang
force-pushed
the
maskdir-with-shared-tmpfs
branch
from
May 13, 2026 03:43
3c5ced7 to
b0320cf
Compare
Co-authored-by: Davanum Srinivas <davanum@gmail.com> Refactored-by: lifubang <lifubang@acmcoder.com> Signed-off-by: lifubang <lifubang@acmcoder.com>
Previously, masked directories (e.g., /proc/acpi, /proc/scsi) were mounted as read-only tmpfs without explicit size or inode limits. Although these mounts are meant to be empty and unwritable, the lack of resource constraints means that—should an attacker bypass the read-only protection (e.g., via container escape, mount namespace manipulation, or a kernel vulnerability)—the tmpfs could consume up to 50% of system memory by default (the kernel's default tmpfs limit). To mitigate this risk in high-density container environments and adhere to the principle of least privilege, we now explicitly set: - nr_blocks=1 (sufficient for at most one block size) - nr_inodes=1 (sufficient for at most one inode) Ref: https://man7.org/linux/man-pages/man5/tmpfs.5.html These limits ensure that even if compromised, kernel memory usage remains strictly bounded and negligible. This change aligns with best practices used by other container runtimes and strengthens defense-in-depth for sensitive masked paths. Co-authored-by: Davanum Srinivas <davanum@gmail.com> Refactored-by: lifubang <lifubang@acmcoder.com> Signed-off-by: lifubang <lifubang@acmcoder.com>
Kubernetes may add one sysfs thermal_throttle entry per CPU to maskedPaths. On large Intel systems this can produce many directory masks for a single container. runc currently handles each directory mask with a separate read-only tmpfs mount, and therefore a separate tmpfs superblock. On Linux 4.18/RHEL 8 kernels, creating and tearing down many tmpfs superblocks can contend on the global shrinker_rwsem when containers start or stop concurrently. Use one read-only tmpfs for directory masks and bind-mount it over the remaining directory targets. The first non-procfs-fd directory mount is reopened through the container root fd before it is reused. File masks still bind /dev/null, and procfs fd targets keep the existing one-tmpfs-per-target behaviour because they are fd aliases rather than stable rootfs paths. If the bind-mount of the shared source fails (e.g. due to kernel restrictions), fall back to individual tmpfs mounts for all remaining directories. Tmpfs mounts use nr_blocks=1,nr_inodes=1 to minimise kernel resource usage. The bind mounts do not create additional tmpfs superblocks. They also retain the read-only mount flag inherited from the source vfsmount, so the masking semantics remain unchanged. xref: kubernetes/kubernetes#138512 xref: kubernetes/kubernetes#138388 xref: kubernetes/kubernetes#131018 Co-authored-by: Davanum Srinivas <davanum@gmail.com> Refactored-by: lifubang <lifubang@acmcoder.com> Signed-off-by: lifubang <lifubang@acmcoder.com>
Co-authored-by: Davanum Srinivas <davanum@gmail.com> Signed-off-by: lifubang <lifubang@acmcoder.com>
lifubang
force-pushed
the
maskdir-with-shared-tmpfs
branch
from
May 13, 2026 05:05
b0320cf to
124772f
Compare
This was referenced May 13, 2026
lifubang
added a commit
to lifubang/runc
that referenced
this pull request
May 16, 2026
This is a follow-up to opencontainers#5275. That change reused a single tmpfs mount to mask multiple directories, which is efficient when masking more than one path. However, it introduced unnecessary overhead when only one directory is masked. This commit restores the original behavior for the single-path case while preserving shared tmpfs logic for multiple paths. Signed-off-by: lifubang <lifubang@acmcoder.com>
lifubang
added a commit
to lifubang/runc
that referenced
this pull request
May 16, 2026
This is a follow-up to opencontainers#5275. That change reused a single tmpfs mount to mask multiple directories, which is efficient when masking more than one path. However, it introduced unnecessary overhead when only one directory is masked. This commit restores the original behavior for the single-path case while preserving shared tmpfs logic for multiple paths. Signed-off-by: lifubang <lifubang@acmcoder.com>
lifubang
added a commit
to lifubang/runc
that referenced
this pull request
May 16, 2026
This is a follow-up to opencontainers#5275. That change reused a single tmpfs mount to mask multiple directories, which is efficient when masking more than one path. However, it introduced unnecessary overhead when only one directory is masked. This commit restores the original behavior for the single-path case while preserving shared tmpfs logic for multiple paths. Signed-off-by: lifubang <lifubang@acmcoder.com>
lifubang
added a commit
to lifubang/runc
that referenced
this pull request
May 20, 2026
This is a follow-up to opencontainers#5275. That change reused a single tmpfs mount to mask multiple directories, which is efficient when masking more than one path. However, it introduced unnecessary overhead when only one directory is masked. This commit restores the original behavior for the single-path case while preserving shared tmpfs logic for multiple paths. Signed-off-by: lifubang <lifubang@acmcoder.com> (cherry picked from commit e7e2f00) Signed-off-by: lifubang <lifubang@acmcoder.com>
lifubang
added a commit
to lifubang/runc
that referenced
this pull request
May 20, 2026
This is a follow-up to opencontainers#5275. That change reused a single tmpfs mount to mask multiple directories, which is efficient when masking more than one path. However, it introduced unnecessary overhead when only one directory is masked. This commit restores the original behavior for the single-path case while preserving shared tmpfs logic for multiple paths. Signed-off-by: lifubang <lifubang@acmcoder.com> (cherry picked from commit e7e2f00) Signed-off-by: lifubang <lifubang@acmcoder.com>
lifubang
added a commit
to lifubang/runc
that referenced
this pull request
May 20, 2026
This is a follow-up to opencontainers#5275. That change reused a single tmpfs mount to mask multiple directories, which is efficient when masking more than one path. However, it introduced unnecessary overhead when only one directory is masked. This commit restores the original behavior for the single-path case while preserving shared tmpfs logic for multiple paths. Signed-off-by: lifubang <lifubang@acmcoder.com> (cherry picked from commit e7e2f00) Signed-off-by: lifubang <lifubang@acmcoder.com>
thaJeztah
reviewed
Jun 27, 2026
| // Destination is a directory: bind mount a ro tmpfs over it. | ||
| dstType = "dir" | ||
| err = mount("tmpfs", path, "tmpfs", unix.MS_RDONLY, label.FormatMountLabel("", mountLabel)) | ||
| err = mount("tmpfs", path, "tmpfs", unix.MS_RDONLY, label.FormatMountLabel("nr_blocks=1,nr_inodes=1", mountLabel)) |
Member
There was a problem hiding this comment.
Wr0ngName
added a commit
to Wr0ngName/Mautrix-Claude
that referenced
this pull request
Sep 18, 2026
Record in .gitlab-ci.yml why the builder image is pinned rather than tracking buildx-stable-1: the runc maskPaths change (opencontainers/runc#5275, in runc v1.3.6/v1.4.3) masks /proc/acpi with a tmpfs using nr_inodes=1, which the dev.wn runner's kernel rejects with EINVAL. Includes the BuildKit -> runc version table, the upstream references (moby/moby#52972, opencontainers/runc#5348), the accepted downside (runc v1.3.5 predates the CVE-2026-41579 fix), and the two explicit conditions for revisiting: runner kernel upgraded, or a BuildKit release bundling runc >= v1.5.1. Also notes why the dockerhub job needs no pin: `imagetools create` starts no build container. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR carries forward #5262.
Wondering if a problem that showed up recently in k8s when we added more masked paths can be handled better in
runcitself? please see details below:Kubernetes may add one sysfs thermal_throttle entry per CPU to maskedPaths. On large Intel systems this can produce many directory masks for a single container. runc currently handles each directory mask with a separate read-only tmpfs mount, and therefore a separate tmpfs superblock.
On Linux 4.18/RHEL 8 kernels, creating and tearing down many tmpfs superblocks can contend on the global shrinker_rwsem when containers start or stop concurrently.
Use one read-only tmpfs for directory masks and bind-mount it over the remaining directory targets. The first non-procfs-fd directory mount is reopened through the container root fd before it is reused. File masks still bind /dev/null, and procfs fd targets keep the existing one-tmpfs-per-target behavior because they are fd aliases rather than stable rootfs paths.
The bind mounts do not create additional tmpfs superblocks. They also retain the read-only mount flag inherited from the source vfsmount, so the masking semantics remain unchanged.
xref: kubernetes/kubernetes#138512
xref: kubernetes/kubernetes#138388
xref: kubernetes/kubernetes#131018
(With some assistance from claude/codex)