Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wgjHb-006MP5-2q for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jul 2026 13:22:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wgjHa-000Rlb-26 for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Jul 2026 13:22:46 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wgjHa-000RlT-0Q for pgsql-hackers@lists.postgresql.org; Mon, 06 Jul 2026 13:22:46 +0000 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wgjHX-00000001qmV-2TYv for pgsql-hackers@lists.postgresql.org; Mon, 06 Jul 2026 13:22:45 +0000 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-493b966dd74so10096255e9.3 for ; Mon, 06 Jul 2026 06:22:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783344162; x=1783948962; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=G5VPRaMcW/Uix4ioxMttx4FDSuXlVE6RXMLiFavtRw0=; b=rtOtVKsTI3b9uo7BnFZfg7NOAvGu28QH11nUhgeAPm5KzHs+dr4ZP00JvSYYdhdfsg 0AgjAhrxnOeylxn9cB1efwri00PAbw6xSG2IrqBZNXuHPwt/bDgzbW9zXhP/fhCA7mTw M3BI+v4tSigRzA8BLfFd+65FDmdRaQ5sCKUnpdECQjdgjXA1wmbdWLIxbqSwHdXhbGDA 8yV3cjM3vePAIJHK7zd8mcMpivE+dGjWtfu5Lkj3IHZywqpDfW43XG5AXzOyijcX7FyZ +PNXSf8O48yUT4cq0uby59Z0Zsvf+kCRuLv7+Zq1lnSzA608sJuCw1WsQs3Y8i+hoyGm 1YDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783344162; x=1783948962; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G5VPRaMcW/Uix4ioxMttx4FDSuXlVE6RXMLiFavtRw0=; b=L0oedqPNBpW0ge2HN7lWK9e9oF6bKQNn3xEhlNtDSh7R+k/0jZ82gULtgd/e58tqoC LNluJeiIaQRPkAkkqhH3csQaYdhwi7UHlbITXovW4LRd+M+9jgiKuHTjYygZ3ccTx0Fa jzUbhl+C8bmLtYXAB9YCRGzNAhGqjgvtRFCjUTaKxDNOHy6V6zL2pUWJzVPv2JvmkPkZ 9PINmUeRRnPzjk5FhhYSf9PqREiDbglC+dTh8bkipeW6YKsqgcL+m+RIEwiO2q0rWdEn 8Z4v7a1Uo1fijcKXLJSDuSY2012cAn/W9Mkm7TNGwlOxz1abJWA4Mq+XgjEjlzuaS+6A Bj1Q== X-Gm-Message-State: AOJu0Yyw+SGvNL1Lt2K02fPGT1gIvli0q6RzpnRwWKzyipuXrJJMsM6X Yw9nxki8UP+Nhq/BFSi+QZgBUNIE3Q85Gb96XmJJ0zWIkWeqCElnjVCtes7tuQ== X-Gm-Gg: AfdE7ckTNEjk4ivwXK770twwJtUsbsln8wf4t492UZaaKMx+Us0lB6Ms5on1ALo88te ttRDoLXulZBGrz4CKiXiVuMZNJgx0S9Fw0NYAtP/cvwDoLrBYhSyA4J7+jj0fVRLxuKjcQX+1Th 4XNxISS9DqOhXA8wJK0c1mi+y3uwT9++63d4fUxCnNoya8q8iY/YGf9SYN/xfyZDemM6bGPgbzp qmkdJcQn/S68KYxMAjMtXt0kIfydy/gmx6GHjXYo8bDVIV6O6vspdkpSAoOjH2uYDLzzVzOgo96 heG7Ht0QZ08FveUg8j9Y8Ped3Gw+fZpZNajgx0qwnb9Bmi+3A+0Btp2ziBTSphlu6oXpUeXw9Zf K4KeTMlemX53Omizep1eWxUPuV6qNMgQ8oow50iFUmh8h+IMku/sI5g336wT1b3NKC9OIiT7/US TbvBl4JiXpjwyQ89wmVqBiiki2KfYX9pdmMGFPR3ekP3ZiHQptCR3j2RFS8gNulUQ9ZgUjf4h4 X-Received: by 2002:a05:600c:c16e:b0:490:bd66:e523 with SMTP id 5b1f17b1804b1-493df06e90amr5028825e9.20.1783344161700; Mon, 06 Jul 2026 06:22:41 -0700 (PDT) Received: from bdtpg (ec2-15-237-197-144.eu-west-3.compute.amazonaws.com. [15.237.197.144]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493c637bbcfsm346826285e9.6.2026.07.06.06.22.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2026 06:22:41 -0700 (PDT) Date: Mon, 6 Jul 2026 13:22:39 +0000 From: Bertrand Drouvot To: pgsql-hackers@lists.postgresql.org Cc: Tom Lane Subject: Re: Fix races conditions in DropRole() and GrantRole() Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="cOHldBwZEf1OqVbN" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --cOHldBwZEf1OqVbN Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, On Sat, Jul 04, 2026 at 07:47:08AM +0000, Bertrand Drouvot wrote: > The patch attached fixes the races by using the same approach as > RangeVarGetRelidExtended(): It encapsulates name resolution, permission checking > (via a caller-supplied callback), and lock acquisition inside a retry loop driven > by SharedInvalidMessageCounter. If invalidation messages arrive between name > resolution and locking, indicating concurrent DDL, the function retries. Also I think we could make use of the same approach to fix one of the issue that was discussed in [1], means: " create role my_group; create role dropped_member; Session 1: begin;grant my_group to dropped_member; Session 2: drop role dropped_member; Session 1: commit; " producing an orphaned pg_auth_members entry: postgres=# SELECT m.member, m.roleid, r.rolname FROM pg_auth_members m LEFT JOIN pg_roles r ON m.member = r.oid WHERE r.oid IS NULL; member | roleid | rolname --------+--------+--------- 16385 | 16384 | (1 row) 0002 fixes this by acquiring AccessShareLock on each resolved role within roleSpecsToIds(), ensuring the role cannot be dropped while any caller is using its OID. It also fixes other cases that would produce orphaned pg_auth_members entries, like "ALTER GROUP my_group ADD USER dropped_member" or "CREATE ROLE new_group ROLE dropped_member" with a concurrent DROP of dropped_member. Note that DropOwnedObjects() and ReassignOwnedObjects() check has_privs_of_role() after the lock is acquired. Moving those into a callback could be done if we feel the need. [1]: https://postgr.es/m/CAM6Zo8woa62ZFHtMKox6a4jb8qQ%3Dw87R2L0K8347iE-juQL2EA%40mail.gmail.com Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com --cOHldBwZEf1OqVbN Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-Add-RoleNameGetOid-with-invalidation-based-retry-.patch"