Bug 253208 - ntpd: fails to start with PIE
Summary: ntpd: fails to start with PIE
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 13.0-STABLE
Hardware: Any Any
: --- Affects Some People
Assignee: Cy Schubert
Depends on:
Reported: 2021-02-03 11:07 UTC by Evgeniy Khramtsov
Modified: 2021-04-28 14:38 UTC (History)
4 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Evgeniy Khramtsov 2021-02-03 11:07:08 UTC
If one builds FreeBSD with:

and sets sysctls:

ntpd will not start:

pid 63899 (ntpd), jid 0, uid 123: exited on signal 11

A workaround is to disable ASLR stack gap:

elfctl -e +noaslrstkgap /usr/sbin/ntpd
Comment 1 mw 2021-02-26 18:26:12 UTC
We will take a closer look at this issue.
Comment 2 Cy Schubert freebsd_committer 2021-04-27 13:57:29 UTC
Can you post the ntp entries from your rc.conf, please. Also the kern.elf64.aslr and the kern.elf32.aslr sysctl MIBs.

grep ntp /etc/rc.conf
sysctl kern.elf64.aslr kern.elf32.aslr

And post the output here.
Comment 3 Evgeniy Khramtsov 2021-04-27 15:32:17 UTC
(In reply to Cy Schubert from comment #2)

I no longer use it, but I restored the old config from backup:

$ grep ntp /etc/rc.conf

$ sysctl kern.elf64.aslr kern.elf32.aslr
kern.elf64.aslr.stack_gap: 3
kern.elf64.aslr.honor_sbrk: 0
kern.elf64.aslr.pie_enable: 1
kern.elf64.aslr.enable: 1
sysctl: unknown oid 'kern.elf32.aslr'

(local kernel no 32-bit)

Still reproducible on main-n246330.
Comment 4 Cy Schubert freebsd_committer 2021-04-27 17:19:21 UTC
main-246330 is this commit.

commit f85ed1249773383bf80cb095b827860d80514339
Author: Andriy Gapon <avg@FreeBSD.org>
Date:   Mon Feb 4 21:50:55 2013 +0000

    ktr: copy content from the early static buffer if KTR_ENTRIES !=
    Reported by:    glebius, jhb
    Pointyhat to:   avg
    MFC after:      14 days
    X-MFC with:     r246282

    svn path=/head/; revision=246330

I think you mean something else. Can you please provide the complete uname -a output. There should be GIT hash after the n246330. The n246330 means nothing whereas the hash number will tell us the GIT commit. Uname -a please.
Comment 5 Evgeniy Khramtsov 2021-04-27 17:23:24 UTC
(In reply to Cy Schubert from comment #4)

Sorry. Commit 5eb9c93a20d7320b24635ed09eba4908951bdeb2 and some local netinet6 patches.

FreeBSD vax.khramtsov.org 14.0-CURRENT FreeBSD 14.0-CURRENT #0 main-n246330-5eb9c93a20d-dirty: Mon Apr 26 20:04:38 MSK 2021     ei@vax.khramtsov.org:/usr/obj/usr/src/amd64.amd64/sys/VAX  amd64
Comment 6 Cy Schubert freebsd_committer 2021-04-27 18:43:51 UTC
Ok, I can finally reproduce the problem with kern.elf64.aslr.pie_enable=1. It's not the stack gap but PIE.

Adjusting the stack to 200 from the default 50, just like OpenBSD does, resolves this issue.

The question now is, do we adjust it globally or only when PIE is enabled. I've reached out to the folks at nwtime.org for their input.
Comment 7 Cy Schubert freebsd_committer 2021-04-27 20:53:43 UTC
As a workaround, until I can bake this into ntp (base and port), please put this at the bottom of your /etc/ntp.conf:

rlimit stacksize 200
Comment 8 Evgeniy Khramtsov 2021-04-27 21:17:56 UTC
(In reply to Cy Schubert from comment #7)

Thanks. I can still reproduce this, even with larger values like '2000' or '20000'.
Comment 9 Evgeniy Khramtsov 2021-04-27 21:24:31 UTC
(In reply to Evgeniy Khramtsov from comment #8)

Anything else to include or look for?
Comment 10 Cy Schubert freebsd_committer 2021-04-27 22:53:22 UTC
So far the only way to resolve this when PIE is enabled, regardless whether the ASLR sysctl is or is not is,

elfctl -e +noaslrstkgap /usr/sbin/ntpd