The vulnerability (CVE-2024-10978) concerns incorrect privilege assignment when PostgreSQL applications use SET ROLE or SET SESSION AUTHORIZATION. Queries reacting to current_setting('role') or the current user ID could then operate with incorrect privileges. The provided commit a5d2e6205 directly addresses these issues. The analysis focused on functions modified by this patch that are responsible for setting, managing, or initializing user IDs, roles, and session authorization contexts.
Key areas of change in the patch include:
miscinit.c: Functions like SetSessionAuthorization, SetCurrentRoleId, and InitializeSessionUserId were modified to correctly manage the session's user/role state and their interactions, particularly how they update underlying user ID variables and GUCs like is_superuser.
parallel.c: ParallelWorkerMain was updated to explicitly set all relevant user ID and role states at the beginning of worker initialization, ensuring parallel workers adopt the correct security context from the leader.
guc.c: set_config_option_ext was modified with a specific hack to enforce that SET SESSION AUTHORIZATION also implies SET ROLE NONE, addressing a fundamental issue in how these GUCs interacted.
variable.c: Check functions like check_session_authorization and check_role were updated to correctly handle states during parallel worker initialization and ensure proper privilege checks.
The identified functions are those whose flawed logic or interaction directly led to the incorrect privilege states described in the CVE. The patch rectifies these flaws by ensuring more robust state management and correct propagation of security contexts, especially across transaction boundaries and into parallel workers.