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: Prevent integer overflows in array subscripting calculations.
Date: Mon, 10 May 2021 14:45:04 +0000
Message-ID: <E1lg79c-0004TS-4i@gemulon.postgresql.org> (raw)

Prevent integer overflows in array subscripting calculations.

While we were (mostly) careful about ensuring that the dimensions of
arrays aren't large enough to cause integer overflow, the lower bound
values were generally not checked.  This allows situations where
lower_bound + dimension overflows an integer.  It seems that that's
harmless so far as array reading is concerned, except that array
elements with subscripts notionally exceeding INT_MAX are inaccessible.
However, it confuses various array-assignment logic, resulting in a
potential for memory stomps.

Fix by adding checks that array lower bounds aren't large enough to
cause lower_bound + dimension to overflow.  (Note: this results in
disallowing cases where the last subscript position would be exactly
INT_MAX.  In principle we could probably allow that, but there's a lot
of code that computes lower_bound + dimension and would need adjustment.
It seems doubtful that it's worth the trouble/risk to allow it.)

Somewhat independently of that, array_set_element() was careless
about possible overflow when checking the subscript of a fixed-length
array, creating a different route to memory stomps.  Fix that too.

Security: CVE-2021-32027

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/467395bfdf33f1ccf67ca388ffdcc927271544cb

Modified Files
--------------
src/backend/executor/execExprInterp.c   |  4 ++++
src/backend/utils/adt/array_userfuncs.c |  1 +
src/backend/utils/adt/arrayfuncs.c      | 40 ++++++++++++++++++++-------------
src/backend/utils/adt/arrayutils.c      | 31 +++++++++++++++++++++++++
src/include/utils/array.h               |  1 +
5 files changed, 61 insertions(+), 16 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1lg79c-0004TS-4i@gemulon.postgresql.org>
Permalink:  ../E1lg79c-0004TS-4i@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1lg79c-0004TS-4i@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: Prevent integer overflows in array subscripting calculations.
  In-Reply-To: <E1lg79c-0004TS-4i@gemulon.postgresql.org>
  References: <E1lg79c-0004TS-4i@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