File tree Expand file tree Collapse file tree 8 files changed +52
-1
lines changed
Filter options
Expand file tree Collapse file tree 8 files changed +52
-1
lines changed
Original file line number Diff line number Diff line change @@ -13603,7 +13603,7 @@ $as_echo "#define HAVE_STDBOOL_H 1" >>confdefs.h
13603
13603
fi
13604
13604
13605
13605
13606
- for ac_header in atomic.h copyfile.h execinfo.h getopt.h ifaddrs.h langinfo.h mbarrier.h poll.h sys/epoll.h sys/event.h sys/ipc.h sys/prctl.h sys/procctl.h sys/pstat.h sys/resource.h sys/select.h sys/sem.h sys/shm.h sys/sockio.h sys/tas.h sys/uio.h sys/un.h termios.h ucred.h wctype.h
13606
+ for ac_header in atomic.h copyfile.h execinfo.h getopt.h ifaddrs.h langinfo.h mbarrier.h poll.h sys/epoll.h sys/event.h sys/ipc.h sys/personality.h sys/ prctl.h sys/procctl.h sys/pstat.h sys/resource.h sys/select.h sys/sem.h sys/shm.h sys/sockio.h sys/tas.h sys/uio.h sys/un.h termios.h ucred.h wctype.h
13607
13607
do :
13608
13608
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
13609
13609
ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
Original file line number Diff line number Diff line change @@ -1404,6 +1404,7 @@ AC_CHECK_HEADERS(m4_normalize([
1404
1404
sys/epoll.h
1405
1405
sys/event.h
1406
1406
sys/ipc.h
1407
+ sys/personality.h
1407
1408
sys/prctl.h
1408
1409
sys/procctl.h
1409
1410
sys/pstat.h
Original file line number Diff line number Diff line change @@ -451,6 +451,10 @@ start_postmaster(void)
451
451
fflush (stdout );
452
452
fflush (stderr );
453
453
454
+ #ifdef EXEC_BACKEND
455
+ pg_disable_aslr ();
456
+ #endif
457
+
454
458
pm_pid = fork ();
455
459
if (pm_pid < 0 )
456
460
{
Original file line number Diff line number Diff line change 25
25
#include <sys/wait.h>
26
26
#include <unistd.h>
27
27
28
+ #ifdef EXEC_BACKEND
29
+ #if defined(HAVE_SYS_PERSONALITY_H )
30
+ #include <sys/personality.h>
31
+ #elif defined(HAVE_SYS_PROCCTL_H )
32
+ #include <sys/procctl.h>
33
+ #endif
34
+ #endif
35
+
28
36
/*
29
37
* Hacky solution to allow expressing both frontend and backend error reports
30
38
* in one macro call. First argument of log_error is an errcode() call of
@@ -470,6 +478,31 @@ set_pglocale_pgservice(const char *argv0, const char *app)
470
478
}
471
479
}
472
480
481
+ #ifdef EXEC_BACKEND
482
+ /*
483
+ * For the benefit of PostgreSQL developers testing EXEC_BACKEND on Unix
484
+ * systems (code paths normally exercised only on Windows), provide a way to
485
+ * disable address space layout randomization, if we know how on this platform.
486
+ * Otherwise, backends may fail to attach to shared memory at the fixed address
487
+ * chosen by the postmaster. (See also the macOS-specific hack in
488
+ * sysv_shmem.c.)
489
+ */
490
+ int
491
+ pg_disable_aslr (void )
492
+ {
493
+ #if defined(HAVE_SYS_PERSONALITY_H )
494
+ return personality (ADDR_NO_RANDOMIZE );
495
+ #elif defined(HAVE_SYS_PROCCTL_H ) && defined(PROC_ASLR_FORCE_DISABLE )
496
+ int data = PROC_ASLR_FORCE_DISABLE ;
497
+
498
+ return procctl (P_PID , 0 , PROC_ASLR_CTL , & data );
499
+ #else
500
+ errno = ENOSYS ;
501
+ return -1 ;
502
+ #endif
503
+ }
504
+ #endif
505
+
473
506
#ifdef WIN32
474
507
475
508
/*
Original file line number Diff line number Diff line change 614
614
/* Define to 1 if you have the <sys/ipc.h> header file. */
615
615
#undef HAVE_SYS_IPC_H
616
616
617
+ /* Define to 1 if you have the <sys/personality.h> header file. */
618
+ #undef HAVE_SYS_PERSONALITY_H
619
+
617
620
/* Define to 1 if you have the <sys/prctl.h> header file. */
618
621
#undef HAVE_SYS_PRCTL_H
619
622
Original file line number Diff line number Diff line change @@ -140,6 +140,11 @@ extern char *pipe_read_line(char *cmd, char *line, int maxsize);
140
140
/* Doesn't belong here, but this is used with find_other_exec(), so... */
141
141
#define PG_BACKEND_VERSIONSTR "postgres (PostgreSQL) " PG_VERSION "\n"
142
142
143
+ #ifdef EXEC_BACKEND
144
+ /* Disable ASLR before exec, for developer builds only (in exec.c) */
145
+ extern int pg_disable_aslr (void );
146
+ #endif
147
+
143
148
144
149
#if defined(WIN32 ) || defined(__CYGWIN__ )
145
150
#define EXE ".exe"
Original file line number Diff line number Diff line change @@ -1104,6 +1104,10 @@ spawn_process(const char *cmdline)
1104
1104
if (logfile )
1105
1105
fflush (logfile );
1106
1106
1107
+ #ifdef EXEC_BACKEND
1108
+ pg_disable_aslr ();
1109
+ #endif
1110
+
1107
1111
pid = fork ();
1108
1112
if (pid == -1 )
1109
1113
{
Original file line number Diff line number Diff line change @@ -397,6 +397,7 @@ sub GenerateFiles
397
397
HAVE_SYS_EPOLL_H => undef ,
398
398
HAVE_SYS_EVENT_H => undef ,
399
399
HAVE_SYS_IPC_H => undef ,
400
+ HAVE_SYS_PERSONALITY_H => undef ,
400
401
HAVE_SYS_PRCTL_H => undef ,
401
402
HAVE_SYS_PROCCTL_H => undef ,
402
403
HAVE_SYS_PSTAT_H => undef ,
You can’t perform that action at this time.
0 commit comments