Instance-controlled files and container root can reach the host through the file API helper, syscall interception and hot-plugged disks
Description
Reported from Incus. This advisory was copied from the Incus advisory GHSA-28m6-7v43-rr8m.
A number of host-side helpers that work on behalf of a container did part of their work in the container's context, or trusted data the container controls.
The helper serving the file API and SFTP enters the instance's root filesystem before the C library has finished initializing. Locale data and name service modules were then looked up inside the instance, so a shared object stored in the instance was loaded by a process running as root on the host. This also applies to instances that were never started and to custom volumes.
With system call interception enabled, three more issues exist. The helper running the container's mount.fuse passed it the daemon's open file descriptors, including the listening socket of the daemon's database. The intercepted mknod could be made to act on a different process than the one that issued the call. The intercepted mount, mknod and setxattr read strings from the container without making sure they were terminated, reading past the end of the buffer.
A read-only disk using ID shifting that is added to a running container could be remounted read-write by root in the container.
The remaining issues affect availability: the PID file of an application container's DHCP helper is taken from the instance volume, a ZFS helper kept running in the daemon's mount namespace when it couldn't create its own, mount points containing escaped characters weren't recognized as mounted, AppArmor profile files weren't removed on hosts without AppArmor, and a failed probe for idmapped mount support was remembered for the life of the daemon.
Impact
A client restricted to a project with restricted=true, in the default configuration, can run code of its choice as root on the host by pushing a few files into a container or custom volume and listing a directory through the file API.
When the project sets restricted.containers.interception=allow, or an administrator enabled the matching security.syscalls.intercept.* options on a container, root inside that container can additionally:
- Take over the daemon's database connection and from there run commands as root on the host.
- Create device nodes at new paths on the host.
- Read parts of the daemon's memory, which can include other clients' requests and freshly issued trust tokens.
Root inside an unprivileged container can write to a disk that the administrator attached read-only, when that disk uses ID shifting and was attached while the container was running. Files written this way are owned by root on the underlying volume or host path and can be setuid.
Lastly, a restricted client or root in a container can degrade the host: terminate the DHCP helper of application containers in other projects, have every mount below the Incus directory detached on ZFS hosts, pile up mounts or leftover files, or make shifted disks unusable until the daemon is restarted.
Workarounds
There is no workaround for the file API issue short of blocking access to the file API and SFTP for untrusted clients, which project restrictions can't do.
Keep restricted.containers.interception at its default of block and don't set security.syscalls.intercept.mount or security.syscalls.intercept.mknod on containers running untrusted workloads.
Restart a container after adding a read-only shifted disk to it, as disks present at start time aren't affected.