Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit93528f7

Browse files
committed
Avoid using PostmasterRandom() for DSM control segment ID.
Commits470d886 et al intended to fix the problem that the postmasterselected the same "random" DSM control segment ID on every start. Butusing PostmasterRandom() for that destroys the intended property that thedelay between random_start_time and random_stop_time will be unpredictable.(Said delay is probably already more predictable than we could wish, butthat doesn't mean that reducing it by a couple orders of magnitude is OK.)Revert the previous patch and add a comment warning against misuse ofPostmasterRandom. Fix the original problem by calling srandom() early inPostmasterMain, using a low-security seed that will later be overwrittenby PostmasterRandom.Discussion: <20789.1474390434@sss.pgh.pa.us>
1 parentc359178 commit93528f7

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

‎src/backend/postmaster/postmaster.c‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ static void processCancelRequest(Port *port, void *pkt);
399399
staticintinitMasks(fd_set*rmask);
400400
staticvoidreport_fork_failure_to_client(Port*port,interrnum);
401401
staticCAC_statecanAcceptConnections(void);
402+
staticlongPostmasterRandom(void);
402403
staticvoidRandomSalt(char*md5Salt);
403404
staticvoidsignal_child(pid_tpid,intsignal);
404405
staticboolSignalSomeChildren(intsignal,inttargets);
@@ -568,6 +569,16 @@ PostmasterMain(int argc, char *argv[])
568569
*/
569570
umask(S_IRWXG |S_IRWXO);
570571

572+
/*
573+
* Initialize random(3) so we don't get the same values in every run.
574+
*
575+
* Note: the seed is pretty predictable from externally-visible facts such
576+
* as postmaster start time, so avoid using random() for security-critical
577+
* random values during postmaster startup. At the time of first
578+
* connection, PostmasterRandom will select a hopefully-more-random seed.
579+
*/
580+
srandom((unsignedint) (MyProcPid ^MyStartTime));
581+
571582
/*
572583
* By default, palloc() requests in the postmaster will be allocated in
573584
* the PostmasterContext, which is space that can be recycled by backends.
@@ -5075,8 +5086,12 @@ RandomSalt(char *md5Salt)
50755086

50765087
/*
50775088
* PostmasterRandom
5089+
*
5090+
* Caution: use this only for values needed during connection-request
5091+
* processing. Otherwise, the intended property of having an unpredictable
5092+
* delay between random_start_time and random_stop_time will be broken.
50785093
*/
5079-
long
5094+
staticlong
50805095
PostmasterRandom(void)
50815096
{
50825097
/*

‎src/backend/storage/ipc/dsm.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
#include"lib/ilist.h"
3838
#include"miscadmin.h"
39-
#include"postmaster/postmaster.h"
4039
#include"storage/dsm.h"
4140
#include"storage/ipc.h"
4241
#include"storage/lwlock.h"
@@ -180,7 +179,7 @@ dsm_postmaster_startup(PGShmemHeader *shim)
180179
{
181180
Assert(dsm_control_address==NULL);
182181
Assert(dsm_control_mapped_size==0);
183-
dsm_control_handle=(dsm_handle)PostmasterRandom();
182+
dsm_control_handle=random();
184183
if (dsm_control_handle==0)
185184
continue;
186185
if (dsm_impl_op(DSM_OP_CREATE,dsm_control_handle,segsize,

‎src/include/postmaster/postmaster.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ extern const char *progname;
4848

4949
externvoidPostmasterMain(intargc,char*argv[])pg_attribute_noreturn();
5050
externvoidClosePostmasterPorts(boolam_syslogger);
51-
externlongPostmasterRandom(void);
5251

5352
externintMaxLivePostmasterChildren(void);
5453

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp