pg.ddx.io pgsql-committers@postgresql.org mailing list archive
help / color / mirror / Atom feedpgsql: Improve error handling of cryptohash computations
6+ messages / 3 participants
[nested] [flat]
Commits from this thread:
2022-01-14 ad5b6f248a Revert error handling improvements for cryptohashes
* pgsql: Improve error handling of cryptohash computations
@ 2022-01-11 00:56 Michael Paquier <michael@paquier.xyz>
0 siblings, 0 replies; 6+ messages in thread
From: Michael Paquier @ 2022-01-11 00:56 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Improve error handling of cryptohash computations
The existing cryptohash facility was causing problems in some code paths
related to MD5 (frontend and backend) that relied on the fact that the
only type of error that could happen would be an OOM, as the MD5
implementation used in PostgreSQL ~13 (the in-core implementation is
used when compiling with or without OpenSSL in those older versions),
could fail only under this circumstance.
The new cryptohash facilities can fail for reasons other than OOMs, like
attempting MD5 when FIPS is enabled (upstream OpenSSL allows that up to
1.0.2, Fedora and Photon patch OpenSSL 1.1.1 to allow that), so this
would cause incorrect reports to show up.
This commit extends the cryptohash APIs so as callers of those routines
can fetch more context when an error happens, by using a new routine
called pg_cryptohash_error(). The error states are stored within each
implementation's internal context data, so as it is possible to extend
the logic depending on what's suited for an implementation. The default
implementation requires few error states, but OpenSSL could report
various issues depending on its internal state so more is needed in
cryptohash_openssl.c, and the code is shaped so as we are always able to
grab the necessary information.
The core code is changed to adapt to the new error routine, painting
more "const" across the call stack where the static errors are stored,
particularly in authentication code paths on variables that provide
log details. This way, any future changes would warn if attempting to
free these strings. The MD5 authentication code was also a bit blurry
about the handling of "logdetail" (LOG sent to the postmaster), so
improve the comments related that, while on it.
The origin of the problem is 87ae969, that introduced the centralized
cryptohash facility. Extra changes are done for pgcrypto in v14 for the
non-OpenSSL code path to cope with the improvements done by this
commit.
Reported-by: Michael Mühlbeyer
Author: Michael Paquier
Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/89B7F072-5BBE-4C92-903E-D83E865D9367@trivadis.com
Backpatch-through: 14
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/b69aba74578adf58f48de0f21dceddc2d9f1c4b1
Modified Files
--------------
contrib/passwordcheck/passwordcheck.c | 2 +-
contrib/uuid-ossp/uuid-ossp.c | 18 ++++--
src/backend/commands/user.c | 4 +-
src/backend/libpq/auth-sasl.c | 2 +-
src/backend/libpq/auth-scram.c | 5 +-
src/backend/libpq/auth.c | 33 ++++++-----
src/backend/libpq/crypt.c | 38 ++++++-------
src/backend/replication/backup_manifest.c | 11 ++--
src/backend/utils/adt/cryptohashfuncs.c | 25 ++++++---
src/common/cryptohash.c | 57 ++++++++++++++++++-
src/common/cryptohash_openssl.c | 93 +++++++++++++++++++++++++++++++
src/common/md5_common.c | 20 +++++--
src/include/common/cryptohash.h | 1 +
src/include/common/md5.h | 9 ++-
src/include/libpq/crypt.h | 7 ++-
src/include/libpq/sasl.h | 4 +-
src/interfaces/libpq/fe-auth.c | 22 ++++++--
src/tools/pgindent/typedefs.list | 1 +
18 files changed, 275 insertions(+), 77 deletions(-)
^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Improve error handling of cryptohash computations
@ 2022-01-11 00:56 Michael Paquier <michael@paquier.xyz>
2022-01-13 17:52 ` Re: pgsql: Improve error handling of cryptohash computations Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 1 reply; 6+ messages in thread
From: Michael Paquier @ 2022-01-11 00:56 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Improve error handling of cryptohash computations
The existing cryptohash facility was causing problems in some code paths
related to MD5 (frontend and backend) that relied on the fact that the
only type of error that could happen would be an OOM, as the MD5
implementation used in PostgreSQL ~13 (the in-core implementation is
used when compiling with or without OpenSSL in those older versions),
could fail only under this circumstance.
The new cryptohash facilities can fail for reasons other than OOMs, like
attempting MD5 when FIPS is enabled (upstream OpenSSL allows that up to
1.0.2, Fedora and Photon patch OpenSSL 1.1.1 to allow that), so this
would cause incorrect reports to show up.
This commit extends the cryptohash APIs so as callers of those routines
can fetch more context when an error happens, by using a new routine
called pg_cryptohash_error(). The error states are stored within each
implementation's internal context data, so as it is possible to extend
the logic depending on what's suited for an implementation. The default
implementation requires few error states, but OpenSSL could report
various issues depending on its internal state so more is needed in
cryptohash_openssl.c, and the code is shaped so as we are always able to
grab the necessary information.
The core code is changed to adapt to the new error routine, painting
more "const" across the call stack where the static errors are stored,
particularly in authentication code paths on variables that provide
log details. This way, any future changes would warn if attempting to
free these strings. The MD5 authentication code was also a bit blurry
about the handling of "logdetail" (LOG sent to the postmaster), so
improve the comments related that, while on it.
The origin of the problem is 87ae969, that introduced the centralized
cryptohash facility. Extra changes are done for pgcrypto in v14 for the
non-OpenSSL code path to cope with the improvements done by this
commit.
Reported-by: Michael Mühlbeyer
Author: Michael Paquier
Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/89B7F072-5BBE-4C92-903E-D83E865D9367@trivadis.com
Backpatch-through: 14
Branch
------
REL_14_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/3a0cced86d3b1bbbf0aaa0fb34e2b15edd643979
Modified Files
--------------
contrib/passwordcheck/passwordcheck.c | 2 +-
contrib/pgcrypto/internal-sha2.c | 9 ++-
contrib/pgcrypto/internal.c | 18 ++++--
contrib/uuid-ossp/uuid-ossp.c | 18 ++++--
src/backend/commands/user.c | 4 +-
src/backend/libpq/auth-scram.c | 2 +-
src/backend/libpq/auth.c | 36 +++++++-----
src/backend/libpq/crypt.c | 38 ++++++-------
src/backend/replication/backup_manifest.c | 9 ++-
src/backend/utils/adt/cryptohashfuncs.c | 25 ++++++---
src/common/cryptohash.c | 57 ++++++++++++++++++-
src/common/cryptohash_openssl.c | 93 +++++++++++++++++++++++++++++++
src/common/md5_common.c | 20 +++++--
src/include/common/cryptohash.h | 1 +
src/include/common/md5.h | 9 ++-
src/include/libpq/crypt.h | 7 ++-
src/include/libpq/scram.h | 3 +-
src/interfaces/libpq/fe-auth.c | 22 ++++++--
src/tools/pgindent/typedefs.list | 1 +
19 files changed, 290 insertions(+), 84 deletions(-)
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: pgsql: Improve error handling of cryptohash computations
2022-01-11 00:56 pgsql: Improve error handling of cryptohash computations Michael Paquier <michael@paquier.xyz>
@ 2022-01-13 17:52 ` Laurenz Albe <laurenz.albe@cybertec.at>
2022-01-13 19:52 ` Re: pgsql: Improve error handling of cryptohash computations Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 6+ messages in thread
From: Laurenz Albe @ 2022-01-13 17:52 UTC (permalink / raw)
To: Michael Paquier <michael@paquier.xyz>; pgsql-committers@lists.postgresql.org
On Tue, 2022-01-11 at 00:56 +0000, Michael Paquier wrote:
> Improve error handling of cryptohash computations
This commit changes the signature of the exported "pg_md5_hash" function,
which breaks my extension that uses this function.
Is there no way to avoid this API break in the back branches?
Yours,
Laurenz Albe
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: pgsql: Improve error handling of cryptohash computations
2022-01-11 00:56 pgsql: Improve error handling of cryptohash computations Michael Paquier <michael@paquier.xyz>
2022-01-13 17:52 ` Re: pgsql: Improve error handling of cryptohash computations Laurenz Albe <laurenz.albe@cybertec.at>
@ 2022-01-13 19:52 ` Tom Lane <tgl@sss.pgh.pa.us>
2022-01-14 01:49 ` Re: pgsql: Improve error handling of cryptohash computations Michael Paquier <michael@paquier.xyz>
0 siblings, 1 reply; 6+ messages in thread
From: Tom Lane @ 2022-01-13 19:52 UTC (permalink / raw)
To: Laurenz Albe <laurenz.albe@cybertec.at>; +Cc: Michael Paquier <michael@paquier.xyz>; pgsql-committers@lists.postgresql.org
Laurenz Albe <laurenz.albe@cybertec.at> writes:
> On Tue, 2022-01-11 at 00:56 +0000, Michael Paquier wrote:
>> Improve error handling of cryptohash computations
> This commit changes the signature of the exported "pg_md5_hash" function,
> which breaks my extension that uses this function.
> Is there no way to avoid this API break in the back branches?
Probably none of this should have been back-patched --- the issues
are not so large that they require a risk of breaking things in
the back branches.
regards, tom lane
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: pgsql: Improve error handling of cryptohash computations
2022-01-11 00:56 pgsql: Improve error handling of cryptohash computations Michael Paquier <michael@paquier.xyz>
2022-01-13 17:52 ` Re: pgsql: Improve error handling of cryptohash computations Laurenz Albe <laurenz.albe@cybertec.at>
2022-01-13 19:52 ` Re: pgsql: Improve error handling of cryptohash computations Tom Lane <tgl@sss.pgh.pa.us>
@ 2022-01-14 01:49 ` Michael Paquier <michael@paquier.xyz>
2022-01-14 06:57 ` Re: pgsql: Improve error handling of cryptohash computations Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 1 reply; 6+ messages in thread
From: Michael Paquier @ 2022-01-14 01:49 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Laurenz Albe <laurenz.albe@cybertec.at>; pgsql-committers@lists.postgresql.org
On Thu, Jan 13, 2022 at 02:52:12PM -0500, Tom Lane wrote:
> Probably none of this should have been back-patched --- the issues
> are not so large that they require a risk of breaking things in
> the back branches.
Agreed, that's not worth breaking things in v14, so I'll go and revert
this stuff in it.
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: pgsql: Improve error handling of cryptohash computations
2022-01-11 00:56 pgsql: Improve error handling of cryptohash computations Michael Paquier <michael@paquier.xyz>
2022-01-13 17:52 ` Re: pgsql: Improve error handling of cryptohash computations Laurenz Albe <laurenz.albe@cybertec.at>
2022-01-13 19:52 ` Re: pgsql: Improve error handling of cryptohash computations Tom Lane <tgl@sss.pgh.pa.us>
2022-01-14 01:49 ` Re: pgsql: Improve error handling of cryptohash computations Michael Paquier <michael@paquier.xyz>
@ 2022-01-14 06:57 ` Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 0 replies; 6+ messages in thread
From: Laurenz Albe @ 2022-01-14 06:57 UTC (permalink / raw)
To: Michael Paquier <michael@paquier.xyz>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-committers@lists.postgresql.org
On Fri, 2022-01-14 at 10:49 +0900, Michael Paquier wrote:
> On Thu, Jan 13, 2022 at 02:52:12PM -0500, Tom Lane wrote:
> > Probably none of this should have been back-patched --- the issues
> > are not so large that they require a risk of breaking things in
> > the back branches.
>
> Agreed, that's not worth breaking things in v14, so I'll go and revert
> this stuff in it.
Thanks!
Yours,
Laurenz Albe
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2022-01-14 06:57 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-01-11 00:56 pgsql: Improve error handling of cryptohash computations Michael Paquier <michael@paquier.xyz>
2022-01-11 00:56 pgsql: Improve error handling of cryptohash computations Michael Paquier <michael@paquier.xyz>
2022-01-13 17:52 ` Laurenz Albe <laurenz.albe@cybertec.at>
2022-01-13 19:52 ` Tom Lane <tgl@sss.pgh.pa.us>
2022-01-14 01:49 ` Michael Paquier <michael@paquier.xyz>
2022-01-14 06:57 ` Laurenz Albe <laurenz.albe@cybertec.at>
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