Repository navigation
Fix/bind mounts type none - #1150
Conversation
✅ Deploy Preview for urunc ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
d139be7 to
d3251f1
Compare
|
thanks @cmainas! Treating A few suggestions before I approve:
Nits:
Rebase & merge replays cleanly on current main (only the spellcheck dict moved), so no need to rebase just for that. Happy to approve once the first two are addressed -- what do you think? |
d3251f1 to
f7e6e1d
Compare
|
Thank you @ananos for the review. I have addressed the first two comments and the first nit. For the e2e test cases, this is already handled by unit tests and adding one e2e test which is not related to e2e testing (with guest/monitor) sounds an overkill. |
An OCI mount is a bind mount when its options include "bind" or "rbind"; its Type is then a dummy that runtimes such as runc ignore. Docker sets it to "bind", but containerd and nerdctl emit volumes (`nerdctl run -v host:/data`) with Type "none". urunc only checked for Type "bind", so such volumes were dropped everywhere bind mounts are filtered: they never reached the shared rootfs of a virtiofs/9p guest, were not copied into a block rootfs or an initrd, and were not remounted with their VFS flags. Add isBindMount, which follows the runtime spec and looks only at the options, and use it in every such check (mount application, shared-fs and block filtering). The initrd package no longer filters mounts itself; its caller passes it only the bind mounts. Also a mount spelled only by its Type, e.g. Type "bind" without a bind option, is not a bind mount and is dropped like other unsupported mounts, so make the e2e ctr helper pass the rbind option that `ctr --mount type=bind` omits. PR: #1150 Signed-off-by: Charalampos Mainas <charalampos.mainas@gmail.com> Reviewed-by: Anastassios Nanos <ananos@nubificus.co.uk> Approved-by: Anastassios Nanos <ananos@nubificus.co.uk>
Rootless runtimes replace the container's sysfs mount with an rbind of the host's /sys, e.g. with --net=host, since they cannot mount a fresh sysfs. Now that such Type "none" binds are recognised, this mount would end up in the rootfs shared with a virtiofs/9p guest, exposing the host's sysfs to it and, through the file server, letting the guest write host kernel knobs. On the block and initrd paths, single-file binds from /proc or /sys would also copy host state into the guest. Add onlyBindMounts as the single place that selects the spec mounts passed to the guest: the bind mounts, minus those whose source resides on a host kernel filesystem (sysfs, procfs, cgroupfs, securityfs, debugfs, tracefs, bpffs, efivarfs, pstore, binfmt_misc, nsfs, configfs, fusectl, mqueue, selinuxfs and smackfs), detected through statfs. Only the source's own filesystem is checked, not what an rbind brings along below it. Skipped mounts are logged. Use it for the shared-fs, initrd and block (file copies and volumes) paths. The guest has its own kernel and its own instances of these filesystems. newRootfsBuilder calls it once and hands the result to the shared-fs, initrd and block (file copies and volumes) paths, which no longer filter on their own. filterBindMounts now only re-roots the mounts, so rename it to rebaseBindMounts. A bind mount whose source cannot be statfs'd, e.g. because it does not exist, now fails container creation on every path. So does a mount with Type "bind" or "rbind" but neither option: it is not a bind mount and runc rejects it too, while dropping it would start the container without the volume it asked for. PR: #1150 Signed-off-by: Charalampos Mainas <charalampos.mainas@gmail.com> Reviewed-by: Anastassios Nanos <ananos@nubificus.co.uk> Approved-by: Anastassios Nanos <ananos@nubificus.co.uk>
For a block rootfs, copyMountfiles copies the source of each bind mount into the rootfs with fileFromHost, which only refused directories. Any other special file broke container creation: opening a socket fails, opening a FIFO blocks forever and reading a device such as /dev/urandom never ends, filling the rootfs. Replace ErrCopyDir with ErrNotRegularFile, which fileFromHost returns for anything that is not a regular file, before opening it, and skip such mounts in copyMountfiles as directories already were. This matches the initrd path, which already copies only regular files. PR: #1150 Signed-off-by: Charalampos Mainas <charalampos.mainas@gmail.com> Reviewed-by: Anastassios Nanos <ananos@nubificus.co.uk> Approved-by: Anastassios Nanos <ananos@nubificus.co.uk>
f7e6e1d to
d544628
Compare
An OCI mount is a bind mount when its options include "bind" or "rbind"; its Type is then a dummy that runtimes such as runc ignore. Docker sets it to "bind", but containerd and nerdctl emit volumes (`nerdctl run -v host:/data`) with Type "none". urunc only checked for Type "bind", so such volumes were dropped everywhere bind mounts are filtered: they never reached the shared rootfs of a virtiofs/9p guest, were not copied into a block rootfs or an initrd, and were not remounted with their VFS flags. Add isBindMount, which follows the runtime spec and looks only at the options, and use it in every such check (mount application, shared-fs and block filtering). The initrd package no longer filters mounts itself; its caller passes it only the bind mounts. Also a mount spelled only by its Type, e.g. Type "bind" without a bind option, is not a bind mount and is dropped like other unsupported mounts, so make the e2e ctr helper pass the rbind option that `ctr --mount type=bind` omits. PR: #1150 Signed-off-by: Charalampos Mainas <charalampos.mainas@gmail.com> Reviewed-by: Anastassios Nanos <ananos@nubificus.co.uk> Approved-by: Anastassios Nanos <ananos@nubificus.co.uk>
Rootless runtimes replace the container's sysfs mount with an rbind of the host's /sys, e.g. with --net=host, since they cannot mount a fresh sysfs. Now that such Type "none" binds are recognised, this mount would end up in the rootfs shared with a virtiofs/9p guest, exposing the host's sysfs to it and, through the file server, letting the guest write host kernel knobs. On the block and initrd paths, single-file binds from /proc or /sys would also copy host state into the guest. Add onlyBindMounts as the single place that selects the spec mounts passed to the guest: the bind mounts, minus those whose source resides on a host kernel filesystem (sysfs, procfs, cgroupfs, securityfs, debugfs, tracefs, bpffs, efivarfs, pstore, binfmt_misc, nsfs, configfs, fusectl, mqueue, selinuxfs and smackfs), detected through statfs. Only the source's own filesystem is checked, not what an rbind brings along below it. Skipped mounts are logged. Use it for the shared-fs, initrd and block (file copies and volumes) paths. The guest has its own kernel and its own instances of these filesystems. newRootfsBuilder calls it once and hands the result to the shared-fs, initrd and block (file copies and volumes) paths, which no longer filter on their own. filterBindMounts now only re-roots the mounts, so rename it to rebaseBindMounts. A bind mount whose source cannot be statfs'd, e.g. because it does not exist, now fails container creation on every path. So does a mount with Type "bind" or "rbind" but neither option: it is not a bind mount and runc rejects it too, while dropping it would start the container without the volume it asked for. PR: #1150 Signed-off-by: Charalampos Mainas <charalampos.mainas@gmail.com> Reviewed-by: Anastassios Nanos <ananos@nubificus.co.uk> Approved-by: Anastassios Nanos <ananos@nubificus.co.uk>
Description
containerd and nerdctl spell volumes as
{"type": "none", "options": ["rbind", ...]}.urunc only acceptedtype: "bind", so such volumes never reached the guest.isBindMountnow follows the OCI runtime spec and runc: a mount is a bind mount if its options includebindorrbind,regardless of its type. A mount withtype: "bind"but no such option is dropped, so the e2e ctr helper now passesoptions=rbind./sys, which would otherwise end up in the virtiofs/9p share.onlyBindMountsskips, with a warning, bind mounts whose source is on sysfs, procfs, cgroupfs or another kernel filesystem, for every rootfs type.At last, a bind mount whose source does not exist now fails container creation for every rootfs type.
Related issues
How was this tested?
With e2e tests
LLM usage
Opus 5.5
Checklist
make lint).make test_ctr,make test_nerdctl,make test_docker,make test_crictl).