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>
Our config moved into /etc/logrotate.d/pihole a while back, so the
system's own scheduled logrotate now picks it up too. Our nightly and
@reboot forced runs were still using a private state file though, so
the system's run and ours each rotated the same logs independently,
unaware of each other.
Drop the private state file and use logrotate's default one instead,
so both sides agree on what's already been rotated. Also clean up the
now-stale /etc/pihole/logrotate and private state file left behind by
older installs.
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
The pihole-FTL-prestart.sh and pihole-FTL-poststop.sh scripts are
executed as root by systemd (via the '+' prefix). Both previously read
the PID file path from pihole.toml via getFTLConfigValue — a file the
pihole user can write to directly. An attacker with pihole-user access
could set files.pid to an arbitrary path and trigger a service restart
to cause root to delete then recreate any file on the system, enabling
local privilege escalation.
Fix by inlining the hardcoded path /run/pihole-FTL.pid directly in
each hook, removing any dependency on user-controlled config. The same
hardening is applied to the SysV init script for consistency.
See: GHSA-6w8x-p785-6pm4
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This was most likely added accidentally (during a refactor in 2017)
Both the 2017 and current version use /opt/pihole/COL_TABLE, as defined earlier and sourced earlier in the code.
Remove PIHOLE_COLTABLE_FILE from REQUIRED_FILES since /usr/local/bin as well as /opt/pihole are never checked
Signed-off-by: darkexplosiveqwx <101737077+darkexplosiveqwx@users.noreply.github.com>
- use `--no---` and `--yes---` to make sure the strings won't match user
comments or parts of domains
- also use `-ALLOW-` and `-BLOCK-`
Also reduce the domain column to 90 characters
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
- Domains table ("type" column): replace 0, 1, 2 and 3 with
"exact-allow", "exact-deny", "regex-allow" and "regex-deny"
- All tables: use yes/no for "enabled" columns
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
Use bash-internal globs and parameter expasion in preference to
assignment from output of ls or basename per file/directory.
When displaying file contents, call sed once and preprocesses the entire
file (eg pihole.toml), rather than spawning a new sed process for every
line of the file.
When checking services, call awk once to extract all data for each ip:port
pair, rather than three times.
Signed-off-by: Rob Gill <rrobgill@protonmail.com>
Adds the keepalive header to all curl requests
This reduces session establishment time across the multiple
requests necessary to authenticate, obtain response and log out
Signed-off-by: Rob Gill <rrobgill@protonmail.com>
This PR updates the function flushing the network tables and the ARP table. It separates the two, renaming the whole function to networkflush and makes flushing ARP optional by appending --arp. Deletion of the network table is now done via FTL's /action/flush/arp endpoint.
Documentation: https://github.com/pi-hole/docs/pull/1253
Related PR in the FTL repo: https://github.com/pi-hole/FTL/pull/2541