Restricted projects can reach host files and host root through disk devices and virtual machine disks
Description
Reported from Incus. This advisory was copied from the Incus advisory GHSA-4375-qwr5-8vjj.
Disk devices and virtual machine disks offered several ways for a user confined to a project to get at the host.
The path of a disk, unix or TPM device inside a container was accepted with .. components. That path is resolved against the host before the container's root filesystem is entered, so the device ended up mounted outside of the container.
For virtual machines, the format of a disk was guessed from the content of the disk when publishing an instance or exposing it over NBD, and a QCOW2 root disk in an image could refer to a backing file or an external data file. In both cases the QEMU tools, running as root, opened a host path named by the disk content. A directory shared with a virtual machine from a restricted source path was only protected from the guest's root user while raw.idmap was set, which the user can unset. A custom volume named like an external Ceph source was treated as one when attached with a pool, and the name of the UEFI variables file was taken from a link inside the instance volume.
For containers, a project using restricted.idmap.uid and restricted.idmap.gid, as created by incus-user, accepted a raw.idmap entry mapping the user's own host ID onto the container's root user.
Impact
A client restricted to a project with restricted=true, including an unprivileged local user going through incus-user, can:
- mount host directories into a container and write to host files as root;
- read arbitrary host files, or any RBD image reachable with the host's Ceph credentials, by having them copied or attached to a virtual machine it controls;
- create setuid root files in a host directory shared with a virtual machine;
- become the owner of an instance's files on the host, and place files with a name of its choice in the virtual machine's runtime directory.
Each of these leads to root on the host, or to the content of files and disks that the project was never given access to.
Workarounds
Setting restricted.devices.disk=block, restricted.devices.unix-char=block, restricted.devices.unix-block=block and restricted.virtual-machines.lowlevel=block (the default), together with restricted.devices.disk.paths left empty and no restricted.idmap.* ranges, removes most of the device related vectors. TPM devices can't be blocked by a project restriction, and virtual machine images supplied by the user remain a vector unless virtual machines are denied with limits.virtual-machines=0.