Skip to content

Commit 61017ea

Browse files
committed
Secure Unix-domain sockets of "make check" temporary clusters.
Any OS user able to access the socket can connect as the bootstrap superuser and in turn execute arbitrary code as the OS user running the test. Protect against that by placing the socket in the temporary data directory, which has mode 0700 thanks to initdb. Back-patch to 8.4 (all supported versions). The hazard remains wherever the temporary cluster accepts TCP connections, notably on Windows. Attempts to run "make check" from a directory with a long name will now fail. An alternative not sharing that problem was to place the socket in a subdirectory of /tmp, but that is only secure if /tmp is sticky. The PG_REGRESS_SOCK_DIR environment variable is available as a workaround when testing from long directory paths. As a convenient side effect, this lets testing proceed smoothly in builds that override DEFAULT_PGSOCKET_DIR. Popular non-default values like /var/run/postgresql are often unwritable to the build user. Security: CVE-2014-0067
1 parent 733c2a4 commit 61017ea

File tree

2 files changed

+44
-22
lines changed

2 files changed

+44
-22
lines changed

doc/src/sgml/regress.sgml

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,14 @@ gmake check
5858

5959
<warning>
6060
<para>
61-
This test method starts a temporary server, which is configured to accept
62-
any connection originating on the local machine. Any local user can gain
63-
database superuser privileges when connecting to this server, and could
64-
in principle exploit all privileges of the operating-system user running
65-
the tests. Therefore, it is not recommended that you use <literal>gmake
66-
check</> on machines shared with untrusted users. Instead, run the tests
67-
after completing the installation, as described in the next section.
68-
</para>
69-
70-
<para>
71-
On Unix-like machines, this danger can be avoided if the temporary
72-
server's socket file is made inaccessible to other users, for example
73-
by running the tests in a protected chroot. On Windows, the temporary
74-
server opens a locally-accessible TCP socket, so filesystem protections
75-
cannot help.
61+
On systems lacking Unix-domain sockets, notably Windows, this test method
62+
starts a temporary server configured to accept any connection originating
63+
on the local machine. Any local user can gain database superuser
64+
privileges when connecting to this server, and could in principle exploit
65+
all privileges of the operating-system user running the tests. Therefore,
66+
it is not recommended that you use <literal>gmake check</> on an affected
67+
system shared with untrusted users. Instead, run the tests after
68+
completing the installation, as described in the next section.
7669
</para>
7770
</warning>
7871

@@ -111,6 +104,17 @@ gmake MAX_CONNECTIONS=10 check
111104
</screen>
112105
runs no more than ten tests concurrently.
113106
</para>
107+
108+
<para>
109+
To protect your operating system user account, the test driver places the
110+
server's socket in a relative subdirectory inaccessible to other users.
111+
Since most systems constrain the length of socket paths well
112+
below <literal>_POSIX_PATH_MAX</>, testing may fail to start from a
113+
directory with a long name. Work around this problem by pointing
114+
the <envar>PG_REGRESS_SOCK_DIR</> environment variable to a substitute
115+
socket directory having a shorter path. On a multi-user system, give that
116+
directory mode <literal>0700</>.
117+
</para>
114118
</sect2>
115119

116120
<sect2>

src/test/regress/pg_regress.c

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ static const char *progname;
109109
static char *logfilename;
110110
static FILE *logfile;
111111
static char *difffilename;
112+
static char *sockdir;
112113

113114
static _resultmap *resultmap = NULL;
114115

@@ -768,8 +769,7 @@ initialize_environment(void)
768769
* the wrong postmaster, or otherwise behave in nondefault ways. (Note
769770
* we also use psql's -X switch consistently, so that ~/.psqlrc files
770771
* won't mess things up.) Also, set PGPORT to the temp port, and set
771-
* or unset PGHOST depending on whether we are using TCP or Unix
772-
* sockets.
772+
* PGHOST depending on whether we are using TCP or Unix sockets.
773773
*/
774774
unsetenv("PGDATABASE");
775775
unsetenv("PGUSER");
@@ -781,7 +781,24 @@ initialize_environment(void)
781781
if (hostname != NULL)
782782
doputenv("PGHOST", hostname);
783783
else
784-
unsetenv("PGHOST");
784+
{
785+
sockdir = getenv("PG_REGRESS_SOCK_DIR");
786+
if (!sockdir)
787+
{
788+
/*
789+
* Since initdb creates the data directory with secure
790+
* permissions, we place the socket there. This ensures no
791+
* other OS user can open our socket to exploit our use of
792+
* trust authentication. Compared to using the compiled-in
793+
* DEFAULT_PGSOCKET_DIR, this also permits testing to work in
794+
* builds that relocate it to a directory not writable to the
795+
* build/test user.
796+
*/
797+
sockdir = malloc(strlen(temp_install) + sizeof("/data"));
798+
sprintf(sockdir, "%s/data", temp_install);
799+
}
800+
doputenv("PGHOST", sockdir);
801+
}
785802
unsetenv("PGHOSTADDR");
786803
if (port != -1)
787804
{
@@ -2253,10 +2270,11 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc
22532270
*/
22542271
header(_("starting postmaster"));
22552272
snprintf(buf, sizeof(buf),
2256-
SYSTEMQUOTE "\"%s/postgres\" -D \"%s/data\" -F%s -c \"listen_addresses=%s\" > \"%s/log/postmaster.log\" 2>&1" SYSTEMQUOTE,
2257-
bindir, temp_install,
2258-
debug ? " -d 5" : "",
2259-
hostname ? hostname : "",
2273+
SYSTEMQUOTE "\"%s/postgres\" -D \"%s/data\" -F%s "
2274+
"-c \"listen_addresses=%s\" -k \"%s\" "
2275+
"> \"%s/log/postmaster.log\" 2>&1" SYSTEMQUOTE,
2276+
bindir, temp_install, debug ? " -d 5" : "",
2277+
hostname ? hostname : "", sockdir ? sockdir : "",
22602278
outputdir);
22612279
postmaster_pid = spawn_process(buf);
22622280
if (postmaster_pid == INVALID_PID)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy