Pi-hole gravity.sh chowns arbitrary directories to pihole as root
Key facts
- Attack vector
- Local
- Privileges required
- Low
- User interaction
- Required
- Attack complexity
- Low
- Impact type
- Privilege escalation
- Confidentiality · integrity · availability
- High · High · High
- Fix status
- Fixed
Attack profile from CVSS 3.1 · GHSA-mff6-cjc4-5wq9. Fix status from GitHub. Impact type from CWE-250.
Summary
Pi-hole up to and including 6.4.3 is affected. The gravity.sh script runs as root and trusts the database path set in files.gravity, a setting the unprivileged pihole account can write, so it changes the owner of an arbitrary parent directory (CWE-73). A local attacker with code execution as the pihole account can gain root code execution when an administrator runs sudo pihole -g.
Written with Claude Haiku 5.5 from the sources below · 2026-11-12
Description from the GitHub advisory
### Summary Local privilege escalation from the unprivileged `pihole` service account to full root code execution. `gravity.sh` — executed as root whenever an administrator runs the standard, documented maintenance command `sudo pihole -g` — reads the gravity database path from the `files.gravity` setting in `/etc/pihole/pihole.toml`, a file owned by the unprivileged `pihole` user (the installer and the FTL pre-start script both recursively `chown -R pihole:pihole /etc/pihole`). Without validating the location, the script's `fix_owner_permissions()` runs `chown pihole:pihole "$(dirname -- "$1")"` on the database's parent directory. Pointing `files.gravity` at `/etc/cron.d/gravity.db` (or `/etc/sudoers.d/`, `/root/`, ...) makes the next routine root gravity run hand ownership of that system directory to the `pihole` user, who then drops a root cron job (or sudoers rule) and gains root code execution. The starting point of this attack — code execution as the `pihole` service account — is the same trust-boundary starting point the project already accepted and fixed as High severity in GHSA-6w8x-p785-6pm4 and GHSA-h8w9-qx2v-wrww. ### Details `files.gravity` is a legitimate, documented configuration option (relocate the gravity database). Because `/etc/pihole/` — including `pihole.toml` — is owned by the `pihole` user in every default install, anyone with code execution as `pihole` (e.g. via the web admin API / any FTL compromise) can set it to an arbitrary path: GRAVITYDB=$(getFTLConfigValue files.gravity) # gravity.sh:42 — value from pihole-owned /etc/pihole/pihole.toml Later, with root privileges, the script derives the database directory from this value and repeatedly changes its ownership: fix_owner_permissions() { ... chown pihole:pihole "${1}" chmod 664 "${1}" # Ensure the containing directory is owned by pihole:pihole ... chown pihole:pihole "$(dirname -- "${1}")" # gravity.sh:77 — chowns ANY parent directory to pihole } The function is invoked on the gravity temp file at gravity.sh:1213 on every gravity run, and additionally from `generate_gravity_database()` (gravity.sh:86) when the database does not exist yet. `gravity_swap_databases()` further creates and chowns a `gravity_backups` subdirectory (gravity.sh:148) and moves/copies database files inside the attacker-chosen directory, all as root. Attack chain (verified end-to-end against the repository script): 1. Attacker (as `pihole`) sets `files.gravity = "/etc/cron.d/gravity.db"` in `/etc/pihole/pihole.toml`. 2. An administrator performs a routine `sudo pihole -g` — the action the official documentation prescribes after changing adlists, and which the `pihole` CLI itself suggests (`try: sudo pihole -g`). The `-g`/`updateGravity` command is flagged `need_root` (pihole:562) and execs `gravity.sh` as root. 3. `gravity.sh` completes successfully and `/etc/cron.d` is now owned by `pihole:pihole` (also true for `/etc/sudoers.d`, `/root`, or any other chosen directory). 4. The attacker writes `* * * * * root <payload>` into `/etc/cron.d/` and the system cron daemon — a hard dependency of Pi-hole — executes it as root. Honest scoping of the trigger: there is no automatic root invocation of gravity — the shipped weekly gravity cron entry runs as the `pihole` user, not root — so exploitation requires one routine administrator `sudo pihole -g` run. This is reflected in the CVSS vector (UI:R) and is not an unusual action: it is the single most common Pi-hole maintenance command, explicitly instructed by the documentation after every adlist change. Source code pointers (pinned to the audited commit, which is current master HEAD / v6.4.3): - Config read — database path taken from pihole-owned configuration: https://github.com/pi-hole/pi-hole/blob/f47b8ede5a8e38f9c703202d324a074dbdba4ca9/gravity.sh#L42 - Sink — `fix_owner_permissions()` chowns the file's parent directory to `pihole`: https://github.com/pi-hole/pi-hole/blob/f47b8ede5a8e38f9c703202d324a074dbdba4ca9/gravity.sh#L67-L78 - Invocation on the gravity temp file during every run: https://github.com/pi-hole/pi-hole/blob/f47b8ede5a8e38f9c703202d324a074dbdba4ca9/gravity.sh#L1213 - Root also creates/chowns `gravity_backups` inside the attacker-chosen directory: https://github.com/pi-hole/pi-hole/blob/f47b8ede5a8e38f9c703202d324a074dbdba4ca9/gravity.sh#L148 - `-g`/`updateGravity` requires root and execs `gravity.sh`: https://github.com/pi-hole/pi-hole/blob/f47b8ede5a8e38f9c703202d324a074dbdba4ca9/pihole#L562 - Why `pihole` controls the config: installer recursively chowns `/etc/pihole` to the pihole user: https://github.com/pi-hole/pi-hole/blob/f47b8ede5a8e38f9c703202d324a074dbdba4ca9/automated%20install/basic-install.sh#L1250 and the FTL pre-start script repeats it: https://github.com/pi-hole/pi-hole/blob/f47b8ede5a8e38f9c703202d324a074dbdba4ca9/advanced/Templates/pihole-FTL-prestart.sh#L5 - Honest trigger note — the weekly gravity cron runs as `pihole`, not root (no automatic trigger): https://github.com/pi-hole/pi-hole/blob/f47b8ede5a8e38f9c703202d324a074dbdba4ca9/advanced/Templates/pihole.cron#L21 Relation to previous advisories: GHSA-6w8x-p785-6pm4 covered a config-controlled path (`files.pid`) consumed by root-executed systemd pre/post hooks, and was fixed by hardcoding that path (the hardening comment is visible in the pre-start script). The mechanism here is different and unfixed: a different config key (`files.gravity`), a different root-side consumer (the routinely executed `gravity.sh`), and a different primitive (recursive directory `chown` to pihole, then cron/sudoers escalation). No path validation comparable to the GHSA-6w8x fix exists for `files.gravity` in the audited code. ### PoC On any default Pi-hole v6 installation (the sandbox harness below reproduces the identical permission facts: `/etc/pihole` owned by `pihole`, repository scripts under `/opt/pihole`, a real `pihole` system user): 1. As the `pihole` user, point the gravity database into a root-owned system directory: pihole$ echo 'files.gravity = "/etc/cron.d/gravity.db"' >> /etc/pihole/pihole.toml (equivalently via the web admin API / settings UI, which legitimately exposes this config key) 2. Wait for, or socially engineer, a routine admin gravity update: root$ sudo pihole -g # completes with "[✓] Done." 3. Observe the directory takeover: $ ls -ld /etc/cron.d drwxr-xr-x 3 pihole pihole 4096 ... /etc/cron.d $ ls -la /etc/cron.d/ -rw-r--r-- 1 pihole pihole 106496 ... gravity.db drwxr-xr-x 2 pihole pihole 4096 ... gravity_backups -rw-r--r-- 1 pihole pihole 94208 ... gravity_old.db 4. Escalate — as the `pihole` user, write a root cron job into the captured directory: pihole$ printf '* * * * * root id > /tmp/gravity-privesc-proof.txt\n' > /etc/cron.d/zz-pihole-escalation On a real host the system cron daemon (a Pi-hole hard dependency) executes the payload as root within a minute. Choosing `/etc/sudoers.d` as the target directory instead yields an immediate root shell. A self-contained sandbox harness (full source in the PoC comment) rebuilds the exact production permission layout — creates the `pihole` user, chowns `/etc/pihole` to it, deploys the repository's `gravity.sh`/`utils.sh` verbatim, builds the gravity database with real `sqlite3` from the repository's own `advanced/Templates/gravity.db.sql`, and stubs only `pihole-FTL` (config queries + sqlite3 passthrough; the vulnerable code path does not depend on FTL internals). It then runs the attack as the `pihole` user, executes `gravity.sh` as root (standing in for `sudo pihole -g`), prints the `/etc/cron.d` ownership flip `root:root → pihole:pihole`, and demonstrates the attacker writing the root cron payload. `sudo bash poc.sh cleanup` restores the machine. ### Impact Local privilege escalation: an attacker who has compromised the unprivileged `pihole` service account obtains full root code execution after a single routine administrator gravity update. The `pihole` → root boundary is a deliberate Pi-hole v6 design boundary (FTL and scripts were de-privileged to run as `pihole`) and the project has twice treated its violation as High severity (GHSA-6w8x-p785-6pm4, GHSA-h8w9-qx2v-wrww, both fixed in 2026). Beyond the directory takeover itself, root also creates/moves files (`gravity.db`, `gravity_old.db`, `gravity_backups/`) inside an attacker-chosen directory, further polluting system locations. All deployments with default file ownership are affected; the trigger is the most common Pi-hole maintenance operation. Suggested remediation: - Validate `files.gravity` (and `files.gravity_tmp`) after reading it: resolve with `realpath -m` and require an allowlisted prefix such as `/etc/pihole/`; refuse or fall back to the default with a loud warning otherwise. Enforcing the same constraint in FTL's config-validation layer prevents local `pihole.toml` edits from bypassing it, but the script-side check is the decisive line of defense. - `fix_owner_permissions()` should not chown the containing directory at all; if ownership repair is genuinely needed, only do it when the directory already belongs to `pihole`, and never follow symlinks (`chown -h` / `realpath` pre-check), mirroring the GHSA-6w8x hardening approach. --- ### Also affected: `pihole flush` The manual `sudo pihole flush` has the same problem with the `files.log.*` paths. `piholeLogFlush.sh` runs `echo " " > "${logfile}"` and `chmod 640` on them as root, so pointing e.g. `files.log.webserver` at a root-owned file truncates it and changes its mode. The fix runs gravity as `pihole` even when started as root, and writes the log files as `pihole` during a flush.
Why it matters now
SSVC decision points
Not available: CISA has not published SSVC decision points for this record.
Affected products
| Vendor | Product | Affected versions | Fixed in | Status | Source |
|---|---|---|---|---|---|
| — | pi-hole | <= 6.4.3 | 6.5 | Patch available | GHSA-mff6-cjc4-5wq9 |
- pi-hole Vendor— Affected <= 6.4.3 Fixed in 6.5 Patch available GHSA-mff6-cjc4-5wq9
Remediation
Update pi-hole to version 6.5, which is the listed fixed version.
Written with Claude Haiku 5.5 from the sources below · 2026-11-12
- Fix · GHSA-mff6-cjc4-5wq9 pi-hole Fixed in 6.5 Advisory →
Timeline
- 2026-11-12 Threatist record created from GHSA-mff6-cjc4-5wq9
References
Sources
This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences