pi-hole/advanced/Scripts
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
..
database_migration Rename views, upgrade gravity database and bump gravity databae version 2025-08-15 19:39:21 +02:00
api.sh Revert "pihole api - use keepalive for curl queries" 2025-07-26 12:35:02 +01:00
COL_TABLE Set color codes when FORCE_COLOR is true 2025-06-24 19:03:24 +02:00
list.sh Remove readonly from list.sh to avoid errors 2025-07-14 21:20:39 -03:00
piholeCheckout.sh Prevent exiting due to set -e 2026-03-22 10:01:11 +01:00
piholeDebug.sh Use /etc/logrotate.d/pihole for logrotate file instead of /etc/pihole/logrotate 2026-05-13 08:38:31 +02:00
piholeLogFlush.sh Stop double-rotating logs now that pihole is in /etc/logrotate.d 2026-07-07 13:40:38 +01:00
piholeNetworkFlush.sh Remove readonly from piholeNetworkFlush.sh to avoid error message 2026-03-01 17:29:19 -03:00
query.sh Update advanced/Scripts/query.sh 2025-07-12 22:25:22 +00:00
update.sh update: abort if FTL branch does not exist 2025-07-10 21:37:28 +02:00
updatecheck.sh fix: never run updatecheck.sh as root 2026-10-15 19:48:02 +01:00
utils.sh We can also hardcode the PID file location in utils.sh 2026-04-25 10:51:55 +01:00
version.sh Set versions in /etc/pihole/versions to null if script fails 2026-04-17 17:13:01 +02:00