Use pg_strong_random() to select each server process's random seed.
authorTom Lane <[email protected]>
Sat, 29 Dec 2018 22:56:06 +0000 (17:56 -0500)
committerTom Lane <[email protected]>
Sat, 29 Dec 2018 22:56:06 +0000 (17:56 -0500)
commit4203842a1cd06a7c30fd3eaae1c111928909e539
tree8246cbeeba4e6d3deadfe585d3e736b2dfd20838
parent6645ad6bdd81e7d5a764e0d94ef52fae053a9e13
Use pg_strong_random() to select each server process's random seed.

Previously we just set the seed based on process ID and start timestamp.
Both those values are directly available within the session, and can
be found out or guessed by other users too, making the session's series
of random(3) values fairly predictable.  Up to now, our backend-internal
uses of random(3) haven't seemed security-critical, but commit 88bdbd3f7
added one that potentially is: when using log_statement_sample_rate, a
user might be able to predict which of his SQL statements will get logged.

To improve this situation, upgrade the per-process seed initialization
method to use pg_strong_random() if available, greatly reducing the
predictability of the initial seed value.  This adds a few tens of
microseconds to process start time, but since backend startup time is
at least a couple of milliseconds, that seems an acceptable price.

This means that pg_strong_random() needs to be able to run without
reliance on any backend infrastructure, since it will be invoked
before any of that is up.  It was safe for that already, but adjust
comments and #include commands to make it clearer.

Discussion: https://postgr.es/m/3859.1545849900@sss.pgh.pa.us
src/backend/postmaster/postmaster.c
src/port/pg_strong_random.c