Commit Graph
7 Commits
Author SHA1 Message Date
Aadhar Agarwal 6f7bb48624 core/mount: Filter X-containerd.* options before kernel mount
The X-containerd.* prefix is reserved for containerd-internal mount
options that are processed by containerd components (such as mount
transformers and handlers). These options must not be passed to the
kernel mount syscall.

This change adds filtering at the core mount layer
as a safety net to prevent kernel errors if components forget to clean
up their options.

Signed-off-by: Aadhar Agarwal <aadagarwal@microsoft.com>
2026-03-23 23:50:54 +00:00
user.email 1466c53196 core/mount: add test for getUnprivilegedMountFlags
Mounts a tmpfs with MS_NOEXEC, MS_NOATIME, and MS_NODIRATIME and
verifies that getUnprivilegedMountFlags detects all of them. These
three flags were the ones missed by the range-over-indices bug.

Also verifies that flags not present on the mount (MS_NOSUID,
MS_NODEV, MS_RDONLY) are not falsely reported.

Signed-off-by: Luke Hinds <luke@stacklok.com>
2026-02-26 00:13:53 -06:00
Rodrigo Campos 27ba690a1e core/mount: Test cleanup of DoPrepareIDMappedOverlay()
Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2025-08-19 14:58:09 +02:00
Rodrigo Campos dd7fe0b76f core/mount: Properly cleanup on doPrepareIDMappedOverlay errors
Before this patch, the cleanup was unconditionally trying an unmount,
which is not needed if the mount never succeeded in the first place.
This causes logs of failed stuff, that should never be there.
Also, one function was creating the tmpDir and the nested one removing
it (in the cleanup function), which complicates the reasoning about
not leaking resources.

This patch on one hand moves the creation of the tmpDir into the
function that will remove it later and renames the parameter. On the
other hand, it also separates the cleanup function in two functions:
cleanDir() and cleanMount(). Each one will clean the directory or the
mount, only if needed, and a new cleanup function that just calls
cleanDir() and cleanMount() is returned as the cleanup function handler.

Because we now create the tmp directory inside the function, we need to
adjust the test: the directory passed as param now will exist, but it
shoild be empty. Therefore, we change the os.Stat() to an os.Remove().
If it's not empty (the cleanup didn't work), the remove will fail.

Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2025-08-19 14:58:09 +02:00
Andrew Halaney 6e9b6eadac core/mount: Only idmap once per overlayfs, not per layer
Per layer idmap'ed bind mounts are costly to performance, as shown in
[0]. Each one requires taking various kernel locks, and each one shows
up in the host's mount table leading to some components like systemd
processing all these temporary mounts unnecessarily.

Let's instead go ahead and idmap the common directory of all the
layers to achieve the same effect. Now instead of being a function of
the number of layers, its a constant idmap per overlayfs! This can have
a big impact. For example, imagine running 100 containers at once, each
with 50 layers. That's going from doing 100 * 50 (5000) bind mounts, to
just 100. In reality both the shim and containerd proper do this, so its
actually double that!

[0]: https://github.com/containerd/containerd/issues/12048#issuecomment-3050444019
Signed-off-by: Andrew Halaney <ahalaney@netflix.com>
2025-08-12 16:28:00 -05:00
Mike Baynton 1e3d10dc29 Make ovl idmap mounts read-only
This is a planned follow-on from #10721 primarily at the request of
@fuweid, exchanging MNT_DETACH at unmount time for MOUNT_ATTR_RDONLY at
mount time. The effect is to increase risk of unmount failure due to
EBUSY (as observed in the wild) but add an additional protection that the
then-leaked bind mount does not act as a conduit for inadvertent modification
of the underlying data, including our own efforts to clean up the mountpoint.

Tests covering the lifecycle of the temporary idmap mounts and integrity
of the underlying lower layer data is also included in the normal and
failed-unmount case.

Fixes #10704

Signed-off-by: Mike Baynton <mike@mbaynton.com>
2024-12-21 16:02:33 -06:00
Derek McGowan 6e5408dcec Move mount to core/mount
Signed-off-by: Derek McGowan <derek@mcg.dev>
2024-01-17 09:52:12 -08:00