Postmaster crashes on SIGHUP when oauth_validator_libraries holds only whitespace - Mailing list pgsql-bugs

From Grigorev Jurij
Subject Postmaster crashes on SIGHUP when oauth_validator_libraries holds only whitespace
Date
Msg-id 04fa84f6ebbe400f940e179ebe1070e9@localhost.localdomain
Whole thread
Responses Re: Postmaster crashes on SIGHUP when oauth_validator_libraries holds only whitespace
List pgsql-bugs
Hi,

I ran into a postmaster crash while investigating a static analyzer
report against 18.6.  I reproduced it on master (92aaf50e230,
--enable-cassert, Debian 13/aarch64).

To reproduce, set the following in postgresql.conf:

    oauth_validator_libraries = '   '

and add an OAuth line without validator= to pg_hba.conf:

    host all all 127.0.0.1/32 oauth issuer="https://example.com" scope="openid"

On reload the server log ends here:

    LOG:  received SIGHUP, reloading configuration files
    LOG:  parameter "oauth_validator_libraries" changed to "   "

gdb then reports SIGSEGV in check_oauth_validator(), via load_hba().
The running instance goes down with every session on it.  The same
configuration also prevents startup.  pg_hba_file_rules() parses the
file from a regular backend, so the same NULL dereference there kills
the backend and the postmaster restarts the cluster.

check_oauth_validator() treats an unset list as an error by looking at
the raw GUC string, but SplitDirectoriesString() accepts a string of
spaces and returns NIL.  The subsequent elemlist->length dereferences
that.  This is a misconfiguration rather than a security issue -- the
GUC has PGC_SIGHUP context and is marked GUC_SUPERUSER_ONLY.

I've attached a patch against master that checks the parsed list
instead.  It also adds a TAP test for reload.  The patched master built
without warnings, and "make check" in src/test/modules/oauth_validator
passed with PG_TEST_EXTRA=oauth.

This appears to affect v18 onward, where OAuth support was added, so it
may need back-patching.  The v18 error message has different wording
and would need a small adjustment.

Could someone take a look at the attached patch and let me know
if this is the right fix?

Thanks,
  Yuriy
Attachment

pgsql-bugs by date:

Previous
From: Ayush Tiwari
Date:
Subject: Re: BUG #19684: Assertion in tuplesort_begin_heap() falsified by parallel plan with sort
Next
From: Daniel Gustafsson
Date:
Subject: Re: Postmaster crashes on SIGHUP when oauth_validator_libraries holds only whitespace