Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 756316 - sys-libs/glibc-2.32-r3: SIGSEGV on adjtime(NULL,...) (was: net-misc/openntpd-6.2_p3-r2 segfaults on start on x86)
Summary: sys-libs/glibc-2.32-r3: SIGSEGV on adjtime(NULL,...) (was: net-misc/openntpd-...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Toolchain Maintainers
URL: https://sourceware.org/PR26833
Whiteboard:
Keywords: PATCH
Depends on:
Blocks:
 
Reported: 2020-11-24 12:52 UTC by Tobias Leupold
Modified: 2021-01-03 13:29 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
'strace' of failing OpenNTPD process (strace.gz,7.30 KB, application/gzip)
2020-12-01 07:10 UTC, Wade Cline
Details
Patch for bug in glibc function adjtime (glibc-2.32-r2_adjtime.patch,845 bytes, patch)
2020-12-03 01:43 UTC, acmondor
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Leupold 2020-11-24 12:52:42 UTC
When trying to start openntpd on both of my old x86 notebook, I get a segfault.

dmesg says:

[   37.611808] ntpd[3107]: segfault at 4 ip b7d2df5a sp bfe435a0 error 4 in libc-2.32.so[b7c8b000+164000]
[   37.611830] Code: 29 06 00 8d b4 26 00 00 00 00 8d b6 00 00 00 00 53 8d 64 24 b8 8b 44 24 50 8b 5c 24 54 65 8b 0d 14 00 00 00 89 4c 24 3c 31 c9 <8b> 50 04 8b 00 89 44 24 1c 89 54 24 24 c1 f8 1f c1 fa 1f 85 db 89

Rebuilding glibc and openntpd didn't change this.

Here's emerge --info:

Portage 3.0.8 (python 3.7.9-final-0, default/linux/x86/17.0/desktop, gcc-9.3.0, glibc-2.32-r2, 5.4.48-gentoo i686)
=================================================================
System uname: Linux-5.4.48-gentoo-i686-Genuine_Intel-R-_CPU_T2080_@_1.73GHz-with-gentoo-2.7
KiB Mem:     1016224 total,    385812 free
KiB Swap:    1951892 total,   1889120 free
Timestamp of repository gentoo: Thu, 05 Nov 2020 20:00:01 +0000
Head commit of repository gentoo: aaacc1a3cc8be5fbb598c34da76d7cd195e647b2
sh bash 5.0_p18
ld GNU ld (Gentoo 2.33.1 p2) 2.33.1
distcc 3.3.3 i686-pc-linux-gnu [enabled]
app-shells/bash:          5.0_p18::gentoo
dev-lang/perl:            5.30.3::gentoo
dev-lang/python:          2.7.18-r4::gentoo, 3.7.9::gentoo, 3.8.5::gentoo
dev-util/cmake:           3.17.4-r1::gentoo
dev-util/pkgconfig:       0.29.2::gentoo
sys-apps/baselayout:      2.7::gentoo
sys-apps/openrc:          0.42.1::gentoo
sys-apps/sandbox:         2.20::gentoo
sys-devel/autoconf:       2.13-r1::gentoo, 2.69-r5::gentoo
sys-devel/automake:       1.16.1-r1::gentoo
sys-devel/binutils:       2.33.1-r1::gentoo, 2.34-r2::gentoo
sys-devel/gcc:            9.3.0-r1::gentoo
sys-devel/gcc-config:     2.3.2::gentoo
sys-devel/libtool:        2.4.6-r6::gentoo
sys-devel/make:           4.2.1-r4::gentoo
sys-kernel/linux-headers: 5.4-r1::gentoo (virtual/os-headers)
sys-libs/glibc:           2.32-r2::gentoo
Repositories:

gentoo
    location: /var/portage/tree
    sync-type: rsync
    sync-uri: rsync://rsync.europe.gentoo.org/gentoo-portage
    priority: -1000
    sync-rsync-extra-opts: 
    sync-rsync-verify-jobs: 1
    sync-rsync-verify-metamanifest: yes
    sync-rsync-verify-max-age: 24

local
    location: /var/portage/local
    masters: gentoo
    priority: 0

ACCEPT_KEYWORDS="x86"
ACCEPT_LICENSE="@FREE"
CBUILD="i686-pc-linux-gnu"
CFLAGS="-march=pentium-m -mavx256-split-unaligned-load -mavx256-split-unaligned-store -mno-accumulate-outgoing-args -mno-sahf -msse3 -mtune=generic --param l1-cache-line-size=64 --param l1-cache-size=32 --param l2-cache-size=1024 -O2 -pipe -fomit-frame-pointer"
CHOST="i686-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/config /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-march=pentium-m -mavx256-split-unaligned-load -mavx256-split-unaligned-store -mno-accumulate-outgoing-args -mno-sahf -msse3 -mtune=generic --param l1-cache-line-size=64 --param l1-cache-size=32 --param l2-cache-size=1024 -O2 -pipe -fomit-frame-pointer"
DISTDIR="/var/portage/distfiles"
ENV_UNSET="CARGO_HOME DBUS_SESSION_BUS_ADDRESS DISPLAY GOBIN GOPATH PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR"
FCFLAGS="-O2 -march=i686 -pipe"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs config-protect-if-modified distcc distlocks ebuild-locks fixlafiles ipc-sandbox merge-sync multilib-strict network-sandbox news parallel-fetch pid-sandbox preserve-libs protect-owned qa-unresolved-soname-deps sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-O2 -march=i686 -pipe"
GENTOO_MIRRORS="        http://ftp.uni-erlangen.de/pub/mirrors/gentoo   http://linux.rz.ruhr-uni-bochum.de/download/gentoo-mirror/  http://ftp.belnet.be/mirror/rsync.gentoo.org/gentoo/ "
LANG="de_DE.UTF-8"
LC_ALL="de_DE.UTF-8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
LINGUAS="de"
MAKEOPTS="-j3"
PKGDIR="/var/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
PORTAGE_TMPDIR="/var/tmp"
USE="X a52 aac acl acpi alsa berkdb bluetooth branding bzip2 cairo cdda cdr cli crypt cups dbus dri dts dvd dvdr elogind emboss encode exif flac fortran gdbm gif gpm gtk gui iconv icu ipv6 jpeg lcms libglvnd libnotify libtirpc mad mng mp3 mp4 mpeg ncurses nls nptl ogg opengl openmp pam pango pcre pdf png policykit ppds qt5 readline sdl seccomp spell split-usr ssl startup-notification svg tcpd tiff truetype udev udisks unicode upower usb vorbis wxwidgets x264 x86 xattr xcb xml xv xvid zlib" ABI_X86="32" ADA_TARGET="gnat_2018" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1 emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="karbon sheets words" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="mmx mmxext sse sse2 sse3" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock greis isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="libinput" KERNEL="linux" L10N="de de_DE" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LUA_SINGLE_TARGET="lua5-1" LUA_TARGETS="lua5-1" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php7-2 php7-3 php7-4" POSTGRES_TARGETS="postgres10 postgres11" PYTHON_SINGLE_TARGET="python3_7" PYTHON_TARGETS="python2_7 python3_7" RUBY_TARGETS="ruby25 ruby26" USERLAND="GNU" VIDEO_CARDS="intel i915" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CC, CPPFLAGS, CTARGET, CXX, EMERGE_DEFAULT_OPTS, INSTALL_MASK, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 1 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2020-11-24 12:55:07 UTC
Able to get a gdb backtrace? (https://wiki.gentoo.org/wiki/Debugging)
Comment 2 Tobias Leupold 2020-11-24 17:17:47 UTC
This seems to be a bit complicated (although I'm not super fit with gdb), as the daemon forks:

    (gdb) run
    Starting program: /usr/sbin/ntpd -d
    [Detaching after fork from child process 3389]
    ntp engine ready
    Terminating
    [Inferior 1 (process 3385) exited normally]

I also tried this one, but it seems to be not really better:

    (gdb) set follow-fork-mode child
    (gdb) run
    Starting program: /usr/sbin/ntpd -d
    [Attaching after process 3395 fork to child process 3399]
    [New inferior 2 (process 3399)]
    [Detaching after fork from parent process 3395]
    [Inferior 1 (process 3395) detached]
    process 3399 is executing new program: /usr/sbin/ntpd
    [Attaching after process 3399 fork to child process 3400]
    [New inferior 3 (process 3400)]
    [Detaching after fork from parent process 3399]
    [Inferior 2 (process 3399) detached]
    ntp engine ready
    process 3400 is executing new program: /usr/sbin/ntpd
    Terminating
    [Inferior 3 (process 3400) exited normally]
Comment 3 Ionen Wolkens gentoo-dev 2020-11-24 20:02:03 UTC
Linking thread about this for reference:
https://forums.gentoo.org/viewtopic-t-1122620.html

I was able to reproduce in a fresh unmodified stage3-i686-20201116T214503Z, but didn't investigate further.
Comment 4 Wade Cline 2020-12-01 07:09:09 UTC
I'm also running into this on both two 32-bit ARM systems and an x86 system (32-bit).  Seems to work fine on my 64-bit system.

I've not managed to get a stack trace or a core dump, despite using 'ulimit -c unlimited' and '/proc/sys/kernel/core_pattern'.

It looks like the daemon is spawning threads and one of them dies shortly after running 'clock_gettime(CLOCK_REALTIME, {tv_sec=1606433599, tv_nsec=15663478}) = 0'.

Will attach an 'strace' dump.
Comment 5 Wade Cline 2020-12-01 07:10:26 UTC
Created attachment 675985 [details]
'strace' of failing OpenNTPD process
Comment 6 acmondor 2020-12-03 01:38:34 UTC
I narrowed down the problem to a bug in the implementation of the function adjtime in sys-libs/glibc-2.32-r2. The bug is in the file sysdeps/unix/sysv/linux/adjtime.c and the problem code is something new for recent versions of glibc. The code in sys-libs/glibc-2.32-r2 does not allow the first parameter of adjtime to be NULL. That goes against the documented behaviour of adjtime (see man adjtime) and is something which openntpd requires.

I patched sys-libs/glibc-2.32-r2 so adjtime behaves as expected and confirmed that the patch does work (ie prevents openntpd from segfault'ng). I also checked the lastest development source code for glibc available at https://www.gnu.org/software/libc/sources.html and there is a fix for this bug there.
Comment 7 acmondor 2020-12-03 01:43:04 UTC
Created attachment 676354 [details, diff]
Patch for bug in glibc function adjtime

This patch almost identical to what already exists upstream for glibc. Also note that the code in question is specific to 32 bit hosts.
Comment 8 Ionen Wolkens gentoo-dev 2020-12-03 17:25:32 UTC
See also: https://sourceware.org/bugzilla/show_bug.cgi?id=26833

I guess this bug should be reassigned to glibc folks.
Comment 9 Sergei Trofimovich (RETIRED) gentoo-dev 2020-12-07 09:04:02 UTC
(In reply to acmondor from comment #6)
> I narrowed down the problem to a bug in the implementation of the function
> adjtime in sys-libs/glibc-2.32-r2. The bug is in the file
> sysdeps/unix/sysv/linux/adjtime.c and the problem code is something new for
> recent versions of glibc. The code in sys-libs/glibc-2.32-r2 does not allow
> the first parameter of adjtime to be NULL. That goes against the documented
> behaviour of adjtime (see man adjtime) and is something which openntpd
> requires.
> 
> I patched sys-libs/glibc-2.32-r2 so adjtime behaves as expected and
> confirmed that the patch does work (ie prevents openntpd from segfault'ng).
> I also checked the lastest development source code for glibc available at
> https://www.gnu.org/software/libc/sources.html and there is a fix for this
> bug there.

Thanks for the analysis. It usually speeds things up to link to upstream fix.

https://sourceware.org/PR26833
Comment 10 Larry the Git Cow gentoo-dev 2020-12-08 00:37:23 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=973c2804ea92b4acb82e0d61ae9179b0fc15db74

commit 973c2804ea92b4acb82e0d61ae9179b0fc15db74
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2020-12-07 22:47:32 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2020-12-08 00:37:18 +0000

    sys-libs/glibc: 2.32: cut 3 patchset
    
    This patchset includes a few upstream backports:
    - sh: Add sh4 fpu Implies folder
    - linux: Allow adjtime with NULL argument [BZ #26833]
    - __vfscanf_internal: fix aliasing violation (bug 26690)
    - iconv: Accept redundant shift sequences in IBM1364 [BZ #26224]
    - aarch64: Add unwind information to _start (bug 26853)
    - support: Provide a way to reorder responses within the DNS test server
    - support: Provide a way to clear the RA bit in DNS server responses
    - resolv: Handle transaction ID collisions in parallel queries (bug 26600)
    - resolv: Serialize processing in resolv/tst-resolv-txnid-collision
    - struct _Unwind_Exception alignment should not depend on compiler flags
    - Remove __warn_memset_zero_len [BZ #25399]
    - Remove __warndecl
    - aarch64: Fix DT_AARCH64_VARIANT_PCS handling [BZ #26798]
    
    Two of them are specual (noticed by Gentoo users):
    - "linux: Allow adjtime with NULL argument [BZ #26833]" fixes openntpd
      startup failure.
    - "__vfscanf_internal: fix aliasing violation (bug 26690)" fixes gcc-11
      compatibility.
    
    Reported-by: Tobias Leupold
    Bug: https://bugs.gentoo.org/756316
    Bug: https://sourceware.org/PR26833
    Reported-by: andy
    Bug: https://bugs.gentoo.org/750992
    Bug: https://sourceware.org/PR26690
    Package-Manager: Portage-3.0.11, Repoman-3.0.2
    Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>

 sys-libs/glibc/Manifest             |    1 +
 sys-libs/glibc/glibc-2.32-r4.ebuild | 1513 +++++++++++++++++++++++++++++++++++
 2 files changed, 1514 insertions(+)
Comment 11 Wade Cline 2020-12-11 20:39:11 UTC
(In reply to acmondor from comment #6)
> I narrowed down the problem to a bug in the implementation of the function
> adjtime in sys-libs/glibc-2.32-r2. The bug is in the file
> sysdeps/unix/sysv/linux/adjtime.c and the problem code is something new for
> recent versions of glibc. The code in sys-libs/glibc-2.32-r2 does not allow
> the first parameter of adjtime to be NULL. That goes against the documented
> behaviour of adjtime (see man adjtime) and is something which openntpd
> requires.
> 
> I patched sys-libs/glibc-2.32-r2 so adjtime behaves as expected and
> confirmed that the patch does work (ie prevents openntpd from segfault'ng).
> I also checked the lastest development source code for glibc available at
> https://www.gnu.org/software/libc/sources.html and there is a fix for this
> bug there.

I'll second what Sergei said: thank you for finding this!
Comment 12 Sergei Trofimovich (RETIRED) gentoo-dev 2021-01-03 13:29:47 UTC
Let's declare it fixed in ~arch. Next glibc stabilization round should have it fixed for everyone.