Skip to content

nspawn: actually mask certain files under /proc/#40833

Open
mrc0mmand wants to merge 1 commit intosystemd:mainfrom
mrc0mmand:nspawn-make-inaccesible-paths-actually-inaccessible
Open

nspawn: actually mask certain files under /proc/#40833
mrc0mmand wants to merge 1 commit intosystemd:mainfrom
mrc0mmand:nspawn-make-inaccesible-paths-actually-inaccessible

Conversation

@mrc0mmand
Copy link
Member

/run/systemd/inaccessible/ exists only on host - in the container we have
/run/host/inaccessible/, and since all the inaccessible mounts have
MOUNT_IN_USERNS we need to use the latter one, otherwise the masking
gets silently skipped:

~# SYSTEMD_LOG_LEVEL=debug systemd-nspawn -q --directory=foo ls -la /proc/kallsyms
...
Bind-mounting /run/systemd/inaccessible/reg on /proc/kallsyms (MS_BIND "")...
Failed to mount /run/systemd/inaccessible/reg (type n/a) on /proc/kallsyms (MS_BIND ""): No such file or directory
Changing mount flags /proc/kallsyms (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_REMOUNT|MS_BIND "")...
Failed to mount n/a (type n/a) on /proc/kallsyms (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_REMOUNT|MS_BIND ""): Invalid argument
Bind-mounting /run/systemd/inaccessible/reg on /proc/kcore (MS_BIND "")...
Failed to mount /run/systemd/inaccessible/reg (type n/a) on /proc/kcore (MS_BIND ""): No such file or directory
Changing mount flags /proc/kcore (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_REMOUNT|MS_BIND "")...
Failed to mount n/a (type n/a) on /proc/kcore (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_REMOUNT|MS_BIND ""): Invalid argument
...
Inner child finished, invoking payload.
-r--r--r--. 1 root root 0 Feb 25 13:19 /proc/kallsyms

Now, this has been broken for a long time (I guess since de40a30, /cc @poettering ). And due to this, some folks actually started relying on this behavior. I know this because I noticed this issue due to one such use case - recently we got an internal report that kernel folks can't build kernels in RHEL 8 mock environments when using the nspawn isolation, because /proc/kallsyms is inaccessible there. That's before de40a30 and hence the masking works there as expected:

# rpm -q systemd
systemd-239-82.el8_10.13.x86_64
# systemd-nspawn -q --directory=foo ls -l /proc/kallsyms
----------. 0 root root 0 Feb 25 13:35 /proc/kallsyms

But later RHEL/Fedora/systemd versions don't mask these files properly, so they're still readable, which won't be possible after fixing it. Unfortunately, I don't think there's currently a way how to "override" this masking to "unbreak" these use cases, as --bind*= and friends won't work there (maybe SYSTEMD_NSPAWN_API_VFS_WRITABLE=yes would work, but it's ugly and I'm not sure about all the implications). Not sure what to do in this case, but I suspect that this might affect Fedora kernel builds as well if fixed (/cc @keszybz).

/run/systemd/inaccessible/ exists only on host - in the container we have
/run/host/inaccessible/, and since all the inaccessible mounts have
MOUNT_IN_USERNS we need to use the latter one, otherwise the masking
gets silently skipped:

~# SYSTEMD_LOG_LEVEL=debug systemd-nspawn -q --directory=foo ls -la /proc/kallsyms
...
Bind-mounting /run/systemd/inaccessible/reg on /proc/kallsyms (MS_BIND "")...
Failed to mount /run/systemd/inaccessible/reg (type n/a) on /proc/kallsyms (MS_BIND ""): No such file or directory
Changing mount flags /proc/kallsyms (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_REMOUNT|MS_BIND "")...
Failed to mount n/a (type n/a) on /proc/kallsyms (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_REMOUNT|MS_BIND ""): Invalid argument
Bind-mounting /run/systemd/inaccessible/reg on /proc/kcore (MS_BIND "")...
Failed to mount /run/systemd/inaccessible/reg (type n/a) on /proc/kcore (MS_BIND ""): No such file or directory
Changing mount flags /proc/kcore (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_REMOUNT|MS_BIND "")...
Failed to mount n/a (type n/a) on /proc/kcore (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_REMOUNT|MS_BIND ""): Invalid argument
...
Inner child finished, invoking payload.
-r--r--r--. 1 root root 0 Feb 25 13:19 /proc/kallsyms
@github-actions github-actions bot added nspawn tests please-review PR is ready for (re-)review by a maintainer labels Feb 25, 2026
@yuwata yuwata added this to the v260 milestone Feb 25, 2026
@yuwata
Copy link
Member

yuwata commented Mar 2, 2026

Could you also add test case with SYSTEMD_NSPAWN_API_VFS_WRITABLE=yes (and network)?

@yuwata yuwata added good-to-merge/with-minor-suggestions and removed please-review PR is ready for (re-)review by a maintainer labels Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants