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

Commit1e4fda6

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 parent20aba55 commit1e4fda6

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
@@ -13363,7 +13363,7 @@ $as_echo "#define HAVE_STDBOOL_H 1" >>confdefs.h
1336313363
fi
1336413364

1336513365

13366-
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/un.h termios.h ucred.h wctype.h
13366+
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/un.h termios.h ucred.h wctype.h
1336713367
do :
1336813368
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
1336913369
ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"

‎configure.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,7 @@ AC_CHECK_HEADERS(m4_normalize([
13771377
sys/epoll.h
13781378
sys/event.h
13791379
sys/ipc.h
1380+
sys/personality.h
13801381
sys/prctl.h
13811382
sys/procctl.h
13821383
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 */
@@ -492,6 +500,31 @@ set_pglocale_pgservice(const char *argv0, const char *app)
492500
}
493501
}
494502

503+
#ifdefEXEC_BACKEND
504+
/*
505+
* For the benefit of PostgreSQL developers testing EXEC_BACKEND on Unix
506+
* systems (code paths normally exercised only on Windows), provide a way to
507+
* disable address space layout randomization, if we know how on this platform.
508+
* Otherwise, backends may fail to attach to shared memory at the fixed address
509+
* chosen by the postmaster. (See also the macOS-specific hack in
510+
* sysv_shmem.c.)
511+
*/
512+
int
513+
pg_disable_aslr(void)
514+
{
515+
#if defined(HAVE_SYS_PERSONALITY_H)
516+
returnpersonality(ADDR_NO_RANDOMIZE);
517+
#elif defined(HAVE_SYS_PROCCTL_H)&& defined(PROC_ASLR_FORCE_DISABLE)
518+
intdata=PROC_ASLR_FORCE_DISABLE;
519+
520+
returnprocctl(P_PID,0,PROC_ASLR_CTL,&data);
521+
#else
522+
errno=ENOSYS;
523+
return-1;
524+
#endif
525+
}
526+
#endif
527+
495528
#ifdefWIN32
496529

497530
/*

‎src/include/pg_config.h.in

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

593+
/* Define to 1 if you have the <sys/personality.h> header file. */
594+
#undef HAVE_SYS_PERSONALITY_H
595+
593596
/* Define to 1 if you have the <sys/prctl.h> header file. */
594597
#undef HAVE_SYS_PRCTL_H
595598

‎src/include/port.h

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

118+
#ifdefEXEC_BACKEND
119+
/* Disable ASLR before exec, for developer builds only (in exec.c) */
120+
externintpg_disable_aslr(void);
121+
#endif
122+
118123

119124
#if defined(WIN32)|| defined(__CYGWIN__)
120125
#defineEXE ".exe"

‎src/test/regress/pg_regress.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,10 @@ spawn_process(const char *cmdline)
11911191
if (logfile)
11921192
fflush(logfile);
11931193

1194+
#ifdefEXEC_BACKEND
1195+
pg_disable_aslr();
1196+
#endif
1197+
11941198
pid=fork();
11951199
if (pid==-1)
11961200
{

‎src/tools/msvc/Solution.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ sub GenerateFiles
380380
HAVE_SYS_EPOLL_H=>undef,
381381
HAVE_SYS_EVENT_H=>undef,
382382
HAVE_SYS_IPC_H=>undef,
383+
HAVE_SYS_PERSONALITY_H=>undef,
383384
HAVE_SYS_PRCTL_H=>undef,
384385
HAVE_SYS_PROCCTL_H=>undef,
385386
HAVE_SYS_PSTAT_H=>undef,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp