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>
- updatecheck.sh: reword the publish comment to refer to mv/rename(2) and
place it directly above the mv call; use chmod 0644
- pihole-FTL-prestart.sh: replace the loop/rm/no-op redirect with a single
documented su call using touch and chmod
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
The `pihole updatechecker` cron job and pihole-FTL-prestart.sh both ran as
root and created/truncated/chmod-ed /etc/pihole/versions on a fixed path
without O_NOFOLLOW. Since the pihole user owns /etc/pihole, a compromised
pihole account could replace `versions` with a symlink to any root-owned
file and have root truncate it, relax its mode, or create it. The chmod
step also allows exposing e.g. /etc/shadow. See GHSA-xch2-4qxw-g5vj.
- pihole.cron: run `updatechecker` as the pihole user (like updateGravity),
so root no longer writes into /etc/pihole from cron.
- updatecheck.sh: build the file in a mktemp'd temp file and rename() it
into place; a symlink at the target is replaced, not followed.
- pihole-FTL-prestart.sh: create/permission `versions` (and, same bug
class, `dhcp.leases`) as the pihole user via `su`, neutralising any
planted symlink. A symlink to a root-owned file then only yields EPERM.
- basic-install.sh / uninstall.sh: register the root-owned Core and Web
repos in git's system-wide safe.directory list so the now-unprivileged
updatechecker can still read local versions.
Behaviour change: /etc/pihole/versions is now consistently mode 0644 after
a service (re)start; the find in prestart previously left it 0640, against
the file's own comment and updatecheck.sh's own chmod 644.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
readonly ADMIN_INTERFACE_DIR=$(getFTLConfigValue "webserver.paths.webroot")$(getFTLConfigValue "webserver.paths.webhome")
^-----------------^ SC2155 (warning): Declare and assign separately to avoid masking return values.
In ./advanced/Scripts/update.sh line 39:
readonly ADMIN_INTERFACE_DIR=$(getFTLConfigValue "webserver.paths.webroot")$(getFTLConfigValue "webserver.paths.webhome")
^-----------------^ SC2155 (warning): Declare and assign separately to avoid masking return values.
In ./advanced/Scripts/updatecheck.sh line 45:
readonly ADMIN_INTERFACE_DIR=$(getFTLConfigValue "webserver.paths.webroot")$(getFTLConfigValue "webserver.paths.webhome")
^-----------------^ SC2155 (warning): Declare and assign separately to avoid masking return values.
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
We could revist this again in future if we decide that there should still be a choice to install the interface or not
Signed-off-by: Adam Warner <me@adamwarner.co.uk>