Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'make check' fails with -D_FORTIFY_SOURCE=3 #358

Closed
thesamesam opened this issue Sep 28, 2022 · 11 comments
Closed

'make check' fails with -D_FORTIFY_SOURCE=3 #358

thesamesam opened this issue Sep 28, 2022 · 11 comments

Comments

@thesamesam
Copy link
Contributor

thesamesam commented Sep 28, 2022

This test failure seems to occur when building with -D_FORTIFY_SOURCE=3. Note that this requires GCC 12 (or Clang 9?+) and glibc 2.35+.

make[3]: Entering directory '/var/tmp/portage/net-analyzer/nfdump-1.7.0/work/nfdump-v.1.7.0/src/test'
PASS: nftest
FAIL: runtest.sh
============================================================================
Testsuite summary for nfdump 1.7.0
============================================================================
# TOTAL: 2
# PASS:  1
# SKIP:  0
# XFAIL: 0
# FAIL:  1
# XPASS: 0
# ERROR: 0
============================================================================
See src/test/test-suite.log
Please report to peter@people.ops-trust.net
============================================================================
make[3]: *** [Makefile:702: test-suite.log] Error 1

test-suite.log:

FAIL: runtest.sh
================

File       : test.flows.nf
Version    : 2 - not compressed
Created    : 2022-09-29 00:09:06
nfdump     : 1070001
encryption : no
Appdx blks : 1
Data blks  : 1
Checking data blocks
 |^MChecking appendix blocks

Total
Type 3 blocks : 2
Records       : 22
File test.flows.nf is already same compression methode
File test.flows.nf compression changed
File test.flows.nf compression changed
File test.flows.nf compression changed
File test.flows.nf compression changed
File test.flows.nf compression changed
File test.flows.nf compression changed
*** buffer overflow detected ***: terminated
Aborted (core dumped)
FAIL runtest.sh (exit status: 134)
Using host libthread_db library "/usr/lib64/libthread_db.so.1".
Core was generated by `/var/tmp/portage/net-analyzer/nfdump-1.7.0/work/nfdump-v.1.7.0/src/nfdump/.libs'.
Program terminated with signal SIGABRT, Aborted.
#0  0x00007fc070faab7c in ?? () from /usr/lib64/libc.so.6
[Current thread is 1 (Thread 0x7fc070f09740 (LWP 3541994))]
(gdb) bt
#0  0x00007fc070faab7c in ?? () from /usr/lib64/libc.so.6
#1  0x00007fc070f58dd6 in raise () from /usr/lib64/libc.so.6
#2  0x00007fc070f427fc in abort () from /usr/lib64/libc.so.6
#3  0x00007fc070f9e4d6 in ?? () from /usr/lib64/libc.so.6
#4  0x00007fc07103bd92 in __fortify_fail () from /usr/lib64/libc.so.6
#5  0x00007fc07103a676 in __chk_fail () from /usr/lib64/libc.so.6
#6  0x00007fc07103a295 in __snprintf_chk () from /usr/lib64/libc.so.6
#7  0x0000556894c885d3 in snprintf (__fmt=0x7fff127aa280 "%1s", __n=<optimized out>, __s=<optimized out>) at /usr/include/bits/stdio2.h:54
#8  ParseOutputFormat (format=<optimized out>, plain_numbers=<optimized out>, printmap=printmap@entry=0x556894ca4ae0 <printmap>) at output_fmt.c:635
#9  0x0000556894c84326 in SetupOutputMode (print_format=0x556894c99341 "line", print_format@entry=0x0, outputParams=outputParams@entry=0x5568950502a0, HasGeoDB=<optimized out>) at output.c:180
#10 0x0000556894c74d28 in main (argc=<optimized out>, argv=<optimized out>) at nfdump.c:1053
(gdb)
@thesamesam
Copy link
Contributor Author

thesamesam commented Sep 28, 2022

Specifically:

nfdump-v.1.7.0/src/test # ../nfdump/nfdump -G none -r test.flows.nf -q -z -w test.2.flows.nf
*** buffer overflow detected ***: terminated
Aborted (core dumped)
# libtool --mode=execute gdb --args ../nfdump/nfdump -G none -r test.flows.nf -q -z -w test.2.flows.nf
[...]
*** buffer overflow detected ***: terminated

Thread 1 "nfdump" received signal SIGABRT, Aborted.
0x00007ffff7de6b7c in ?? () from /usr/lib64/libc.so.6
(gdb) bt
#0  0x00007ffff7de6b7c in ?? () from /usr/lib64/libc.so.6
#1  0x00007ffff7d94dd6 in raise () from /usr/lib64/libc.so.6
#2  0x00007ffff7d7e7fc in abort () from /usr/lib64/libc.so.6
#3  0x00007ffff7dda4d6 in ?? () from /usr/lib64/libc.so.6
#4  0x00007ffff7e77d92 in __fortify_fail () from /usr/lib64/libc.so.6
#5  0x00007ffff7e76676 in __chk_fail () from /usr/lib64/libc.so.6
#6  0x00007ffff7e76295 in __snprintf_chk () from /usr/lib64/libc.so.6
#7  0x000055555556c5d3 in snprintf (__fmt=0x7fffffffdc40 "%1s", __n=<optimized out>, __s=<optimized out>) at /usr/include/bits/stdio2.h:54
#8  ParseOutputFormat (format=<optimized out>, plain_numbers=<optimized out>, printmap=printmap@entry=0x555555588ae0 <printmap>) at output_fmt.c:635
#9  0x0000555555568326 in SetupOutputMode (print_format=0x55555557d341 "line", print_format@entry=0x0, outputParams=outputParams@entry=0x5555555ad2a0, HasGeoDB=<optimized out>) at output.c:180
#10 0x0000555555558d28 in main (argc=<optimized out>, argv=<optimized out>) at nfdump.c:1053

@phaag
Copy link
Owner

phaag commented Sep 29, 2022

Thanks for reporting! What OS/Version are you using?

@phaag
Copy link
Owner

phaag commented Sep 29, 2022

I assume it could be a missing var initialization. Could you please try the fixed master branch?

@thesamesam
Copy link
Contributor Author

thesamesam commented Sep 29, 2022

Thanks for reporting! What OS/Version are you using?

Hi! Sorry for not giving that information last night, doh.

It's Gentoo Linux (I'm the maintainer of the nfdump package over there). Here's my system information:

Portage 3.0.37 (python 3.11.0-candidate-2, default/linux/amd64/17.1/hardened, gcc-12.2.1, glibc-2.36-r3, 5.15.67-gentoo-dist-hardened x86_64)
=================================================================
System uname: Linux-5.15.67-gentoo-dist-hardened-x86_64-AMD_Ryzen_9_3950X_16-Core_Processor-with-glibc2.36
KiB Mem:    65765036 total,  17437428 free
KiB Swap:    8290300 total,   3055740 free
Timestamp of repository gentoo: Thu, 29 Sep 2022 06:32:04 +0000
Head commit of repository gentoo: 60bdc7c2ad9261b5ec1fc2a375844b6f1742cedf

Timestamp of repository emacs: Wed, 24 Aug 2022 05:02:36 +0000
Head commit of repository emacs: cfdb9df2b4b45d064912481b0fa29cd2c6965703

Timestamp of repository kde: Sun, 25 Sep 2022 19:02:33 +0000
Head commit of repository kde: bdff9eefb9c4db131551b459a7c0ef3cad86a03e

Timestamp of repository qt: Sat, 24 Sep 2022 21:31:42 +0000
Head commit of repository qt: 8be4628731c054633e1d313f7da30a46feaa7d35

Timestamp of repository sam_c: Thu, 22 Sep 2022 03:01:46 +0000
Head commit of repository sam_c: d13161c447f2cf16381c26fe6a89e10bb0a84094

Timestamp of repository steam-overlay: Wed, 07 Sep 2022 08:26:00 +0000
Head commit of repository steam-overlay: 78208ca83614c4cc031ca8f8ec9b023a5c9c3b1e

sh dash 0.5.11.5
ld GNU ld (Gentoo 2.39 p4) 2.39.0
ccache version 4.6.3 [disabled]
app-misc/pax-utils:        1.3.5::gentoo
app-shells/bash:           5.2::gentoo
dev-java/java-config:      2.3.1::gentoo
dev-lang/perl:             5.36.0::gentoo
dev-lang/python:           2.7.18_p15-r1::gentoo, 3.8.14::gentoo, 3.9.14::gentoo, 3.10.7::gentoo, 3.11.0_rc2::gentoo
dev-lang/rust:             1.64.0-r1::gentoo
dev-util/ccache:           4.6.3::gentoo
dev-util/cmake:            3.24.2::gentoo
dev-util/meson:            0.63.2-r1::gentoo
sys-apps/baselayout:       2.9::gentoo
sys-apps/sandbox:          2.29::gentoo
sys-apps/systemd:          251.4::gentoo
sys-devel/autoconf:        2.13-r3::gentoo, 2.69-r7::gentoo, 2.71-r4::gentoo
sys-devel/automake:        1.16.5::gentoo
sys-devel/binutils:        2.39-r2::gentoo
sys-devel/binutils-config: 5.4.1::gentoo
sys-devel/clang:           14.0.6-r1::gentoo, 15.0.1::gentoo, 16.0.0_pre20220918::gentoo
sys-devel/gcc:             9.5.0::gentoo, 10.4.1_p20220922::gentoo, 11.3.1_p20220923::gentoo, 12.2.1_p20220924::gentoo, 13.0.0_pre20220918::gentoo
sys-devel/gcc-config:      2.6::gentoo
sys-devel/libtool:         2.4.7::gentoo
sys-devel/lld:             14.0.6::gentoo
sys-devel/llvm:            14.0.6-r2::gentoo, 15.0.1::gentoo, 16.0.0_pre20220918::gentoo
sys-devel/make:            9999::gentoo
sys-kernel/linux-headers:  5.19::gentoo (virtual/os-headers)
sys-libs/glibc:            2.36-r3::gentoo
Repositories:

gentoo
    location: /var/db/repos/gentoo
    sync-type: git
    sync-uri: https://github.com/gentoo-mirror/gentoo.git
    priority: -1000
    eclass-overrides: sam_c
    sync-git-clone-extra-opts: -b stable -c gc.reflogExpire=0 -c gc.reflogExpireUnreachable=0 -c gc.rerereresolved=0 -c gc.rerereunresolved=0 -c gc.pruneExpire=now
    sync-git-verify-commit-signature: yes

crossdev
    location: /var/db/repos/crossdev
    masters: gentoo
    eclass-overrides: sam_c

emacs
    location: /var/db/repos/emacs
    sync-type: git
    sync-uri: https://github.com/gentoo-mirror/emacs.git
    masters: gentoo
    eclass-overrides: sam_c

kde
    location: /var/db/repos/kde
    sync-type: git
    sync-uri: https://github.com/gentoo-mirror/kde.git
    masters: gentoo
    eclass-overrides: sam_c

local
    location: /var/db/repos/local
    masters: gentoo
    eclass-overrides: sam_c

qt
    location: /var/db/repos/qt
    sync-type: git
    sync-uri: https://github.com/gentoo-mirror/qt.git
    masters: gentoo
    eclass-overrides: sam_c

sam_c
    location: /var/db/repos/sam_c
    sync-type: git
    sync-uri: https://github.com/gentoo-mirror/sam_c.git
    masters: gentoo
    eclass-overrides: sam_c

steam-overlay
    location: /var/db/repos/steam-overlay
    sync-type: git
    sync-uri: https://github.com/gentoo-mirror/steam-overlay.git
    masters: gentoo
    eclass-overrides: sam_c

test
    location: /var/db/repos/test
    masters: gentoo
    eclass-overrides: sam_c

ACCEPT_KEYWORDS="amd64 ~amd64"
ACCEPT_LICENSE="@FREE"
CBUILD="x86_64-pc-linux-gnu"
CC="gcc"
CFLAGS="-O2 -D_FORTIFY_SOURCE=3 -ggdb3"
CHOST="x86_64-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 /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c"
CXXFLAGS="-O2 -pipe -march=native -fdiagnostics-color=always -frecord-gcc-switches -D_GLIBCXX_ASSERTIONS"
DISTDIR="/var/cache/distfiles"
EMERGE_DEFAULT_OPTS="--keep-going --with-bdeps=y --complete-graph --deep --dynamic-deps=n --changed-deps=n --usepkg-exclude sys-fs/zfs --usepkg-exclude sys-fs/zfs-kmod --usepkg=y --implicit-system-deps=n --jobs=4 --load-average 32"
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 -pipe -march=native -fdiagnostics-color=always -frecord-gcc-switches"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs buildpkg cgroup clean-logs config-protect-if-modified distlocks ebuild-locks fixlafiles ipc-sandbox mount-sandbox multilib-strict network-sandbox news parallel-fetch parallel-install pid-sandbox preserve-libs protect-owned qa-unresolved-soname-deps sandbox sfperms split-log strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-O2 -pipe -march=native -fdiagnostics-color=always -frecord-gcc-switches"
GENTOO_MIRRORS="http://mirror.bytemark.co.uk/gentoo/ http://www.mirrorservice.org/sites/distfiles.gentoo.org/ http://mirrors.soeasyto.com/distfiles.gentoo.org/"
LANG="en_GB.UTF-8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed -Wl,--defsym=__gentoo_check_ldflags__=0 -Wl,-z,pack-relative-relocs"
LINGUAS="en en_GB"
PKGDIR="/var/cache/binpkgs"
PORTAGE_COMPRESS="zstd"
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"
RUSTFLAGS="-C target-cpu=native"
SHELL="/bin/bash"
USE="PIC X a52 aac acl acpi activities aes alsa amd64 avx avx2 bash-completion bluetooth branding bzip2 cairo caps cdda cdr clang cli crypt dbus declarative dist-kernel dri dts dvd dvdr emacs encode exif f16c filecaps firewalld flac fma3 fortran freetype gdbm gif gmp gpm graphite gtk gui hardened harfbuzz hunspell iconv icu ipv6 jit jpeg kde kdesu kwallet lcms libglvnd libnotify libtirpc llvm-libunwind lto mad mmx mmxext mng mp3 mp4 mpeg multilib ncurses nftables nls nptl ogg opengl openmp pam pango pclmul pcre pdf pgo pie pipewire plasma png policykit popcnt ppds pulseaudio qml qt5 rdrand readline screencast sdl seccomp semantic-desktop sha spell sse sse2 sse3 sse4_1 sse4_2 sse4a ssl ssp ssse3 startup-notification svg system-av1 system-binutils system-boost system-bootstrap system-cairo system-clang system-digest system-ffmpeg system-harfbuzz system-heimdal system-icu system-jpeg system-leveldb system-libevent system-libs system-libvpx system-libyaml system-llvm system-lz4 system-mitkrb5 system-sqlite system-ssl system-tbb system-uulib system-webp system-zlib systemd tiff truetype udev udisks unicode upower usb verify-sig vorbis vulkan wayland widgets x264 xattr xcb xml xtpax xv xvid zfs zlib zsh-completion" ABI_X86="32 64" ADA_TARGET="gnat_2020" 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="aes avx avx2 f16c fma3 mmx mmxext pclmul popcnt rdrand sha sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3" 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="en en-GB" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LLVM_TARGETS="AArch64 AMDGPU ARM AVR BPF Hexagon Lanai MSP430 Mips NVPTX PowerPC RISCV Sparc SystemZ WebAssembly X86 XCore" LUA_SINGLE_TARGET="lua5-1" LUA_TARGETS="lua5-1" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php7-4 php8-0" POSTGRES_TARGETS="postgres12 postgres13" PYTHON_SINGLE_TARGET="python3_10" PYTHON_TARGETS="python3_10 pypy3 python3_11 python3_8 python3_9" QEMU_USER_TARGETS="aarch64 aarch64_be alpha armeb hppa m68k ppc64le sparc64" RUBY_TARGETS="ruby31" USERLAND="GNU" VIDEO_CARDS="amdgpu radeonsi radeon" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq proto steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  ADDR2LINE, AR, ARFLAGS, AS, ASFLAGS, CCLD, CONFIG_SHELL, CPP, CPPFLAGS, CTARGET, CXX, CXXFILT, ELFEDIT, EXTRA_ECONF, F77FLAGS, FC, GCOV, GPROF, INSTALL_MASK, LC_ALL, LD, LEX, LFLAGS, LIBTOOL, MAKE, MAKEFLAGS, MAKEOPTS, NM, OBJCOPY, OBJDUMP, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, RANLIB, READELF, SIZE, STRINGS, STRIP, YACC, YFLAGS

Build manually in this case w/ export CFLAGS="-O2 -D_FORTIFY_SOURCE=3 -ggdb3" CC=gcc and ./configure && make -j32 check.

Master still seems to break, unfortunately:

FAIL: runtest.sh
================

File       : test.flows.nf
Version    : 2 - not compressed
Created    : 2022-09-29 13:52:52
nfdump     : 1070001
encryption : no
Appdx blks : 1
Data blks  : 1
Checking data blocks
 |^MChecking appendix blocks

Total
Type 3 blocks : 2
Records       : 22
File test.flows.nf is already same compression methode
File test.flows.nf compression changed
File test.flows.nf compression changed
File test.flows.nf compression changed
File test.flows.nf compression changed
File test.flows.nf compression changed
File test.flows.nf compression changed
*** buffer overflow detected ***: terminated
Aborted (core dumped)
FAIL runtest.sh (exit status: 134)
$ libtool --mode=execute gdb --args ../nfdump/nfdump -G none -r test.flows.nf -q -z -w test.2.flows.nf
[...]
Starting program: /home/sam/git/nfdump/src/nfdump/.libs/nfdump -G none -r test.flows.nf -q -z -w test.2.flows.nf
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib64/libthread_db.so.1".
[New Thread 0x7ffff7c286c0 (LWP 784619)]
*** buffer overflow detected ***: terminated

Thread 1 "nfdump" received signal SIGABRT, Aborted.
0x00007ffff7db7b7c in ?? () from /usr/lib64/libc.so.6
(gdb) bt
#0  0x00007ffff7db7b7c in ?? () from /usr/lib64/libc.so.6
#1  0x00007ffff7d65dd6 in raise () from /usr/lib64/libc.so.6
#2  0x00007ffff7d4f7fc in abort () from /usr/lib64/libc.so.6
#3  0x00007ffff7dab4d6 in ?? () from /usr/lib64/libc.so.6
#4  0x00007ffff7e48d92 in __fortify_fail () from /usr/lib64/libc.so.6
#5  0x00007ffff7e47676 in __chk_fail () from /usr/lib64/libc.so.6
#6  0x00007ffff7e47295 in __snprintf_chk () from /usr/lib64/libc.so.6
#7  0x000055555556eada in snprintf (__fmt=0x555555580dbc "%s", __n=<optimized out>, __s=<optimized out>) at /usr/include/bits/stdio2.h:54
#8  ParseOutputFormat (format=<optimized out>, plain_numbers=<optimized out>, printmap=printmap@entry=0x55555558aae0 <printmap>) at output_fmt.c:609
#9  0x000055555556a8a7 in SetupOutputMode (print_format=0x55555557f351 "line", print_format@entry=0x0, outputParams=outputParams@entry=0x5555555af2a0, HasGeoDB=<optimized out>) at output.c:180
#10 0x000055555555bc58 in main (argc=<optimized out>, argv=<optimized out>) at nfdump.c:1053
(gdb)

@atbohmer
Copy link

Just out curiosity: how to have runtest.sh run correct from source? Is this a configure option at build time?
Seems nfgen.c is not compiled so runtest.sh fails to work properly.
Thanks!

@thesamesam
Copy link
Contributor Author

Just out curiosity: how to have runtest.sh run correct from source? Is this a configure option at build time?
Seems nfgen.c is not compiled so runtest.sh fails to work properly.
Thanks!

Run "make check" first.

@phaag
Copy link
Owner

phaag commented Sep 29, 2022

but this time it's output_fmt.c:609, last time it was output_fmt.c:635

@phaag
Copy link
Owner

phaag commented Sep 29, 2022

I test the code on a regular interval with the sanitizers - https://github.com/google/sanitizers and had no failure.

@phaag
Copy link
Owner

phaag commented Sep 29, 2022

Got it! Found another one. Could you please check with latest master branch.

@thesamesam
Copy link
Contributor Author

You nailed it!

PASS: nftest
PASS: runtest.sh
============================================================================
Testsuite summary for nfdump 1.7.0
============================================================================
# TOTAL: 2
# PASS:  2
# SKIP:  0
# XFAIL: 0
# FAIL:  0
# XPASS: 0
# ERROR: 0
============================================================================

Thank you!

@phaag phaag closed this as completed Sep 30, 2022
@phaag
Copy link
Owner

phaag commented Sep 30, 2022

Fixed in new release 1.7.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants