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 1w0kjY-002B3T-10 for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Mar 2026 18:26:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w0kjV-00GX2V-2k for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Mar 2026 18:26:06 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w0khG-00GTpR-1K for pgsql-hackers@lists.postgresql.org; Thu, 12 Mar 2026 18:23:46 +0000 Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w0khE-00000002L68-1deE for pgsql-hackers@postgresql.org; Thu, 12 Mar 2026 18:23:46 +0000 Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-467161c4b89so841126b6e.3 for ; Thu, 12 Mar 2026 11:23:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773339823; cv=none; d=google.com; s=arc-20240605; b=DMoHA6MMTfGWCQklavMjCKwkW49EWOa1yQnrkeMZxHk325y6pl0ADq5lVij6NfLEhX DgDehMJRVSAg5rQnnY+EpGTXoYeMIKS2LhI2Hv9PTax8oewiEQ1/lrY2wzY/jmUr9RJA R48AVVbi3oDCNnXN3Ufz9+B5Mqu7JMkHkCGERLx+aCD8fHwgrmC28BtLlaCoDJwRhTNJ DN0XiVJaPVZAn33mJTcuwYZtLZ+LWrBU5zWgzpSTyYYMk+zgtCTqcssYLiZJck3qe2yz eV5M0QIp7gHbY3lcbbEJl6k/Jl7/8OqGHt3aVPQPzTq6OkcVHoA/ZlPqrN0QwOdoMaUf bk8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=gx41W1fvgXBn4osO1wJWQteOEKISadr2xdmVdu1QMR8=; fh=C7+1OUakbWZCCc5JoZ+Io2pGOEnQDtI2ospd5IfpQfM=; b=dJnh/7czdjr9IV6oji2saICULsU/EHJPC10HTNpVbwP/J/mdYkQPUuA/HfuxgQeM+G VxMASwAPcWGl9GtMopZcEo5UzKMJ4qr9JRRuVNijBduuHVb0X45GmTmjB9B0fp9h7r9k 3BhfBlCA+0VmSvSzw2WYGQNOrIDQzePrjI5aWsF5at6K6ISjSSNUbBWUx8Yu1aXbFuBD 3/6dzoOybM1HPCtSOvgfXF99sna+OvJsIqF+OvQ9njdCLlIJ7b45HxPq2IFlECKY/1wV t6Nf1oTm0y5EKSj8wDP9pPoscCoAbRyl2Tqcf6BBFhdMDN+MkXESAu9JW3CsMGX0qcaG fcKA==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tigerdata.com; s=google; t=1773339823; x=1773944623; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=gx41W1fvgXBn4osO1wJWQteOEKISadr2xdmVdu1QMR8=; b=HpfMkqKBIQcWkRxt2+4+v2HW64WjL05kT70R+eEgzAJFIlwboOVYmkaHNbsxqANFq7 rxIQxjXc0pFLiYOAb5MVxGeYNkhlhQRbw4joCZtoX21j8Z8BvY3x7IJM/iDF8Oz3elKL 0Tb3sHAiwuIdDLycO886Vyk5AqosvJ9AurJJVKaGtQYoUQA4RHxpneHHAdnuwvNJhoee fkkbk5qvFbhHc0K7cbxSQGYkPBXMN+5IkynRRF7zW4PgmOUQ0ldZ0MKUcQ0ZG9B2jvsg lBUQef5WtE6cdV9CwIOU3asIvhOE4ymlIv/2s8uXZPX/AWDx4ArP54Y7To1Fn8mDZz/r Kadw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773339823; x=1773944623; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=gx41W1fvgXBn4osO1wJWQteOEKISadr2xdmVdu1QMR8=; b=t4jvjwYueN99o/omHlXyeI45HifepAIFFzfYoh4OquyiHxXyfczx0Woc4oEZeJme1H YWGzA/HJHEhyV8MbSchMKa1RkoZpdYqQ7PteGuehxV0bdjJAVs8lJk2wq+IVhVhxp0fY OEN83OHZpip38vxN3dsbYWwg4LEuUx+a4IC8jkPUslVpm4aWk8Ic0Jf21meZU0dnsVy0 ATeDTIQjjq+kyzKK5k1LqJKeJVMzCHV4jkuvKfElyWCjXqzxaHLaLjtJ6+DR+nCAk7GY PbhsVYukNiRVzcc6OXGSN7DovPBtL26WgN3SSHcn9TD/el8Q0j56w6a9tMF1zwD/hQuq ew1g== X-Forwarded-Encrypted: i=1; AJvYcCVcloznCWkmWbRoEdzF8NOOeStTVHnTuFODSNv4GZZTHT9kd9/Pt5MXVRmpCoUWTmyFxCV6Gc0mdGPtzsFL@postgresql.org X-Gm-Message-State: AOJu0YxvqJWp23MueHnAOjNIJ1UjOCsN/8oWroaU2qI0ANa9b0DWGGR6 PzqMe1VNUzAXNm+YcqYNNnUdtHc20buC9zoxJtsntMlnrev4xotD3AFF94L/UPqe1bsdNS/VAT8 3GySaAlIKeNtsbhKl2jfsYhBPubCZCA1IvBTeRh3H7g== X-Gm-Gg: ATEYQzyB+BDyrenzozLuLpTa9VNuecqK4NirKMdGE164MD+jfel01S7j0tI5oiHT1bv 70+MSvGhYW9Bs1fSXCM6gE8Mx/NOepwD6JpWyvqkUGyViyp/OZKuy0dViSd6eKuPrWRXBEIEn1T xVUgo03JwdkPwuEADuGXSEDbYRDn83QOpKbIC3tLByst1IbCEPiJ5RnMyYS1U53xOWnJNK4Eadq rosLbU32AGFQysfn1N3o6Y3XrZKWT2raDZVWUNqVCZ5r5Tx/5Qzm31TLHxFZy5eRoJcs1JKKpSM /Tmu/A== X-Received: by 2002:a05:6808:4fec:b0:467:1462:a9a0 with SMTP id 5614622812f47-46757116a69mr192778b6e.15.1773339822595; Thu, 12 Mar 2026 11:23:42 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Alexander Kuzmenkov Date: Thu, 12 Mar 2026 19:23:31 +0100 X-Gm-Features: AaiRm51O0mIOiNi1pTxdWGgrB8R_gNnzeJUCuBrM3WKIfE3z1_az7xfxsMzTVhM Message-ID: Subject: Re: Fix uninitialized xl_running_xacts padding To: Heikki Linnakangas Cc: Andres Freund , Anthonin Bonnefoy , Bertrand Drouvot , Michael Paquier , Thomas Munro , PostgreSQL Hackers Content-Type: multipart/alternative; boundary="0000000000003132b3064cd7dafd" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000003132b3064cd7dafd Content-Type: text/plain; charset="UTF-8" The functions in the "0003" patch haven't surfaced in my "make installcheck-parallel" runs with Valgrind, or the "make check" with MemorySanitizer. However, I could hit most of them with some fuzzing. The only exception was `xl_hash_vacuum_one_page` but that's probably also triggerable. I noticed that we also use `sizeof` in some WAL functions, so probably the tail padding can also be written to WAL? For example, consider this: (gdb) ptype/o gistxlogPageSplit type = struct gistxlogPageSplit { /* 0 | 4 */ BlockNumber origrlink; /* XXX 4-byte hole */ /* 8 | 8 */ GistNSN orignsn; /* 16 | 1 */ _Bool origleaf; /* XXX 1-byte hole */ /* 18 | 2 */ uint16 npage; /* 20 | 1 */ _Bool markfollowright; /* XXX 3-byte padding */ /* total size (bytes): 24 */ } And then we do XLogRegisterData((char *) &xlrec, sizeof(gistxlogPageSplit)); In general, I'm wondering what our approach to this should be. Several potential improvements were mentioned, but I think for now we could focus on removing the Valgrind suppression. This is a meaningful improvement that uses the existing test tools. Do we want to defensively zero-initialize every case that seems to be potentially affected, i.e. written to WAL and has holes/tail padding? That sounds cheap and simple and probably even backportable. In the "0001" patch, there are several cases where no padding goes into WAL, I can remove these. For example, the use of xl_brin_createidx in brinbuild() does not have this problem. --0000000000003132b3064cd7dafd Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
The functions in the "0003" patch haven't su= rfaced in my "make installcheck-parallel" runs with Valgrind, or = the "make check" with MemorySanitizer. However, I could hit most = of them with some fuzzing. The only exception was `xl_hash_vacuum_one_page`= but that's probably also triggerable.

I noticed that we also us= e `sizeof` in some WAL functions, so probably the tail padding can also be = written to WAL? For example, consider this:
(gdb) ptype/o gistxlogPageSplit
type =3D struct gistxlogPageSp= lit {
/* =C2=A0 =C2=A0 =C2=A00 =C2=A0 =C2=A0 =C2=A0| =C2=A0 =C2=A0 =C2= =A0 4 */ =C2=A0 =C2=A0BlockNumber origrlink;
/* XXX =C2=A04-byte hole = =C2=A0 =C2=A0 =C2=A0*/
/* =C2=A0 =C2=A0 =C2=A08 =C2=A0 =C2=A0 =C2=A0| = =C2=A0 =C2=A0 =C2=A0 8 */ =C2=A0 =C2=A0GistNSN orignsn;
/* =C2=A0 =C2=A0= 16 =C2=A0 =C2=A0 =C2=A0| =C2=A0 =C2=A0 =C2=A0 1 */ =C2=A0 =C2=A0_Bool orig= leaf;
/* XXX =C2=A01-byte hole =C2=A0 =C2=A0 =C2=A0*/
/* =C2=A0 =C2= =A0 18 =C2=A0 =C2=A0 =C2=A0| =C2=A0 =C2=A0 =C2=A0 2 */ =C2=A0 =C2=A0uint16 = npage;
/* =C2=A0 =C2=A0 20 =C2=A0 =C2=A0 =C2=A0| =C2=A0 =C2=A0 =C2=A0 1 = */ =C2=A0 =C2=A0_Bool markfollowright;
/* XXX =C2=A03-byte padding =C2= =A0 */

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/* total size (bytes): = =C2=A0 24 */
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0}

And then we do=C2=A0 X= LogRegisterData((char *) &xlrec, sizeof(gistxlogPageSplit));

In general, I'm wondering what our approach to this should be. Several= potential improvements were mentioned, but I think for now we could focus = on removing the Valgrind suppression. This is a meaningful improvement that= uses the existing test tools. Do we want to defensively zero-initialize ev= ery case that seems to be potentially affected, i.e. written to WAL and has= holes/tail padding? That sounds cheap and simple and probably even backpor= table. In the "0001" patch, there are several cases where no padd= ing goes into WAL, I can remove these. For example, the use of xl_brin_crea= teidx in brinbuild() does not have this problem.
--0000000000003132b3064cd7dafd--