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.94.2) (envelope-from ) id 1uhoCY-004L82-RF for pgsql-bugs@arkaria.postgresql.org; Fri, 01 Aug 2025 11:45:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uhoCX-007aUh-Av for pgsql-bugs@arkaria.postgresql.org; Fri, 01 Aug 2025 11:45:29 +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.94.2) (envelope-from ) id 1uhoCW-007aTy-JQ for pgsql-bugs@lists.postgresql.org; Fri, 01 Aug 2025 11:45:29 +0000 Received: from fhigh-b6-smtp.messagingengine.com ([202.12.124.157]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1uhoCT-000BRT-2u for pgsql-bugs@lists.postgresql.org; Fri, 01 Aug 2025 11:45:27 +0000 Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfhigh.stl.internal (Postfix) with ESMTP id 7D83D7A018E; Fri, 1 Aug 2025 07:45:25 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-12.internal (MEProxy); Fri, 01 Aug 2025 07:45:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1754048725; x=1754135125; bh=gd/jnlMkl7 SdUbohRKhULtFuwAw0q6Av+Qd5krhhcTA=; b=FoYtMvMJ/mQnSVhE3WUiix6LD8 gO0kpmTm9ruRe+hPmiEDAclGcmI+KU6bnu6u0C/GbGPcvqPfMnb9+jy3asLDHj1h e5G2kQpQgNwaPYQAb5GxFfYTH8dAkqHHoVMipNl8ZqLZYxz9dHaWJSh7MQ4v8h6n eSg6YtGEeGJX6x11kv7JS99v9t8wPt8WrVZ4B9coMXYJwnoJHlB4Oqc7Rome9iYS jGbIqKpH5kHfDnj0DUWAbZCFOfJfhUDurP9Q1ZfDbqMHK3Nea6ppUI/y0wHexFww Uxx93UiZnV6WM1XfZIIxfd9q06yD9qsGMKJejfM4ti8wjtv5BvDLq5jYIrPA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1754048725; x=1754135125; bh=gd/jnlMkl7SdUbohRKhULtFuwAw0q6Av+Qd 5krhhcTA=; b=S9RAG3OESUoy8Do9Mp0iXpaU+0hMBu3pzwkGJIh/ZGCeEOuRIkt o02DeUdw8QpeGuJwcqFm/yf82WwwdHVF2l5jfAJGQuiOViw8PMCpekoPX5NTHW1f J5FKEkodh59biGwW58Tx6Ou9374olqtNO+6SNdHeMfV8HiAeFMS8FpA+hJhdbHvr AJFSlDf1xZzkwc7Ouj9OiPzFTJnYK0q34yGpu3afX8k5axq+kS+EURCXhlTLz7uX iX9aEgCvyn3Y3D6W1byC1z5F6pfAcjM0JnZS27ApmpXvF7AOI67xinYJbxBawnCT sx701tVOD71yXLUpukmj4Sp0M7onHr3p5eQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgddutdefiedtucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnegfrh hlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddv necuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesphgrqh huihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepteelieefudffhffhtdetleeggeeg fffhkeeuveetiefgudduvedutefggeeivdejnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihiidp nhgspghrtghpthhtohepgedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheprghmih htrdhkrghpihhlrgduieesghhmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhlqdgs uhhgsheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhgpdhrtghpthhtohepshgrfi gruggrrdhmshhhkhesghhmrghilhdrtghomhdprhgtphhtthhopegvthhhrghnrdhmvghr thiisehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 1 Aug 2025 07:45:23 -0400 (EDT) Date: Fri, 1 Aug 2025 20:45:10 +0900 From: Michael Paquier To: Amit Kapila Cc: Postgres bugs , Masahiko Sawada , Ethan Mertz Subject: Re: Use-after-free in reorderbuffer.c for INSERT ON CONFLICT Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="qeLOSZoHqZHPEEvu" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --qeLOSZoHqZHPEEvu Content-Type: multipart/mixed; boundary="f7jaUnqZwvisdiDh" Content-Disposition: inline --f7jaUnqZwvisdiDh Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Aug 01, 2025 at 03:30:17PM +0530, Amit Kapila wrote: > I mean to say we can use the same change LSN both for > REORDER_BUFFER_CHANGE_INTERNAL_SPEC_CONFIRM and > REORDER_BUFFER_CHANGE_INTERNAL_SPEC_ABORT. Right now, for > REORDER_BUFFER_CHANGE_INTERNAL_SPEC_CONFIRM, we switch the change to > specinsert which would have a prior LSN value (say, if confirm/abort > record will have value, 1000, it will be 800 or so) but we should > still use 1000 for update_progress_txn. The update_progress_txn() is > helpful when such an insert is skipped by a plugin (in this case > pgouput) and in that case, we would require the latest LSN processed > by reorder buffer to pass to it. We use it to send a keep_alive to a > client with the last LSN processed. Ah, OK, I've missed your point then. It's kind of an optimization in itself because we would be a bit more aggressive with the updates, but I agree to do that in the scope of this fix. The updated attached uses prev_lsn for the job, for both the ABORT and CONFIRM cases, meaning a one-liner. -- Michael --f7jaUnqZwvisdiDh Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-Fix-use-after-free-in-reorderbuffer.c-with-ON-CON.patch" Content-Transfer-Encoding: quoted-printable =46rom df18f6e51050193c739397056c80f82f3002dbb6 Mon Sep 17 00:00:00 2001 =46rom: Michael Paquier Date: Fri, 1 Aug 2025 20:35:05 +0900 Subject: [PATCH v2] Fix use-after-free in reorderbuffer.c with ON CONFLICT changes --- src/backend/replication/logical/reorderbuffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/= replication/logical/reorderbuffer.c index 5febd154b6ba..34cf05668ae8 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2599,7 +2599,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBuf= ferTXN *txn, =20 if (++changes_count >=3D CHANGES_THRESHOLD) { - rb->update_progress_txn(rb, txn, change->lsn); + rb->update_progress_txn(rb, txn, prev_lsn); changes_count =3D 0; } } --=20 2.50.0 --f7jaUnqZwvisdiDh-- --qeLOSZoHqZHPEEvu Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmiMqMYACgkQnvQgOdby QH1iAQ//fl/EU76+Md7SHvQB98v+AzRJPpEexrkNNq9CKBPAXOy33LyocWPIMd9v feVORbrIDABhJb15W0Tyh0BYi9aS+H+BcJqx2osFZaEgWkmkmicxOYG2bK7UQiF3 srtTpJVhvQBtZZPI0T/raSsN+VTWrbakSyx0zkWUtHVoV+zvASgVCQOk7B3jXTGs JJM9+03OpanHD9lXKnf88alxY+zycG5qby7wo5FDbFnkY3qM839mre7izBQ0AmiM jRNc+Q5QrNRmAid2esroGNHJRvmbt/6meYgPhE06PAAHL1a1KtPxoxszpbB0q+X7 GASN8GuwXdCl8LbpgBWiQXvuF/J10h7s9nXajCdDsh0Ky2sMnGLsMjsF4Ug2R9iB hbHHG+cbalyKCqvXDf7m6U1MCDAfWTeDSKsjWnpeIo3PkkNP7Ym9UAqvqjIFDfq+ IYr2oTjEV4v7ocAdi1Bllt21U61M8uOEeUpkcqqkEtDhRxdsOM126tSb5nx056Sp 1yc65EsYWFIen06oGt4K35S7oj9CxbtKgSmLqEbEUt7mUXKHbHFUWjknuHzDexSC pU0fvoNUn6yi9LTPtP0TZOJreKTuXcvv21Y9dWUzFSUv2ehPzkJfxWRVnU+7pVry zTY6NA2ecTduH0+OwhSkdjq1076IyVgLSLC1jkWjIh9lE22BAok= =PTcj -----END PGP SIGNATURE----- --qeLOSZoHqZHPEEvu--