Package: postgresql-common
Version: 297
Severity: important
Tags: security
X-Debbugs-CC: [email protected]

Two root-run helpers follow symlinks that the postgres account places
in its own config directories. These were reported privately to the
Debian security team, with a reproducer. I am filing them publicly at
their request. Line numbers are from postgresql-common 297.

1. pg_conftool set. set_conffile_value (PgCommon.pm:358-369) opens
<config>.new, writes it, and runs chown and chmod on that path before
renaming it. The postgres account can create postgresql.conf.new as a
symlink to a root-only file. An administrator's "pg_conftool <version>
<cluster> set ..." then truncates that file, writes the config lines
into it, and changes its owner to postgres and its mode to 0644.
Source inspection shows the same pattern in disable_conffile_value
(PgCommon.pm:395-428), which remove uses. Only set was tested.

2. pg_upgradecluster --method=upgrade --keep-on-error with the old
cluster running. pg_upgradecluster stops the running old cluster
(529-534) and skips the restricted restart (536-550).
migrate_config_files (595) then copies postgresql.conf as root through
install_file (PgCommon.pm:1254-1260) into the new cluster, at mode
644. The postgres account can replace the old postgresql.conf with a
link to a root-only file. Root then copies that file into a
world-readable config. The upgrade then exits with status 1, and
--keep-on-error keeps the copy. pg_upgradecluster is one of the
scripts covered by CVE-2017-8806, whose fix (postgresql-common 188,
commit 8b4d0a88) did not change this source-side copy.

Tested on Debian 13 using the PGDG package postgresql-common
297.pgdg13+1, with root-only test files. Path 1 changed the test file
in 10 of 10 attempts. Path 2 copied it into a world-readable config in
10 of 10, and each run exited with status 1. In all three controls for
each path, the reported effect did not occur. Source inspection also
found the .new code in 278+deb13u1, 295 and 297, and the install_file
copy in 248+deb12u2.

The fix should not let root follow a postgres-owned symlink in the
.new write, its chown and chmod, or the install_file copy.

Reported by Hasnain Naeem and Ryan Henry (University of Calgary).

Reply via email to