pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: libpq: handle GSS credentials more sanely.
Date: Fri, 30 Oct 2026 17:56:34 +0000
Message-ID: <E1xMqqA-00000001R5C-2aqV@gemulon.postgresql.org> (raw)

libpq: handle GSS credentials more sanely.

pg_GSS_have_cred_cache() always acquires new GSS credentials.
If we already had some, they were just leaked due to overwriting
conn->gcred, and that's a nontrivial amount of memory (around 16K
according to reporter).  Unfortunately, pg_GSS_continue() did this
each time through, and it is typically called more than once in a
GSSAPI connection cycle.  So repeated connections using GSS
authentication could leak substantial amounts of memory.

IMO the source of this problem is really the poorly-designed API
of pg_GSS_have_cred_cache(): it's unclear that it always gets new
credentials.  Let's rename it and remove the unnecessary pointer
parameter to make its behavior clearer.

To add insult to injury, pg_GSS_continue() shouldn't even be
trying to acquire credentials unless GSS delegation is enabled,
which it is not by default; so the whole effort is often wasted.

Problems evidently introduced by 6633cfb21, so back-patch to v16.

Bug: #19411
Reported-by: Matt Carter <Matt.Carter@twosigma.com>
Diagnosed-by: Matt Carter <Matt.Carter@twosigma.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/19411-0440c8897a04b638@postgresql.org
Backpatch-through: 16

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/5aed88ff9f36422de302c7fe406c23cd732934b9

Modified Files
--------------
src/interfaces/libpq/fe-auth.c          | 10 ++++++----
src/interfaces/libpq/fe-connect.c       | 16 +++++++++++-----
src/interfaces/libpq/fe-gssapi-common.c | 15 ++++++---------
src/interfaces/libpq/fe-gssapi-common.h |  2 +-
src/interfaces/libpq/fe-secure-gssapi.c |  4 ++--
5 files changed, 26 insertions(+), 21 deletions(-)



view thread (5+ messages)  latest in thread

Message-ID: <E1xMqqA-00000001R5C-2aqV@gemulon.postgresql.org>
Permalink:  ../E1xMqqA-00000001R5C-2aqV@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xMqqA-00000001R5C-2aqV@gemulon.postgresql.org

 · 

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-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: libpq: handle GSS credentials more sanely.
  In-Reply-To: <E1xMqqA-00000001R5C-2aqV@gemulon.postgresql.org>
  References: <E1xMqqA-00000001R5C-2aqV@gemulon.postgresql.org>

* 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