pgsql: Fix insecure parsing of server command-line switches. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Fix insecure parsing of server command-line switches.
Date
Msg-id E1UMj3k-0000ak-9w@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix insecure parsing of server command-line switches.

An oversight in commit e710b65c1c56ca7b91f662c63d37ff2e72862a94 allowed
database names beginning with "-" to be treated as though they were secure
command-line switches; and this switch processing occurs before client
authentication, so that even an unprivileged remote attacker could exploit
the bug, needing only connectivity to the postmaster's port.  Assorted
exploits for this are possible, some requiring a valid database login,
some not.  The worst known problem is that the "-r" switch can be invoked
to redirect the process's stderr output, so that subsequent error messages
will be appended to any file the server can write.  This can for example be
used to corrupt the server's configuration files, so that it will fail when
next restarted.  Complete destruction of database tables is also possible.

Fix by keeping the database name extracted from a startup packet fully
separate from command-line switches, as had already been done with the
user name field.

The Postgres project thanks Mitsumasa Kondo for discovering this bug,
Kyotaro Horiguchi for drafting the fix, and Noah Misch for recognizing
the full extent of the danger.

Security: CVE-2013-1899

Branch
------
REL9_0_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/3d21a0f3009ad0ba3236499e3851732352e35af6

Modified Files
--------------
src/backend/main/main.c             |    2 +-
src/backend/postmaster/postmaster.c |    9 +-----
src/backend/tcop/postgres.c         |   42 +++++++++++++++++-----------------
src/backend/utils/init/postinit.c   |    2 +-
src/include/tcop/tcopprot.h         |    7 +++--
5 files changed, 29 insertions(+), 33 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Fix insecure parsing of server command-line switches.
Next
From: Tom Lane
Date:
Subject: pgsql: Make REPLICATION privilege checks test current user not authenti