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

Commit6b4dba7

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 parent533cc39 commit6b4dba7

File tree

7 files changed

+51
-1
lines changed

7 files changed

+51
-1
lines changed

‎configure

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

1333013330

13331-
for ac_header in atomic.h copyfile.h crypt.h fp_class.h getopt.h ieeefp.h ifaddrs.h langinfo.h mbarrier.h poll.h sys/epoll.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 utime.h wchar.h wctype.h
13331+
for ac_header in atomic.h copyfile.h crypt.h fp_class.h getopt.h ieeefp.h ifaddrs.h langinfo.h mbarrier.h poll.h sys/epoll.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 utime.h wchar.h wctype.h
1333213332
do :
1333313333
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
1333413334
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
@@ -1407,6 +1407,7 @@ AC_CHECK_HEADERS(m4_normalize([
14071407
poll.h
14081408
sys/epoll.h
14091409
sys/ipc.h
1410+
sys/personality.h
14101411
sys/prctl.h
14111412
sys/procctl.h
14121413
sys/pstat.h

‎src/bin/pg_ctl/pg_ctl.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,10 @@ start_postmaster(void)
459459
fflush(stdout);
460460
fflush(stderr);
461461

462+
#ifdefEXEC_BACKEND
463+
pg_disable_aslr();
464+
#endif
465+
462466
pm_pid=fork();
463467
if (pm_pid<0)
464468
{

‎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 */
@@ -623,6 +631,31 @@ set_pglocale_pgservice(const char *argv0, const char *app)
623631
}
624632
}
625633

634+
#ifdefEXEC_BACKEND
635+
/*
636+
* For the benefit of PostgreSQL developers testing EXEC_BACKEND on Unix
637+
* systems (code paths normally exercised only on Windows), provide a way to
638+
* disable address space layout randomization, if we know how on this platform.
639+
* Otherwise, backends may fail to attach to shared memory at the fixed address
640+
* chosen by the postmaster. (See also the macOS-specific hack in
641+
* sysv_shmem.c.)
642+
*/
643+
int
644+
pg_disable_aslr(void)
645+
{
646+
#if defined(HAVE_SYS_PERSONALITY_H)
647+
returnpersonality(ADDR_NO_RANDOMIZE);
648+
#elif defined(HAVE_SYS_PROCCTL_H)&& defined(PROC_ASLR_FORCE_DISABLE)
649+
intdata=PROC_ASLR_FORCE_DISABLE;
650+
651+
returnprocctl(P_PID,0,PROC_ASLR_CTL,&data);
652+
#else
653+
errno=ENOSYS;
654+
return-1;
655+
#endif
656+
}
657+
#endif
658+
626659
#ifdefWIN32
627660

628661
/*

‎src/include/pg_config.h.in

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

615+
/* Define to 1 if you have the <sys/personality.h> header file. */
616+
#undef HAVE_SYS_PERSONALITY_H
617+
615618
/* Define to 1 if you have the <sys/prctl.h> header file. */
616619
#undef HAVE_SYS_PRCTL_H
617620

‎src/include/port.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ extern intfind_other_exec(const char *argv0, const char *target,
114114
/* Doesn't belong here, but this is used with find_other_exec(), so... */
115115
#definePG_BACKEND_VERSIONSTR "postgres (PostgreSQL) " PG_VERSION "\n"
116116

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

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

‎src/test/regress/pg_regress.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,10 @@ spawn_process(const char *cmdline)
11751175
if (logfile)
11761176
fflush(logfile);
11771177

1178+
#ifdefEXEC_BACKEND
1179+
pg_disable_aslr();
1180+
#endif
1181+
11781182
pid=fork();
11791183
if (pid==-1)
11801184
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp