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 1nALNk-00089j-2L for pgsql-general@arkaria.postgresql.org; Thu, 20 Jan 2022 00:32:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nALNi-0000gm-Gh for pgsql-general@arkaria.postgresql.org; Thu, 20 Jan 2022 00:32:50 +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 1nALNg-0000ga-KZ for pgsql-general@lists.postgresql.org; Thu, 20 Jan 2022 00:32:50 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nALNZ-00022E-D3 for pgsql-general@postgresql.org; Thu, 20 Jan 2022 00:32:47 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 973DB3201E88; Wed, 19 Jan 2022 19:32:39 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 19 Jan 2022 19:32:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=SEzKK6q3LIIkPztNQ/gLB65KB08 R66b0/u5FD4BJ9gM=; b=QrArKR7axp0SsFxZIlSJNu9zuM6b640zNsWT7W3MC9u Vw/gnJYG1PRg9oKWqeZMKIi9C90hTBX64fM/iij5u2Aqmkl8oYdXUn3CDoTGoNvp orLLUJ0FS5cYKraGKH7unaYKZFvFoQNDWePASqtf3B9phm90Nb4Pb7WmephEfcy5 UitVJCLnNPjey2SAPdHxdWmBOliX6Rk3BGCv0eW07khoH6XzrFAIKbJlhYpnadt0 uD8Mb9ZOmx59RAcKlaCt8cVpMdukVOp1+iI5bPdadSbpBEP9RFPvox217fTf3ShW Ne6rASF07hKNRq+1HUJnaYSf7Me1UpnkoaFnNSZBuwA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=SEzKK6 q3LIIkPztNQ/gLB65KB08R66b0/u5FD4BJ9gM=; b=KtkmRatvA2VQHkK1Cw8NCy lt5jqwMBT4wIkQpQlfDsfZO38skXACRGE7/1pxuWgY0Is9S2IKHsWnuIyzZpcrG6 awYjwtwqfohIxO2kGoRvvKEsex6n4fUx68jh1XGsQ28/J30rfHU9myg3UhZ3/PjJ ExgDmzFoYb4XT7UzupTH5FG5M7fqwGkek8l1erUYQCCqVMFDgMa61z5pbfLxHB9c HUJ90cGTiAStQbKgLo7Xt5jVS8fmRf7fN4fyCdBBNj4y54r+KogXmk9tnnbfSttd DzutxCYJl5add5M1guWfCHFEtsreAhGCP+Oj1Xu8ov8xobKSPXpeoklAUNrHsbfA == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudejgddvfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfg hrlhcuvffnffculdefhedmnecujfgurhepfffhvffukfhfgggtuggjsehgtderredttddv necuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesphgrqh huihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepffdufeeflefghfekudekkeevvddu gfeiteekkeduleefvefhhffftdduffeiuedtnecuffhomhgrihhnpehpohhsthhgrhgvsh hqlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhr ohhmpehmihgthhgrvghlsehprghquhhivghrrdighiii X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 19 Jan 2022 19:32:37 -0500 (EST) Date: Thu, 20 Jan 2022 09:32:33 +0900 From: Michael Paquier To: Thomas Munro Cc: Carla Iriberri , pgsql-general Subject: Re: could not accept SSL connection: Success Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="pzuLx0RCkLQTLys6" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --pzuLx0RCkLQTLys6 Content-Type: multipart/mixed; boundary="bEX8AlSlIQe9Sn4X" Content-Disposition: inline --bEX8AlSlIQe9Sn4X Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jan 20, 2022 at 09:05:35AM +1300, Thomas Munro wrote: > Good news, I'm glad they nailed that down. I recall that this > behaviour was a bit of a moving target in earlier versions: >=20 > https://www.postgresql.org/message-id/CAEepm%3D3cc5wYv%3DX4Nzy7VOUkdHBiJs= 9bpLzqtqJWxdDUp5DiPQ%40mail.gmail.com Ahh.. So you saw the same problem a couple of years back. This thread did not catch much attention. I don't think that it makes much sense to leave this unchecked as the message is confusing as it stands. Perhaps we could do something like the attached by adding a note about OpenSSL 3.0 to revisit this code once we unplug support for 1.1.1 and avoiding the errno=3D=3D0 case? The frontend has its own ideas of socket failures as it requires thread support, making things different with the backend, but it seems to me that we could see cases where SOCK_ERRNO is also 0. That's mostly what you suggested on the other thread. The error handling changes are really cosmetic, so I'd rather leave the back-branches out of that. Thoughts? -- Michael --bEX8AlSlIQe9Sn4X Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="ssl-eof-errno.patch" diff --git a/src/backend/libpq/be-secure-openssl.c b/src/backend/libpq/be-secure-openssl.c index 3d0168a369..12ddc6f82f 100644 --- a/src/backend/libpq/be-secure-openssl.c +++ b/src/backend/libpq/be-secure-openssl.c @@ -493,7 +493,13 @@ aloop: WAIT_EVENT_SSL_OPEN_SERVER); goto aloop; case SSL_ERROR_SYSCALL: - if (r < 0) + /* + * OpenSSL 1.1.1 and older versions return nothing on + * an unexpected EOF, and errno may not be set. Note that + * in OpenSSL 3.0, an unexpected EOF would result in + * SSL_ERROR_SSL with a meaningful error set on the stack. + */ + if (r < 0 && errno != 0) ereport(COMMERROR, (errcode_for_socket_access(), errmsg("could not accept SSL connection: %m"))); diff --git a/src/interfaces/libpq/fe-secure-openssl.c b/src/interfaces/libpq/fe-secure-openssl.c index 9f735ba437..b47ea87b43 100644 --- a/src/interfaces/libpq/fe-secure-openssl.c +++ b/src/interfaces/libpq/fe-secure-openssl.c @@ -314,6 +314,12 @@ pgtls_write(PGconn *conn, const void *ptr, size_t len) n = 0; break; case SSL_ERROR_SYSCALL: + /* + * OpenSSL 1.1.1 and older versions return nothing on + * an unexpected EOF, and errno may not be set. Note that + * in OpenSSL 3.0, an unexpected EOF would result in + * SSL_ERROR_SSL with a meaningful error set on the stack. + */ if (n < 0) { result_errno = SOCK_ERRNO; @@ -322,11 +328,14 @@ pgtls_write(PGconn *conn, const void *ptr, size_t len) libpq_gettext("server closed the connection unexpectedly\n" "\tThis probably means the server terminated abnormally\n" "\tbefore or while processing the request.\n")); - else + else if (result_errno != 0) appendPQExpBuffer(&conn->errorMessage, libpq_gettext("SSL SYSCALL error: %s\n"), SOCK_STRERROR(result_errno, sebuf, sizeof(sebuf))); + else + appendPQExpBuffer(&conn->errorMessage, + libpq_gettext("SSL SYSCALL error: internal failure\n")); } else { --bEX8AlSlIQe9Sn4X-- --pzuLx0RCkLQTLys6 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmHoraEACgkQnvQgOdby QH3YPw//Tx6zuW6BZgHrhN4z+tpiNgbNRJ+7IjvQhejF4nRXjQixlC0WY/G7XavO zRL8f70d8B4kcN0eDbAFRG6Ibq4UZMqTpyddcZSRNM24PEd+h+Dx/wPDq0ubSzcQ 8mDMG/B+2Wy/kqZOcQhBOfZeS9D9deakHOK6IzSUjaNxiziTTKbtWYww6UyCxJtW jzBubFlWRdIlsrrGWfy9qKgBAcWvix1xJL00JEuy2blT0Hn/o1Sj/14S4wgZ5MxF Gsy+872EBJ7AonxSaHhHHPgW4bEtu3gRQgjtDw3b9QOzjmKa7EUncjpggZ9dpm+o 7sNVvewaddMeGLrQR976QspDb+0Tq2SveyfxgdzmbLYtBusnoOYUWsIVndL+sCgx aVtHICd6kt2snUl5cbURREz4Iy+Agrkwq2yu6nve41vD/qMBqufMZAJUrHhX0m0r OpKlkb5/6GqD/MFeDhczdMXnjNygXBKYd1BFy1/9VwYWMoUsVW9w5S7GTdTnJ9AO nmXJfVTNbjxyy2twQsJAUbGZC8EfuiPEG1FpMz/OOWJz2gseaXpn9P7+5tkM6CO8 nuOlcr8W94G+dnXE3IHqF9f8n4JYovxUGgB5WckjMJc1Vj0vr1VrU8Icew0K3Ps3 TNcoF8GFBMWwBXMHN60izPA+0LVJtNTgnc+z2DZBG7wFtwjZIRQ= =WPlj -----END PGP SIGNATURE----- --pzuLx0RCkLQTLys6--