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 1n5VoF-0001JW-PV for pgsql-general@arkaria.postgresql.org; Thu, 06 Jan 2022 16:40:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1n5VoE-0002Hc-LV for pgsql-general@arkaria.postgresql.org; Thu, 06 Jan 2022 16:40:14 +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 1n5VoE-0002HQ-Az for pgsql-general@lists.postgresql.org; Thu, 06 Jan 2022 16:40:14 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n5VoC-0004rg-5L for pgsql-general@lists.postgresql.org; Thu, 06 Jan 2022 16:40:13 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 206Ge4UA1084380; Thu, 6 Jan 2022 11:40:05 -0500 From: Tom Lane To: Michael Paquier cc: Christoph Moench-Tegeder , Michael =?iso-8859-1?Q?M=FChlbeyer?= , "pgsql-general@lists.postgresql.org" Subject: Re: md5 issues Postgres14 on OL7 In-reply-to: References: <89B7F072-5BBE-4C92-903E-D83E865D9367@trivadis.com> <4038656.1641318875@sss.pgh.pa.us> <4190764.1641362933@sss.pgh.pa.us> Comments: In-reply-to Michael Paquier message dated "Thu, 06 Jan 2022 17:20:27 +0900" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <1084195.1641487059.0@sss.pgh.pa.us> Date: Thu, 06 Jan 2022 11:40:04 -0500 Message-ID: <1084379.1641487204@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1084195.1641487059.1@sss.pgh.pa.us> Michael Paquier writes: > I have been looking at that, and finished with the attached. It is > close to the end of the day, so this needs an extra lookup, but I have > finished by using the idea of an extra routine, called > pg_cryptohash_error(), able to grab the error saved in the private > contexts, so as any callers from the backend or the frontend can feed > on that. This way, it is possible to make the difference between > several class of errors: OOMs, a too short destination buffer, OpenSSL > internal error, etc. I don't like the end result of this at all: postgres=# select md5('foo'); ERROR: could not compute MD5 hash: OpenSSL failure Maybe we've successfully laid off blame somewhere else, but this doesn't move the user one inch towards understanding the cause. I think we need to report the actual OpenSSL error reason. I experimented with the attached, very rough delta on top of your patch, and got postgres=# select md5('foo'); ERROR: could not compute MD5 hash: disabled for FIPS which seems far better, plus it'd work for other sorts of OpenSSL failures. There are two problems with my delta as it stands: 1. It draws a cast-away-const warning. We'd have to make the result of pg_cryptohash_error be "const char *", which would be better practice anyway, but that propagates into some other APIs and I didn't take the trouble to chase it to the end. 2. It feels a bit bogus to be fetching ERR_get_error() at this point. Maybe it's all right to assume that the OpenSSL error stack won't change state before we get to pg_cryptohash_error, but I don't like the idea much. I think it'd be better to capture ERR_get_error() sooner and store it in an additional field in pg_cryptohash_ctx. Also, I wonder if this shouldn't be unified with the SSLerrmessage() support found in be-secure-openssl.c and fe-secure-openssl.c. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="openssl-error-delta.patch"; charset="us-ascii" Content-ID: <1084195.1641487059.2@sss.pgh.pa.us> Content-Description: openssl-error-delta.patch diff -u cryptohash_openssl.c.orig cryptohash_openssl.c --- cryptohash_openssl.c.orig 2022-01-06 11:15:59.268256281 -0500 +++ cryptohash_openssl.c 2022-01-06 11:22:28.602734304 -0500 @@ -21,6 +21,7 @@ #include "postgres_fe.h" #endif +#include #include #include "common/cryptohash.h" @@ -309,7 +310,14 @@ case PG_CRYPTOHASH_ERROR_DEST_LEN: return _("destination buffer too small"); case PG_CRYPTOHASH_ERROR_OPENSSL: - return _("OpenSSL failure"); + { + unsigned long ecode = ERR_get_error(); + const char *errreason = ERR_reason_error_string(ecode); + + if (errreason) + return errreason; + return _("OpenSSL failure"); + } } /* assume that the default is out-of-memory, anyway */ ------- =_aaaaaaaaaa0--