Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gcbSf-0003yJ-Dp for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Dec 2018 19:36:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gcbSc-0000r5-Hn for pgsql-hackers@arkaria.postgresql.org; Thu, 27 Dec 2018 19:36:50 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gcbSc-0000qy-7R for pgsql-hackers@lists.postgresql.org; Thu, 27 Dec 2018 19:36:50 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gcbSZ-00058x-O3 for pgsql-hackers@postgresql.org; Thu, 27 Dec 2018 19:36:49 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id wBRJaXvu009704; Thu, 27 Dec 2018 14:36:33 -0500 From: Tom Lane To: Thomas Munro cc: Peter Geoghegan , Michael Paquier , Alvaro Herrera , Adrien Nayrat , Dmitry Dolgov <9erthalion6@gmail.com>, Tomas Vondra , Vik Fearing , Robert Haas , David Rowley , Pg Hackers Subject: Re: random() (was Re: New GUC to sample log queries) In-reply-to: References: <20181129214850.kiq6mvofsgplqjdr@alvherre.pgsql> <3859.1545849900@sss.pgh.pa.us> <20181227013458.GF2106@paquier.xyz> <32696.1545875185@sss.pgh.pa.us> <2820.1545878340@sss.pgh.pa.us> Comments: In-reply-to Thomas Munro message dated "Thu, 27 Dec 2018 17:55:16 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <9702.1545939393.1@sss.pgh.pa.us> Date: Thu, 27 Dec 2018 14:36:33 -0500 Message-ID: <9703.1545939393@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Thomas Munro writes: > On Thu, Dec 27, 2018 at 3:55 PM Peter Geoghegan wrote: >> On Wed, Dec 26, 2018 at 6:39 PM Tom Lane wrote: >>> The point here is not to be cryptographically strong at every single >>> place where the backend might want a random number; I think we're >>> all agreed that we don't need that. To me, the point is to ensure that >>> the user-accessible random sequence is kept separate from internal uses, >>> and the potential security exposure in the new random-logging patch is >>> what justifies getting more worried about this than we were before. > +1, but I wonder if just separating them is enough. Is our seeding > algorithm good enough for this new purpose? The initial seed is 100% > predictable to a logged in user (it's made from the backend PID and > backend start time, which we tell you), and not even that hard to > guess from the outside, so I think Coverity's warning is an > understatement in this case. Even if we separate the PRNG state used > for internal stuff so that users can't clobber its seed from SQL, > wouldn't it be possible to predict which statements will survive the > log sampling filter given easily available information and a good > guess at how many times random() (or whatever similar thing) has been > called so far? Yeah, that's a good point. Maybe we should upgrade the per-process seed initialization to make it less predictable. I could see expending a call of the strong RNG to contribute some more noise to the seeds selected in InitProcessGlobals(). regards, tom lane