Host file read and write through backups, images, storage volumes and migration
Description
Reported from Incus. This advisory was copied from the Incus advisory GHSA-42x8-664j-84w8.
Several code paths that move data in or out of storage volumes handled content controlled by the client as if it were trusted, while running as root on the host.
Instance backups, custom volume backups and image publishing walked the volume by host path, so a directory replaced by a symbolic link during the walk was followed. Custom volumes could be accessed through an endpoint meant for the other content type (file and SFTP access on a block volume, NBD access on a filesystem volume) or refreshed from a volume of the other content type, in each case leaving a disk image path under the client's control. The bucket backup export endpoint built a file path from the backup name without checking that the backup exists.
Image handling had similar issues. The fingerprint and the delta base name supplied by a remote image server were used as file names before being validated. A custom volume being imported, and an instance being rebuilt, renamed or created, could also be accessed or changed while its content was still being unpacked.
Finally, a migration target could request snapshots that the source never offered, with the names used as path components on the source, and a number of small files taken from images and backups were read without a size limit.
Impact
A client with access to a single project, including a project with restricted=true, can read arbitrary files of the host as root and, through the unpack related issues, write arbitrary files as root. Both lead to a full compromise of the host and of every instance on it.
Some of the issues need nothing more than the ability to create a custom volume or a storage bucket. Others need the client to win a race against an unpack, which it can retry at will, or to have the server pull from an image server or migrate to a peer that the client controls.
Oversized metadata files in an image or backup can additionally be used to exhaust the memory of the daemon.
Workarounds
There is no complete workaround. Only giving access to fully trusted users avoids the issues. Setting restricted.devices.disk=block, restricted.backups=block and removing access to storage buckets and custom volumes from untrusted projects reduces the exposure but doesn't cover the image related issues.