pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Michael Paquier <michael@paquier.xyz>
Cc: Christoph Moench-Tegeder <cmt@burggraben.net>
Cc: Michael Mühlbeyer <Michael.Muehlbeyer@trivadis.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: md5 issues Postgres14 on OL7
Date: Thu, 06 Jan 2022 11:40:04 -0500
Message-ID: <1084379.1641487204@sss.pgh.pa.us> (raw)
In-Reply-To: <YdamS8Sdwmiu4gsN@paquier.xyz>
References: <89B7F072-5BBE-4C92-903E-D83E865D9367@trivadis.com>
	<YcCRp9QvQvCZ7ODI@elch.exwg.net>
	<YdQ1GLqQ/Vq6LwW9@paquier.xyz>
	<4038656.1641318875@sss.pgh.pa.us>
	<YdUx+6Sm5T0II8Un@paquier.xyz>
	<4190764.1641362933@sss.pgh.pa.us>
	<YdVEGLO/Ft7FUWF6@paquier.xyz>
	<YdamS8Sdwmiu4gsN@paquier.xyz>

Michael Paquier <michael@paquier.xyz> 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

Attachments:

openssl-error-delta.patch (text/x-diff, 756B) download 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 <openssl/err.h> #include <openssl/evp.h> #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 */

view thread (16+ messages)  latest in thread

Message-ID: <1084379.1641487204@sss.pgh.pa.us>
Permalink:  ../1084379.1641487204@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1084379.1641487204@sss.pgh.pa.us

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, michael@paquier.xyz, cmt@burggraben.net, Michael.Muehlbeyer@trivadis.com
  Subject: Re: md5 issues Postgres14 on OL7
  In-Reply-To: <1084379.1641487204@sss.pgh.pa.us>
  References: <89B7F072-5BBE-4C92-903E-D83E865D9367@trivadis.com> <YcCRp9QvQvCZ7ODI@elch.exwg.net> <YdQ1GLqQ/Vq6LwW9@paquier.xyz> <4038656.1641318875@sss.pgh.pa.us> <YdUx+6Sm5T0II8Un@paquier.xyz> <4190764.1641362933@sss.pgh.pa.us> <YdVEGLO/Ft7FUWF6@paquier.xyz> <YdamS8Sdwmiu4gsN@paquier.xyz> <1084379.1641487204@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox