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

Commit0801345

Browse files
committed
Make EXEC_BACKEND more convenient on Linux and FreeBSD.
Try to disable ASLR when building in EXEC_BACKEND mode, to avoid randommemory mapping failures while testing. For developer use only, noeffect on regular builds.This has been originally applied as off3e7806 for v15~, butrecently-added buildfarm member gokiburi tests this configuration onolder branches as well, causing it to fail randomly as ASLR would beenabled.Suggested-by: Andres Freund <andres@anarazel.de>Tested-by: Bossart, Nathan <bossartn@amazon.com>Discussion:https://postgr.es/m/20210806032944.m4tz7j2w47mant26%40alap3.anarazel.deBackpatch-through: 12
1 parente4c4e62 commit0801345

File tree

8 files changed

+52
-1
lines changed

8 files changed

+52
-1
lines changed

‎configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13781,7 +13781,7 @@ $as_echo "#define HAVE_STDBOOL_H 1" >>confdefs.h
1378113781
fi
1378213782

1378313783

13784-
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/signalfd.h sys/sockio.h sys/tas.h sys/uio.h sys/un.h termios.h ucred.h wctype.h
13784+
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/signalfd.h sys/sockio.h sys/tas.h sys/uio.h sys/un.h termios.h ucred.h wctype.h
1378513785
do :
1378613786
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
1378713787
ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"

‎configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,7 @@ AC_CHECK_HEADERS(m4_normalize([
14241424
sys/epoll.h
14251425
sys/event.h
14261426
sys/ipc.h
1427+
sys/personality.h
14271428
sys/prctl.h
14281429
sys/procctl.h
14291430
sys/pstat.h

‎src/bin/pg_ctl/pg_ctl.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,10 @@ start_postmaster(void)
453453
fflush(stdout);
454454
fflush(stderr);
455455

456+
#ifdefEXEC_BACKEND
457+
pg_disable_aslr();
458+
#endif
459+
456460
pm_pid=fork();
457461
if (pm_pid<0)
458462
{

‎src/common/exec.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
#include<sys/wait.h>
2626
#include<unistd.h>
2727

28+
#ifdefEXEC_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+
2836
/* Inhibit mingw CRT's auto-globbing of command line arguments */
2937
#if defined(WIN32)&& !defined(_MSC_VER)
3038
externint_CRT_glob=0;/* 0 turns off globbing; 1 turns it on */
@@ -475,6 +483,31 @@ set_pglocale_pgservice(const char *argv0, const char *app)
475483
}
476484
}
477485

486+
#ifdefEXEC_BACKEND
487+
/*
488+
* For the benefit of PostgreSQL developers testing EXEC_BACKEND on Unix
489+
* systems (code paths normally exercised only on Windows), provide a way to
490+
* disable address space layout randomization, if we know how on this platform.
491+
* Otherwise, backends may fail to attach to shared memory at the fixed address
492+
* chosen by the postmaster. (See also the macOS-specific hack in
493+
* sysv_shmem.c.)
494+
*/
495+
int
496+
pg_disable_aslr(void)
497+
{
498+
#if defined(HAVE_SYS_PERSONALITY_H)
499+
returnpersonality(ADDR_NO_RANDOMIZE);
500+
#elif defined(HAVE_SYS_PROCCTL_H)&& defined(PROC_ASLR_FORCE_DISABLE)
501+
intdata=PROC_ASLR_FORCE_DISABLE;
502+
503+
returnprocctl(P_PID,0,PROC_ASLR_CTL,&data);
504+
#else
505+
errno=ENOSYS;
506+
return-1;
507+
#endif
508+
}
509+
#endif
510+
478511
#ifdefWIN32
479512

480513
/*

‎src/include/pg_config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,9 @@
619619
/* Define to 1 if you have the <sys/ipc.h> header file. */
620620
#undef HAVE_SYS_IPC_H
621621

622+
/* Define to 1 if you have the <sys/personality.h> header file. */
623+
#undef HAVE_SYS_PERSONALITY_H
624+
622625
/* Define to 1 if you have the <sys/prctl.h> header file. */
623626
#undef HAVE_SYS_PRCTL_H
624627

‎src/include/port.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ extern char *pipe_read_line(char *cmd, char *line, int maxsize);
138138
/* Doesn't belong here, but this is used with find_other_exec(), so... */
139139
#definePG_BACKEND_VERSIONSTR "postgres (PostgreSQL) " PG_VERSION "\n"
140140

141+
#ifdefEXEC_BACKEND
142+
/* Disable ASLR before exec, for developer builds only (in exec.c) */
143+
externintpg_disable_aslr(void);
144+
#endif
145+
141146

142147
#if defined(WIN32)|| defined(__CYGWIN__)
143148
#defineEXE ".exe"

‎src/test/regress/pg_regress.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,10 @@ spawn_process(const char *cmdline)
12071207
if (logfile)
12081208
fflush(logfile);
12091209

1210+
#ifdefEXEC_BACKEND
1211+
pg_disable_aslr();
1212+
#endif
1213+
12101214
pid=fork();
12111215
if (pid==-1)
12121216
{

‎src/tools/msvc/Solution.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ sub GenerateFiles
399399
HAVE_SYS_EPOLL_H=>undef,
400400
HAVE_SYS_EVENT_H=>undef,
401401
HAVE_SYS_IPC_H=>undef,
402+
HAVE_SYS_PERSONALITY_H=>undef,
402403
HAVE_SYS_PRCTL_H=>undef,
403404
HAVE_SYS_PROCCTL_H=>undef,
404405
HAVE_SYS_PSTAT_H=>undef,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp