Package: postgresql-common Version: 297 Severity: important Tags: security X-Debbugs-CC: [email protected]
pg_createcluster follows a symlink that the postgres account places in a data directory. When an administrator adopts an existing data directory with pg_createcluster, root copies the link's target into a new, world-readable postgresql.conf and then deletes the target. This was reported privately to the Debian security team, with a reproducer. I am filing it publicly at their request. Details (line numbers from postgresql-common 297): pg_createcluster takes its adoption branch (pg_createcluster:353-375) when PG_VERSION exists. There, move_conffile (pg_createcluster:93-109, called at 384-389) resolves the symlink. It installs the resolved file through install_file (PgCommon.pm:1254-1260) as postgres:postgres 644, then unlinks both the link and the resolved target. The postgres account owns the data directory, so it can replace postgresql.conf with a link to a root-only file. This is related to CVE-2017-8806. Its fix (postgresql-common 188, commit 8b4d0a88, "Replace chown by lchown where applicable") changed the destination ownership calls, but not this source-side handling. Tested on Debian 13 using the PGDG package postgresql-common 297.pgdg13+1, with a root-only test file. In 10 of 10 attempts, the new config was postgres:postgres 644, contained the test file's marker, and was readable by an unprivileged user, and the test file was deleted. In all three controls with a regular postgresql.conf, the test file stayed unchanged, and its marker did not appear in the new config. Source inspection also found the same code in 248+deb12u2, 278+deb13u1, 295 and 297. The fix should not let root copy or delete the target of a postgres-owned symlink. Reported by Hasnain Naeem and Ryan Henry (University of Calgary).

