diff --git a/contrib/ntp/ntpd/ntpd.c b/contrib/ntp/ntpd/ntpd.c index bcfca27a535..2ed3046c264 100644 --- a/contrib/ntp/ntpd/ntpd.c +++ b/contrib/ntp/ntpd/ntpd.c @@ -790,6 +790,13 @@ ntpdmain( int fd; int zero; # endif + int aslr = 0; + int aslr_len = sizeof(aslr); +#ifdef __LP64__ + char *aslr_var = "kern.elf64.aslr.enable"; +#else + char *aslr_var = "kern.elf32.aslr.enable"; +#endif # ifdef NEED_PTHREAD_WARMUP my_pthread_warmup(); @@ -998,7 +1005,15 @@ ntpdmain( /* Setup stack size in preparation for locking pages in memory. */ # if defined(HAVE_MLOCKALL) # ifdef HAVE_SETRLIMIT - ntp_rlimit(RLIMIT_STACK, DFLT_RLIMIT_STACK * 4096, 4096, "4k"); + + if ((rc = sysctlbyname(aslr_var, aslr, &aslr_len, NULL, 0)) != 0)) + msyslog(LOG_ERR, + "sysctlbyname: %s: %s", + aslr_var, + strerror(rc)); + + if (aslr == 0) + ntp_rlimit(RLIMIT_STACK, DFLT_RLIMIT_STACK * 4096, 4096, "4k"); # if defined(RLIMIT_MEMLOCK) && defined(DFLT_RLIMIT_MEMLOCK) && DFLT_RLIMIT_MEMLOCK != -1 /* * The default RLIMIT_MEMLOCK is very low on Linux systems.