Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kcIxM-0002Qx-F4 for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Nov 2020 02:00:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kcIxL-0002V6-9w for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Nov 2020 02:00:23 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kcIxJ-0002Uz-T3 for pgsql-hackers@lists.postgresql.org; Tue, 10 Nov 2020 02:00:23 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kcIxH-0002WY-M7 for pgsql-hackers@lists.postgresql.org; Tue, 10 Nov 2020 02:00:20 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 0BD6F5C01BE; Mon, 9 Nov 2020 21:00:19 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Mon, 09 Nov 2020 21:00:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:mime-version:content-type; s= fm3; bh=yIVjK5w/iJAC7thlZBGfq+sOGFy7tgrEEDkTvfLlGBw=; b=HczYXlpd QYThyqVPVCNwXbMZs9jwFV+wnVkFL72uoPDXXS/29GBG/eB/MF++epsJkxNa0ekm VAo7G/uqk+/gxoPLoJIrKYcJ5Yi4pOy8ih4Ft6SshZu1wGXdQcLYYWqMDw4cYGm3 fsYddBa5fz401LEHqExlhaSSZH9gFKyqpw3vXuPizWt5k93ba7vJZLT9c+2aBpka PmtRI3tpdmtD3uJmQDtlvP27l08sH5qAiFyHwF++wDwNKxq0VTd23O1DMBVF7T6c NuDo6CXyt25N1RXMyYSF27I/yEc7qqVHl8F+86cYGkv3CLX5gyZscx1UkDUyvja/ 3iy9szj/bwLgpA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:message-id :mime-version:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=yIVjK5w/iJAC7thlZBGfq+sOGFy7t grEEDkTvfLlGBw=; b=rCt6iyMZQdS4QiM57RrZuZn0QuazCGRlp4ZYJkUhP8mei heyqqhmU3NpCq1I42Qg+BnV9qfgTGB1qDg7oFF0L+vrf+sOUuo5njHJw/rr/m3fv cLWz37z/1B4n3dOuRv9+YKDXUfz8g+OI2XtvJqyAJgM+Q9uetdY1V0RH9JTGbp0J WV8esRN6uqy3c5hE3ZC+UTtskNIjp4+hNYTKWkP5d2pM9xps8oJKnXDazAvBXN+2 +XiddWFJWjS/qOBfPfYQzyp5x292mBZBR5p+XUbTJB/Ebg5x5oQlsshthr0+NyI6 JOj0Kjx1mQZsXIVafFU20zzLVaXdfIQB4G3UBnOaQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudduiedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdlfeehmdenucfjughrpeffhffvuffkgggtugesghdtreertddtvden ucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprghquh hivghrrdighiiiqeenucggtffrrghtthgvrhhnpeeihedvveekjeejudduheegjeeivdfh hfefgeeftdejieelgedtgeffhfetvdevtdenucffohhmrghinhepphhoshhtghhrvghsqh hlrdhorhhgnecukfhppeduuddurddutddvrddukedtrddukeehnecuvehluhhsthgvrhfu ihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuih gvrhdrgiihii X-ME-Proxy: Received: from paquier.xyz (ee0822lan1.rev.em-net.ne.jp [111.102.180.185]) by mail.messagingengine.com (Postfix) with ESMTPA id DD0E43063081; Mon, 9 Nov 2020 21:00:16 -0500 (EST) Date: Tue, 10 Nov 2020 11:00:14 +0900 From: Michael Paquier To: Postgres hackers Cc: Julien Rouhaud , Robert Haas Subject: Avoiding useless SHA256 initialization with backup manifests, breaking base backups with FIPS Message-ID: <20201110020014.GE1887@paquier.xyz> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="i3lJ51RuaGWuFYNw" Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --i3lJ51RuaGWuFYNw Content-Type: multipart/mixed; boundary="ffoCPvUAPMgSXi6H" Content-Disposition: inline --ffoCPvUAPMgSXi6H Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi all, Trying to use OpenSSL with FIPS breaks if one attempts to call the low-level SHA2 routines we currently use in sha2_openssl.c (upstream calls that OpenSSLDie()), forcing a crash of PG. The actual way to fix that is to use EVP as I solved here: https://commitfest.postgresql.org/30/2762/ Unfortunately, this enforces an ABI breakage so this is not backpatchable material. Now, if one attempts to use OpenSSL with FIPS, the initialization of backup manifests in InitializeBackupManifest() enforces a call to pg_sha256_init() for the manifest file itself even if pg_basebackup, or anything requesting a base backup with the replication protocol, does *not* want a backup manifest. One can for example enforce to not use a backup manifest with --no-manifest in pg_basebackup, but even if you specify that base backups cause the backend to crash on HEAD if using FIPS in OpenSSL. Looking at the code, the checksum of the manifest file is updated or finalized only if IsManifestEnabled() is satisfied, meaning that if the caller does not want a manifest we do its initialization, but we have no use for it. Attached is a patch that I would like to back-patch down to v13 to avoid this useless initialization, giving users the possibility to take base backups with FIPS when not using a backup manifest. Without the solution in the first paragraph, you cannot make use of backup=20 manifests at all with OpenSSL+FIPS (one can still enforce the use of the in-core SHA2 implementation even if building with OpenSSL), but at least it gives an escape route with 13. Thoughts? -- Michael --ffoCPvUAPMgSXi6H Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="backup-manifest-init-v1.patch" diff --git a/src/backend/replication/backup_manifest.c b/src/backend/replication/backup_manifest.c index 556e6b5040..bab5e2f53b 100644 --- a/src/backend/replication/backup_manifest.c +++ b/src/backend/replication/backup_manifest.c @@ -57,12 +57,17 @@ InitializeBackupManifest(backup_manifest_info *manifest, backup_manifest_option want_manifest, pg_checksum_type manifest_checksum_type) { + memset(manifest, 0, sizeof(backup_manifest_info)); + manifest->checksum_type = manifest_checksum_type; + if (want_manifest == MANIFEST_OPTION_NO) manifest->buffile = NULL; else + { manifest->buffile = BufFileCreateTemp(false); - manifest->checksum_type = manifest_checksum_type; - pg_sha256_init(&manifest->manifest_ctx); + pg_sha256_init(&manifest->manifest_ctx); + } + manifest->manifest_size = UINT64CONST(0); manifest->force_encode = (want_manifest == MANIFEST_OPTION_FORCE_ENCODE); manifest->first_file = true; --ffoCPvUAPMgSXi6H-- --i3lJ51RuaGWuFYNw Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAl+p9C4ACgkQnvQgOdby QH0LPhAAghhWkc7Z2TdukEeI/v5pINEy49g0L1KwG3o7Khab0wydLV9cX1/gQg8A qRBiDsapDNzEEpx5GijnhfGqOvfCZ3Hi0Y7uVXRfbrSjccpkXTnwW10GfGJe1I8M ciXLdkAjU5dHpwIIUOv4Jucbv1bdjDVBKL8V3qRjpzdPuLkRM6He0SjsoiuCKHsd b8fmjD4Z1Yn/dhx7eban18CBr19v7tn4Ps6gJyfeAG/8C0fVws+OkO3SxThGnSSu gHxxP4Eo17TU2uZKjmgV+/bfICdrmXZcqBX0RFbloOIRyE0iPapysVDiG3k5Z37q YA/fxxBjN+3dgRk/8XMjM8XkzK6C1oejeHkaJwxzbxGyUuo6y5f/8KDtK3A5p6vL ilE4qeKV+RTGKKJqTK+uGcmi8J9YiJgi/rel2dHF/jatz7PR2TwVhh7DGwxcfrru lEWXLkPbengcMixfoRbBG125d0JK6lQyVh6qFCe8vT3if22yib/UFZEmPfVV8Lg8 duK4vFlXwL0cCSLxswu1ZKIqbWrLXFVfpNAWhklVpC6BFjZxYmz5TYB/i1l7qy66 BcKc8xxRn9z/vZTbJY7h2Ut+s9fo97LfNXyQXzRdHjL8dNFpKvgLQQnwKmzLvqHW Jh5L3U4Ki+i9jd6GReMW4jYi8kfKdiQUvp2ZnjAwUpJkUjMD/IM= =tm57 -----END PGP SIGNATURE----- --i3lJ51RuaGWuFYNw--