pi-hole/advanced
Adam Warner e05dc3f139
fix: never run updatecheck.sh as root
updatecheck.sh writes the versions file into /etc/pihole, which is owned
by the unprivileged pihole user. When it ran as root (the installer,
`pihole -up`, `pihole checkout`, `sudo pihole updatechecker`, the Docker
start-up check, ...) the pihole user could watch the directory, swap the
script's temporary file for a symlink and have root chmod/chown/append
to whatever it pointed at. Reproduced: a root-only file ended up owned by
pihole.

- When started as root, hand over to the pihole user (`su`) and exit
  with its result. This covers every caller, including future ones, and
  the pihole user can only damage what it already owns. The "reboot"
  argument is forwarded.
- Drop the chown of the temporary file; it is no longer needed and was
  the dangerous part.
- Use `mv -fT` so that a symlink to a directory at the target path is
  replaced rather than having the temporary file moved into the
  directory.

Tests (fresh install): started as root the script must do its work as
the pihole user and write a pihole-owned 0644 versions file; a symlink
(to a file or to a directory) at the target path must be replaced rather
than followed.

Note: running as the pihole user needs git to trust the root-owned Core
and Web repositories (safe.directory). The installer sets that up (see
the following commit); other installers of this script, such as the
Docker image, need the equivalent.

Reported-by: Keith Linneman (LinnemanLabs)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
2026-10-15 19:48:02 +01:00
..
bash-completion add missing local variable 2025-10-15 04:37:19 +02:00
Scripts fix: never run updatecheck.sh as root 2026-10-15 19:48:02 +01:00
Templates fix: run the permission fix-up in prestart as the pihole user 2026-10-15 19:48:02 +01:00