Summary
A path traversal vulnerability in LXD instance template processing allows attackers to overwrite arbitrary files on the host with root privileges. The issue becomes critical when a user can edit container metadata or launch a crafted image containing malicious template paths.
Affected context
The vulnerability occurs in LXD deployments that process instance template paths supplied through image metadata.yaml files. It is relevant when an attacker can edit an instance or provide a crafted image and the template processing logic validates paths using a confined directory handle but later creates files through an unconfined string path.
Exploit preconditions
- Attack surface: LXD instance template processing during instance creation or configuration - Required access: Container edit permissions or the ability to launch a crafted image - Trigger point: Processing of attacker-controlled target template paths from metadata.yaml - Why exploitation is possible: Path validation and file creation use different path-resolution mechanisms, allowing a path that passes confinement checks to escape the intended directory when opened
Why this happens
The underlying bug is inconsistent path handling across security-sensitive operations. LXD validates a template path relative to a confined os.Root directory handle, but subsequently passes an unconfined string path to os.Create. This check-use mismatch can bypass directory confinement and maps primarily to CWE-22, Improper Limitation of a Pathname to a Restricted Directory, with characteristics of CWE-23, Relative Path Traversal.
Potential impact
- An attacker may overwrite root-owned host files.
- Host services could be altered or disrupted.
- The attacker could achieve code execution with host root privileges.
- LXD-managed workloads and other tenants could be compromised.
- System integrity, availability, and confidentiality could be affected.
General mitigation guidance
Mitigation generally focuses on maintaining a single trusted path-resolution model from validation through file creation. Secure-by-default designs should resolve and open paths through the same confined directory abstraction, reject absolute and traversal-based paths, and constrain templates to an explicit allowlisted destination. Input trust should be reduced by treating image metadata and instance configuration as untrusted, while file creation should use least-privilege service identities, restrictive permissions, and host isolation controls where practical.
How teams detect issues like this
Detection can include static analysis for validation performed with one path API followed by file access through a separate unconfined string API. Code review should flag path joins, normalization checks, and file creation that do not share the same confinement mechanism. Runtime monitoring can alert on LXD processes creating or modifying sensitive host paths, and policy enforcement can restrict template destinations and image metadata sources. Automated security review tools may help identify traversal and check-use inconsistencies.

