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 1wi5Bs-0000Ov-08 for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Jul 2026 06:58:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wi5Bq-00GOGR-1K for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Jul 2026 06:58:27 +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 1wi5Bq-00GOGI-0H for pgsql-hackers@lists.postgresql.org; Fri, 10 Jul 2026 06:58:26 +0000 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wi5Bo-00000000R7O-2FDe for pgsql-hackers@postgresql.org; Fri, 10 Jul 2026 06:58:25 +0000 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-475881b9a4bso561848f8f.3 for ; Thu, 09 Jul 2026 23:58:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1783666703; x=1784271503; darn=postgresql.org; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:to:from:subject:message-id:from:to:cc :subject:date:message-id:reply-to:content-type; bh=UI3JeeUhbEGGEAwjeLZqEIglwud11imFnbeSjj7dxhI=; b=N7MwKeNMhHCBrK5KDXEMeJUFMK8EmiGJVWafNo7oyfMFgYouj6GrPnqxkzYHbZXkNP UJH3N21oaexvTWk9sgngdAhAnidsMmmcaC1xpXjXK9XLz4dJ4h0WiLGrtx5jkgcmNYvq 9kGmgQqWLMcnugBxSYZ7h9O81WbtR0ZUQTz7eWCv+dusQjn3+o+cAuQb22iP/wNIiFCQ 4JM8DSIGyC/f7Q2TymepGC7XyR1mBFDR+qSSpY0D+xvzZBZNndTnQ1UaGYGixjjM9x0W /Sjw+5lsdJQjaUQ//oK/duIDLNb+go+l7h79z2Hf8yCD4y+9ufheVdMNQ0bhLGawFDu1 er2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783666703; x=1784271503; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=UI3JeeUhbEGGEAwjeLZqEIglwud11imFnbeSjj7dxhI=; b=JugfkZFYTT0rzqcERfzWP6njqYS7eazJejsX1Vvxrn62M4YqLtobNV7O2q8+5fDzW4 EHS+twb7vwHwEm5XSt8LERj9DhpDUbqU58w0fI3gP59+oWeFQ4GBGEb/IHodo+3o33sy x71rP5iB9W7txWlM/rugZGsJ/P4BQ3fIyxIPMaqWYbrW4BuNPfPQrTeSzow3PNayqcMz b7Hg0QZjC3VqbV4qOsowjjkRL8zgPbNYzJ1Lv73sXLMfKOurUkwJ9cONaJvvHwRMsFVB JVV8LFXV2TeYBER7MG2qPFGkzZYRWgUBXx/ApDXA8TRcGcKpu8mtKI8uN8HcBRDWDoQ7 xrYA== X-Forwarded-Encrypted: i=1; AHgh+RrTJROn6PWt56RveQkC4z8mbnR8x4iH7+CoFPb7wvSnf3aR5LkWoI9++H7/UW65UMEpUz+NoqyGglCFwRCG@postgresql.org X-Gm-Message-State: AOJu0Ywi2hmmHdKpNnK136UsSNXQEpMghMa7jtKVTn5scQEmLqElpjDM 0yL1kXNU1PVM2N4q31S7Hb7znx/NvPIVIhcbtlFv23m+IXtaFCx8fg15vx4NTGz2JYj7PP0iPGJ ntbvnbx6pVQ== X-Gm-Gg: AfdE7ckLW+ppijIQaDPh7DSKg3WXQ7MsaGGnfHfrdY1ocJxxiT3JZNrVkiNZlGDjZUg fSg79T8VC3WwQsc4hyz7o28Jglbf6t5NFmWIVw0fcUMwx6TVn4UhDlPNvncePXY1GJRk+GBySQw TAOR0WQVxrjHffy625tSTvxALhQn5qYrkleAhGwbSltF46NF37UiLQIkFqM1SBPz97+iqup1JQT WG8t512UU3uuWm4B13gacUvjCE6k110iAd7XqZ7RYNp3AXoH9n0ZLqEW4nmF/+1128CeAnp0Ur+ 7kJYOVcH/l2MfOkjoZnaoSaCGFTjNSK/Kl/3ZSXxiVKmLx9natCgP61Ai1aqjV3NBrT9ugCMxD8 oLGsLfatWtoYA2CroJEMX0e+Q5Se2KNnxX4hAdCL9+RHEzfvoeAwxyF3+t48nlO3OHu+RNL9Yes jVtwW7T23zDAJI3hy1VaYmJqGRyinpF6SZb36xZ//fLy72 X-Received: by 2002:a05:6000:2007:b0:460:1301:dec6 with SMTP id ffacd0b85a97d-47df0715673mr11388536f8f.10.1783666703384; Thu, 09 Jul 2026 23:58:23 -0700 (PDT) Received: from laurenz.albe-K4N0CV00F97414D ([2001:871:270:b5dd:d75a:6339:d2c8:1d69]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47aa0960634sm58721369f8f.26.2026.07.09.23.58.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2026 23:58:22 -0700 (PDT) Message-ID: Subject: Re: equalPolicy() doesn't compare the permissive flag From: Laurenz Albe To: Andreas Lind , pgsql-hackers@postgresql.org Date: Fri, 10 Jul 2026 08:58:22 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.58.3 (3.58.3-1.fc43) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 2026-07-09 at 16:28 +0200, Andreas Lind wrote: > While working on an unrelated RLS patch, I noticed that equalPolicy() in > relcache.c doesn't compare the permissive field of RowSecurityPolicy. It > compares polcmd, hassublinks, policy_name, roles, qual, and > with_check_qual, but not permissive, so two policies that are identical > in every other respect except their PERMISSIVE/RESTRICTIVE designation > are reported as equal. >=20 > equalPolicy() is used (via equalRSDesc()) by RelationRebuildRelation() > to decide whether an open relation's existing row-security descriptor > can be kept as-is across a relcache rebuild, or must be treated as > changed. ALTER POLICY has no way to flip a policy's > PERMISSIVE/RESTRICTIVE designation, but DROP POLICY followed by CREATE > POLICY of the same name, roles, command, and quals, differing only in AS > PERMISSIVE/RESTRICTIVE, hits this exactly: the stale descriptor would be > kept, leaving the relcache out of sync with how the policy should now > combine with others (PERMISSIVE policies are ORed together; RESTRICTIVE > policies are ANDed with the rest). >=20 > I wasn't able to construct a simple SQL reproduction: > RelationRebuildRelation() (and thus this comparison) is only reached > while the relation is still open (refcount > 0) at the moment its > invalidation is processed. Closing and reopening the relation between > statements -- the usual behavior -- sidesteps the bug, and a second > session can't hold the relation open across the DROP/CREATE either, > since both need AccessExclusiveLock. This looks analogous to > ab6d1cd26eb, which fixed the same kind of omission in this function for > the USING qual and likewise shipped without a test. I don't know if the omission to check for identical PERMISSIVE or RESTRICTIVE settings can lead to real problems, but I feel that it violates the promise of the function. So I am +1 on this change. Yours, Laurenz Albe