pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Add safeguards for pg_fsync() called with incorrectly-opened fds
Date: Tue, 26 Nov 2019 04:33:42 +0000
Message-ID: <E1iZSXm-0008Mn-Rs@gemulon.postgresql.org> (raw)

Add safeguards for pg_fsync() called with incorrectly-opened fds

On some platforms, fsync() returns EBADFD when opening a file descriptor
with O_RDONLY (read-only), leading ultimately now to a PANIC to prevent
data corruption.

This commit adds a new sanity check in pg_fsync() based on fcntl() to
make sure that we don't repeat again mistakes with incorrectly-set file
descriptors so as problems are detected at an early stage.  Without
that, such errors could only be detected after running Postgres on a
specific supported platform for the culprit code path, which could take
some time before being found.  b8e19b93 was a fix for such a problem,
which got undetected for more than 5 years, and a586cc4b fixed another
similar issue.

Note that the new check added works as well when fsync=off is
configured, so as all regression tests would detect problems as long as
assertions are enabled.  fcntl() being not available on Windows, the
new checks do not happen there.

Author: Michael Paquier
Reviewed-by: Mark Dilger
Discussion: https://postgr.es/m/20191009062640.GB21379@paquier.xyz

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/12198239c0a5122e29619d50f76f89adc5bc7ade

Modified Files
--------------
src/backend/storage/file/fd.c | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)



Message-ID: <E1iZSXm-0008Mn-Rs@gemulon.postgresql.org>
Permalink:  ../E1iZSXm-0008Mn-Rs@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1iZSXm-0008Mn-Rs@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: michael@paquier.xyz
  Subject: Re: pgsql: Add safeguards for pg_fsync() called with incorrectly-opened fds
  In-Reply-To: <E1iZSXm-0008Mn-Rs@gemulon.postgresql.org>
  References: <E1iZSXm-0008Mn-Rs@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