Summary
A path traversal vulnerability in LXD allows crafted image archives to cause template paths to escape the intended instance templates directory. In affected virtual machine and QEMU execution paths, an attacker may read arbitrary host files or create files at unintended host locations when malicious image metadata is processed.
Affected context
The issue can arise in LXD deployments that process image metadata templates for virtual machine instances using the QEMU driver. It requires a crafted image archive containing template directives whose paths are not sufficiently constrained to the designated instance templates directory.
Exploit preconditions
- Attack surface: LXD image import or processing of image metadata templates
- Required access: Ability to provide or cause LXD to process a crafted image archive
- Trigger point: Template handling during virtual machine or QEMU instance execution
- Why exploitation is possible: Template paths containing traversal elements can escape the intended directory when canonicalization and boundary enforcement are incomplete
Why this happens
The underlying bug is improper validation and containment of file paths derived from image metadata. When path components are accepted without reliably resolving and verifying that the resulting path remains beneath the permitted templates directory, attacker-controlled input can redirect file operations elsewhere on the host. This behavior maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Potential impact
- An attacker may read sensitive host files
- An attacker could create or overwrite files outside the intended templates directory
- Host configuration or runtime integrity may be affected
- Instance isolation could be weakened
- File creation may support persistence, denial of service, or follow-on compromise depending on host permissions
General mitigation guidance
Mitigation generally focuses on enforcing a strict filesystem boundary for all template-derived paths.
Common defensive patterns include:
- Resolve candidate paths before use and verify they remain beneath the permitted directory
- Reject absolute paths, traversal components, unexpected separators, and symbolic-link escapes
- Use secure-by-default file APIs that operate relative to a trusted directory where available
- Treat image archives and metadata as untrusted input until validation is complete
- Apply strict archive-entry validation and allowlist expected template locations
- Run LXD and related virtualization processes with the minimum host privileges required
- Use filesystem permissions and isolation controls to limit the consequences of unintended file access
How teams detect issues like this
Detection approaches may include:
- Static analysis rules for path construction using archive or image metadata
- Code review checks for missing canonicalization and directory-boundary validation
- Tests covering relative paths, absolute paths, encoded traversal, symbolic links, and platform-specific separators
- Runtime auditing of LXD file access outside approved instance template directories
- Policy enforcement that restricts accepted archive entries and template locations
- Automated security review tools that flag untrusted input reaching filesystem APIs

