Skip to content

Commit 00b94e8

Browse files
committed
Parallel workers use AuthenticatedUserId for connection privilege checks.
Commit 5a2fed9 had an unexpected side-effect: the parallel worker launched for the new test case would fail if it couldn't use a superuser-reserved connection slot. The reason that test failed while all our pre-existing ones worked is that the connection privilege tests in InitPostgres had been based on the superuserness of the leader's AuthenticatedUserId, but after the rearrangements of 5a2fed9 we were testing the superuserness of CurrentUserId, which the new test case deliberately made to be a non-superuser. This all seems very accidental and probably not the behavior we really want, but a security patch is no time to be redesigning things. Pending some discussion about desirable semantics, hack it so that InitPostgres continues to pay attention to the superuserness of AuthenticatedUserId when starting a parallel worker. Nathan Bossart and Tom Lane, per buildfarm member sawshark. Security: CVE-2024-10978
1 parent 256e346 commit 00b94e8

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/backend/utils/init/postinit.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "access/genam.h"
2323
#include "access/heapam.h"
2424
#include "access/htup_details.h"
25+
#include "access/parallel.h"
2526
#include "access/session.h"
2627
#include "access/sysattr.h"
2728
#include "access/tableam.h"
@@ -772,7 +773,23 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
772773
else
773774
{
774775
InitializeSessionUserId(username, useroid);
775-
am_superuser = superuser();
776+
777+
/*
778+
* In a parallel worker, set am_superuser based on the
779+
* authenticated user ID, not the current role. This is pretty
780+
* dubious but it matches our historical behavior. Note that this
781+
* value of am_superuser is used only for connection-privilege
782+
* checks here and in CheckMyDatabase (we won't reach
783+
* process_startup_options in a background worker).
784+
*
785+
* In other cases, there's been no opportunity for the current
786+
* role to diverge from the authenticated user ID yet, so we can
787+
* just rely on superuser() and avoid an extra catalog lookup.
788+
*/
789+
if (InitializingParallelWorker)
790+
am_superuser = superuser_arg(GetAuthenticatedUserId());
791+
else
792+
am_superuser = superuser();
776793
}
777794
}
778795
else

0 commit comments

Comments
 (0)