Repository navigation
agent: mask directories in maskedPaths with a shared read-only tmpfs - #14189
Merged
Merged
Conversation
Contributor
Author
fidencio
reviewed
Nov 1, 2026
mask_path bind-mounts /dev/null over each entry of linux.maskedPaths and treats ENOTDIR as success, so a directory such as /sys/firmware or /proc/acpi stays visible in the guest. containerd's default list has five directories, and it adds one thermal_throttle directory per CPU. Mount an empty read-only tmpfs (nr_blocks=1,nr_inodes=1) over the first masked directory and bind-mount it over the others. A bind shares the superblock, so it is read-only too and the container gets one tmpfs instance however many directories are masked. When SELinux is enabled in the guest, the tmpfs gets the spec's mount label, like the other mounts. runc and crun mask directories the same way. Fixes: kata-containers#14188 Signed-off-by: Davanum Srinivas <[email protected]>
1 of 2 tasks
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Critical masking defects can abort container creation for valid masked-path orders and omit the supplied tmpfs mount label on SELinux-enabled guests.
3 open issues
What changed in this PR
This PR addresses directory entries in maskedPaths being left exposed by kata-agent, as reported in #14188. It adds directory masking alongside the existing file masking.
Changes:
- Masks directories with an empty, read-only tmpfs shared across entries.
- Adds mount-label handling for SELinux-enabled guests.
- Extends unit tests for directory reuse, file masks, and skipped paths.
| File | Description |
|---|---|
src/agent/rustjail/src/mount.rs |
Implements shared tmpfs directory masking, passes the spec’s mount label, and extends masking tests. |
Review effort: Balanced
selinux::is_enabled looks for selinuxfs in /proc/mounts. finish_rootfs runs after pivot_rootfs has detached the guest root, so /proc/mounts in the container no longer lists the guest's selinuxfs and the check returns false. On an SELinux guest the masking tmpfs then gets no context option. do_init_child already reads the SELinux state before it unshares the mount namespace and uses it for the process label. Pass that value to finish_rootfs and mask_paths. Signed-off-by: Davanum Srinivas <[email protected]>
BbolroC
approved these changes
Nov 2, 2026
BbolroC
left a comment
Member
There was a problem hiding this comment.
Overall, it looks good to me. I've left just one comment, which is non-blocker. Thanks!
Member
|
@zvonkok back to your question: Here is my two cents:
So, |
mask_path bind-mounted the shared tmpfs by the path it was mounted on. A later entry in maskedPaths can mask a parent of that path, and the next bind then fails with ENOENT. With /a/b, /a and /c in that order, /a/b holds the tmpfs, masking /a hides it, and the bind onto /c aborts the container start. Open the root of the tmpfs with O_PATH after the first mount and bind from /proc/self/fd instead. The descriptor stays attached to the tmpfs whatever is mounted over its path later. runc and crun keep a descriptor as well. The unit tests mock mount(). The mock now records its calls, so the tests check what each masked path gets mounted from: /dev/null for a file, a read-only tmpfs with the mount label for the first directory, and the descriptor of that tmpfs for every later directory, also when a child is listed before its parent. test_mask_path builds its tree in a temporary directory instead of using /tmp and /dev. Signed-off-by: Davanum Srinivas <[email protected]>
zvonkok
approved these changes
Nov 2, 2026
BbolroC
added a commit
to BbolroC/kata-containers
that referenced
this pull request
Nov 3, 2026
The IBM SEL check in `k8s-confidential.bats` runs "cd /sys/firmware/uv; cat prot_virt_guest | grep 1" over ssh inside the workload container. containerd lists /sys/firmware in maskedPaths, and since the agent started masking directories with an empty read-only tmpfs (kata-containers#14189), the container no longer sees /sys/firmware/uv. grep then exits non-zero, the ssh loop reports "Failed to connect to pod." six times and the test dies with "Confidential compute is expected but not enabled.", although the guest is a protected env. A privileged container has no masked paths, so set privileged on the Deployment's container for qemu-se* only. The other TEE flavours check dmesg or cpuid and do not read /sys/firmware, so they keep the unmodified pod YAML. This is a test-only workaround. It is not a recommended configuration, and real workloads should not run privileged just to see /sys/firmware. Assisted-By: IBM Bob Signed-off-by: Hyounggyu Choi <[email protected]>
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.

kata-agent bind-mounts /dev/null over each maskedPaths entry and treats ENOTDIR as success, so
directories such as /sys/firmware are never masked. With containerd's defaults every kata
container can read the guest's ACPI tables, SMBIOS table and memory map, and a rootfs directory
in the list stays writable.
Mount an empty read-only tmpfs (nr_blocks=1,nr_inodes=1) over the first masked directory and
bind-mount it over the others, so one tmpfs covers them all. runc and crun do the same:
The tmpfs gets the spec's mount label when SELinux is enabled in the guest, like the other
mounts.
Fixes: #14188
Tested on x86_64 with kata-static 4.3.1 (runtime-rs, cloud-hypervisor and qemu, guest kernel
6.18.56) and the agent from this branch in the guest image:
under a file: 12 masks on one superblock, files read empty, the rest skipped