Re: [oauth] Increased CPU usage during device flow with libcurl 8.20.0

Поиск
Список
Период
Сортировка
Искать

Re: [oauth] Increased CPU usage during device flow with libcurl 8.20.0

От:
Jacob Champion <jacob.champion@enterprisedb.com>
Дата:
Вложения:
On Mon, Jun 15, 2026 at 12:47 PM Tom Lane  wrote:
> Jacob Champion  writes:
> > So that just leaves what to do about the current test failures. My
> > current idea is to just skip the test if the curl binary reports that
> > specific minor version.
>
> Seems like a good solution.  We don't know how long such curl
> binaries will persist in the wild.

Cool. Unfortunately, I immediately ran into an obvious-in-retrospect
problem: the Homebrew libcurl we're linked against is not what you see
when you type `curl --version` at the command line, and I don't think
we record the runtime version of libcurl anywhere today. I've attached
a solution that should work well for PG20, but I don't feel as good
about it for 19 (or a backport to 18).

I need to switch to a different context for today, but tomorrow I'll
try to find a solution that touches only the test code.

Thanks,
--Jacob

Re: [oauth] Increased CPU usage during device flow with libcurl 8.20.0

От:
Daniel Gustafsson <daniel@yesql.se>
Дата:
> On 16 Jun 2026, at 21:46, Jacob Champion  wrote:

> Attached as v2-0002, which moves the version check into one of the
> OAuth test executables. (I'll hold 0004 until after REL_19_STABLE is
> branched; it just implements the v1 strategy and reverts 0002.)

+#if USE_LIBCURL
+
+/*
+ * XXX You may wonder why this test executable, which purposely does not make
+ * use of libcurl functionality, is printing out the version of Curl. This is
+ * needed to skip tests in 001_server when we see a known broken version of
+ * libcurl. (Querying the local Curl executable isn't good enough, because that
+ * may not use the same libcurl that we've been configured with.)

If there is concern over the neatness of this (long term in the backbranches,
for master it will be reverted as mentioned), I guess one option could be to
introduce a new binary, oauth_curl_version, which only prints the version and
exits instead oa adding a flag to an otherwise unrelated binary.  It would add
a little compilation overhead though.

--
Daniel Gustafsson



Re: [oauth] Increased CPU usage during device flow with libcurl 8.20.0

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Jacob Champion  writes:
> Attached as v2-0002, which moves the version check into one of the
> OAuth test executables. (I'll hold 0004 until after REL_19_STABLE is
> branched; it just implements the v1 strategy and reverts 0002.)

> I've tested this against a local Homebrew installation, but if anyone
> who's hit this in the wild has a chance to put 0001-3 through a smoke
> test, that'd be awesome. Barring any objections or bad test results,
> I'll plan to push tomorrow.

I confirm that, with or without 0004, this fixes the oauth_validator
failure on the machine where I saw that.

However ... I don't love the plan of fixing this differently in v19
and v20 just because of feature freeze.  Exposing more information
for testing purposes isn't a user-visible feature IMO, so I would
rather we go straight to 0004.

CC'ing the RMT to see if they agree.  (I think the rmt@ alias is
not functioning, so cc'ing members directly.)

			regards, tom lane


Re: [oauth] Increased CPU usage during device flow with libcurl 8.20.0

От:
Jacob Champion <jacob.champion@enterprisedb.com>
Дата:
On Tue, Jun 16, 2026 at 1:12 PM Daniel Gustafsson  wrote:
> If there is concern over the neatness of this (long term in the backbranches,
> for master it will be reverted as mentioned), I guess one option could be to
> introduce a new binary, oauth_curl_version, which only prints the version and
> exits instead oa adding a flag to an otherwise unrelated binary.  It would add
> a little compilation overhead though.

I considered that, but I think adding a second binary to the existing
Makefile is likely to result in build system churn (to get it to
behave like e.g. test_json_parser/Makefile). I can investigate that
path if you think it'd be more maintainable that way, but let's make
sure Tom's point below doesn't moot it:

On Tue, Jun 16, 2026 at 1:40 PM Tom Lane  wrote:
> I confirm that, with or without 0004, this fixes the oauth_validator
> failure on the machine where I saw that.

Thanks very much!

> However ... I don't love the plan of fixing this differently in v19
> and v20 just because of feature freeze.  Exposing more information
> for testing purposes isn't a user-visible feature IMO, so I would
> rather we go straight to 0004.

Fair enough. If the RMT is okay with this for 19, were you thinking
we'd also backpatch that code directly to 18?

--Jacob


Re: [oauth] Increased CPU usage during device flow with libcurl 8.20.0

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Jacob Champion  writes:
> On Tue, Jun 16, 2026 at 1:40 PM Tom Lane  wrote:
>> However ... I don't love the plan of fixing this differently in v19
>> and v20 just because of feature freeze.  Exposing more information
>> for testing purposes isn't a user-visible feature IMO, so I would
>> rather we go straight to 0004.

> Fair enough. If the RMT is okay with this for 19, were you thinking
> we'd also backpatch that code directly to 18?

Sure.

			regards, tom lane


Re: [oauth] Increased CPU usage during device flow with libcurl 8.20.0

От:
Nathan Bossart <nathandbossart@gmail.com>
Дата:
[RMT hat]

On Tue, Jun 16, 2026 at 05:02:28PM -0400, Tom Lane wrote:
> Jacob Champion  writes:
>> On Tue, Jun 16, 2026 at 1:40 PM Tom Lane  wrote:
>>> However ... I don't love the plan of fixing this differently in v19
>>> and v20 just because of feature freeze.  Exposing more information
>>> for testing purposes isn't a user-visible feature IMO, so I would
>>> rather we go straight to 0004.
> 
>> Fair enough. If the RMT is okay with this for 19, were you thinking
>> we'd also backpatch that code directly to 18?
> 
> Sure.

This seems like a reasonable plan to me.

-- 
nathan


Re: [oauth] Increased CPU usage during device flow with libcurl 8.20.0

От:
Melanie Plageman <melanieplageman@gmail.com>
Дата:
On Wed, Jun 17, 2026 at 11:40 AM Nathan Bossart
 wrote:
>
> >> Fair enough. If the RMT is okay with this for 19, were you thinking
> >> we'd also backpatch that code directly to 18?
> >
> > Sure.
>
> This seems like a reasonable plan to me.

+1


Re: [oauth] Increased CPU usage during device flow with libcurl 8.20.0

От:
Jacob Champion <jacob.champion@enterprisedb.com>
Дата:
On Wed, Jun 17, 2026 at 8:51 AM Melanie Plageman
 wrote:
> On Wed, Jun 17, 2026 at 11:40 AM Nathan Bossart
>  wrote:
>
> > This seems like a reasonable plan to me.
>
> +1

Great, thanks everyone! I've pushed a patchset based on v1, after some
additional testing.

--Jacob


pgsql: Teach psql to skip in-line COPY ... FROM STDIN data after a fail

От:
Noah Misch <noah@leadboat.com>
Дата:
Teach psql to skip in-line COPY ... FROM STDIN data after a failure.

If the COPY command fails before sending PGRES_COPY_IN, psql did
not realize that it ought to consume any in-line data following
the command.  Failing to do so leads to trying to execute that
data as SQL commands, which in the best case is wrong and in the
worst case is a SQL-injection hazard.

To fix:

1. Extend psqlscan.l to recognize COPY ... FROM STDIN.  This can
be done with a pretty simple extension to the logic that already
recognizes nested BEGIN blocks within CREATE FUNCTION et al.
But unlike that case, we need to consider and count multiple COPY
commands within a single query string (separated by "\;").  The
fallout from that is that psql_scan_reset must now always be called
before starting a new query string.  (The comment for it that claimed
we didn't need that because "the scan state must be INITIAL" was
really obsolete already, since it has long reset more state besides
start_state.)

2. Teach handleCopyIn() to read and discard data when passed
NULL for "conn".

3. Add logic to SendQuery() to call handleCopyIn() that way
if the query string contained COPY ... FROM STDIN command(s)
that remain unaccounted-for at the end.

Now that we have this counting logic, we can also detect
if the backend sends an unexpected PGRES_COPY_IN message.
That should never happen, but perhaps a malicious server
could try to extract data that way.

A side-effect of doing this is that we have to adjust a number of test
scripts that thought they needn't write "\." after a COPY FROM STDIN
that they expect to fail.  On the whole this is an improvement, since
there's now a uniform rule "write \. after COPY FROM STDIN, whether
you expect it to work or not".  But it is an annoying amount of test
churn.

A loose end in this patch is that if it has to skip data, it assumes
that that data is text not binary.  It seems unduly difficult to
detect whether the COPY command requested binary (we could handle the
old-style COPY BINARY ... syntax, but not the new style with format
options).  In practice, copying in-line binary data is unsupported
anyway, because there's no way to write an end marker: the textual
terminator sequence "\n\\.\n" could appear in binary data and there's
no provision for escaping it, so neither psql nor the server look for
it when in binary mode.

Reported-by: Alexander Lakhin 
Author: Tom Lane 
Reviewed-by: Noah Misch 
Backpatch-through: 14
Security: CVE-2026-6464

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/46fa1f6f373865fae7553043790cd17944893ac3
Author: Tom Lane 

Modified Files
--------------
src/bin/psql/common.c                | 109 ++++++++++++++--
src/bin/psql/common.h                |   2 +-
src/bin/psql/copy.c                  |  48 ++++---
src/bin/psql/mainloop.c              |  15 ++-
src/bin/psql/psqlscanslash.l         |  18 +--
src/bin/psql/startup.c               |   2 +-
src/fe_utils/psqlscan.l              | 243 ++++++++++++++++++++++++++---------
src/include/fe_utils/psqlscan.h      |   2 +
src/include/fe_utils/psqlscan_int.h  |  15 ++-
src/test/regress/expected/copy.out   |   4 -
src/test/regress/expected/psql.out   |   5 +
src/test/regress/sql/alter_table.sql |   2 +
src/test/regress/sql/copy.sql        |   1 +
src/test/regress/sql/copy2.sql       |  44 +++++++
src/test/regress/sql/copyselect.sql  |   1 +
src/test/regress/sql/generated.sql   |   4 +
src/test/regress/sql/privileges.sql  |   3 +
src/test/regress/sql/psql.sql        |   9 ++
src/test/regress/sql/rowsecurity.sql |   4 +
19 files changed, 413 insertions(+), 118 deletions(-)

FAQ