Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 913420 - net-misc/xmrig 6.20.0 + 6.18.1-r1 (GCC) buffer overflow
Summary: net-misc/xmrig 6.20.0 + 6.18.1-r1 (GCC) buffer overflow
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Matthew Smith
URL: https://github.com/xmrig/xmrig/issues...
Whiteboard:
Keywords:
Depends on:
Blocks: 847148
  Show dependency tree
 
Reported: 2023-09-01 14:54 UTC by William Rabbermann
Modified: 2024-03-23 07:36 UTC (History)
2 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description William Rabbermann 2023-09-01 14:54:54 UTC
I am getting a buff overflow in xmrig versions 6.20.0 and 6.18.1-r1.
p2pool is synced and XMRig should be able to connect to the stratum server on port 3333.


equery u xmrig

+cpu_flags_x86_sse4_1
-donate
+hwloc
+opencl
+ssl


Here is the log:

xmrig -o 127.0.0.1:3333 --randomx-1gb-pages --verbose

 * ABOUT        XMRig/6.20.0 gcc/12.3.1
 * LIBS         libuv/1.46.0 OpenSSL/3.0.9 hwloc/2.9.1
 * HUGE PAGES   supported
 * 1GB PAGES    supported
 * CPU          Intel(R) Core(TM) i5-8600K CPU @ 3.60GHz (1) 64-bit AES
                L2:1.5 MB L3:9.0 MB 6C/6T NUMA:1
 * MEMORY       9.5/15.4 GB (62%)
                DIMM_A0: <empty>
                DIMM_A1: 8 GB DDR4 @ 3200 MHz CMU16GX4M2C3000C15  
                DIMM_B0: <empty>
                DIMM_B1: 8 GB DDR4 @ 3200 MHz CMU16GX4M2C3000C15  
 * MOTHERBOARD  Gigabyte Technology Co., Ltd. - Z370 HD3-CF
 * DONATE       0%
 * ASSEMBLY     auto:intel
 * POOL #1      127.0.0.1:3333 algo auto
 * COMMANDS     hashrate, pause, resume, results, connection
 * OPENCL       disabled
[2023-09-01 09:45:35.163]  net      use pool 127.0.0.1:3333  127.0.0.1
[2023-09-01 09:45:35.163]  net      new job from 127.0.0.1:3333 diff 4002K algo rx/0 height 2964711 (43 tx)
[2023-09-01 09:45:35.163]  cpu      use argon2 implementation AVX2
*** buffer overflow detected ***: terminated
[2023-09-01 09:45:35.163]  msr      0x000001a4:0x000000000000000f -> 0x000000000000000f
[2023-09-01 09:45:35.163]  msr      register values for "intel" preset have been set successfully (0 ms)
./run_xmrig_p2pool: line 5: 22557 Aborted                 $CMD
[2023-09-01 09:45:35.163]  randomx  init dataset algo rx/0 (6 threads) seed 3a1cbe3d24b09081...



emerge --info
Portage 3.0.49 (python 3.11.5-final-0, default/linux/amd64/17.1/hardened, gcc-12, glibc-2.37-r3, 6.1.46-gentoo x86_64)
=================================================================
System uname: Linux-6.1.46-gentoo-x86_64-Intel-R-_Core-TM-_i5-8600K_CPU_@_3.60GHz-with-glibc2.37
KiB Mem:    16194272 total,    190792 free
KiB Swap:   15625212 total,  11900156 free
Timestamp of repository gentoo: Tue, 29 Aug 2023 20:15:01 +0000
Head commit of repository gentoo: fd1822196659661a6a3be292ac6f01de71de7f64
Head commit of repository librewolf: 9fd9f4571ae3b188dc1e994d587467ce43ed1f13

Timestamp of repository steam-overlay: Wed, 23 Aug 2023 07:46:41 +0000
Head commit of repository steam-overlay: f99709b5ad1cef25a18763987742b5e07cd1e649

sh bash 5.1_p16-r6
ld GNU ld (Gentoo 2.40 p5) 2.40.0
distcc 3.4 x86_64-pc-linux-gnu [disabled]
app-misc/pax-utils:        1.3.5::gentoo
app-shells/bash:           5.1_p16-r6::gentoo
dev-lang/perl:             5.36.1-r3::gentoo
dev-lang/python:           3.11.5::gentoo
dev-lang/rust:             1.69.0-r1::gentoo
dev-util/cmake:            3.26.5-r2::gentoo
dev-util/meson:            1.1.1::gentoo
sys-apps/baselayout:       2.14::gentoo
sys-apps/openrc:           0.47.1::gentoo
sys-apps/sandbox:          2.37::gentoo
sys-devel/autoconf:        2.13-r7::gentoo, 2.71-r6::gentoo
sys-devel/automake:        1.16.5-r1::gentoo
sys-devel/binutils:        2.40-r5::gentoo
sys-devel/binutils-config: 5.5::gentoo
sys-devel/clang:           15.0.7-r3::gentoo, 16.0.6::gentoo
sys-devel/gcc:             12.3.1_p20230526::gentoo
sys-devel/gcc-config:      2.11::gentoo
sys-devel/libtool:         2.4.7-r1::gentoo
sys-devel/lld:             15.0.7::gentoo
sys-devel/llvm:            15.0.7-r3::gentoo, 16.0.6::gentoo
sys-devel/make:            4.4.1-r1::gentoo
sys-kernel/linux-headers:  6.1::gentoo (virtual/os-headers)
sys-libs/glibc:            2.37-r3::gentoo
Repositories:

gentoo
    location: /var/db/repos/gentoo
    sync-type: rsync
    sync-uri: rsync://rsync.namerica.gentoo.org/gentoo-portage
    priority: -1000
    volatile: False
    sync-rsync-verify-metamanifest: yes
    sync-rsync-extra-opts:
    sync-rsync-verify-jobs: 1
    sync-rsync-verify-max-age: 24

librewolf
    location: /var/db/repos/librewolf
    sync-type: git
    sync-uri: https://gitlab.com/librewolf-community/browser/gentoo.git
    masters: gentoo
    volatile: False

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

crossdev
    location: /var/db/repos/crossdev
    masters: gentoo
    priority: 10
    volatile: False

Installed sets: @looking-glass
ACCEPT_KEYWORDS="amd64"
ACCEPT_LICENSE="*"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=skylake -O2 -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /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=skylake -O2 -pipe"
DISTDIR="/var/cache/distfiles"
ENV_UNSET="CARGO_HOME DBUS_SESSION_BUS_ADDRESS DISPLAY GDK_PIXBUF_MODULE_FILE 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 XDG_STATE_HOME"
FCFLAGS="-march=skylake -O2 -pipe"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs binpkg-multi-instance buildpkg buildpkg-live config-protect-if-modified 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="-march=skylake -O2 -pipe"
GENTOO_MIRRORS="https://mirror.leaseweb.com/gentoo/ https://mirrors.rit.edu/gentoo/ https://mirror.rackspace.com/gentoo/ http://www.gtlib.gatech.edu/pub/gentoo https://gentoo.osuosl.org/ http://gentoo.osuosl.org/"
LANG="en_US.utf8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
LEX="flex"
MAKEOPTS="-j6"
PKGDIR="/var/cache/binpkgs"
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"
SHELL="/bin/zsh"
USE="X acl alsa amd64 bash-completion bzip2 cet cli crypt cups dbus dri elogind fortran gdbm gtk hardened hostonly iconv initramfs intel ipv6 libtirpc libvirt multilib ncurses nfs nls nptl nvidia openmp pam pcre pie pipewire pulseaudio qt qt5 readline sdl sdl2 seccomp split-usr ssl ssp test-rust udev unicode xattr xinerama xtpax zlib zsh-completion" ABI_X86="64" ADA_TARGET="gnat_2021" 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 aes avx avx2 f16c fma3 pclmul popcnt rdrand sse3 sse4_1 sse4_2 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" GRUB_PLATFORMS="efi-64" INPUT_DEVICES="evdev" KERNEL="linux" 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="php8-1" POSTGRES_TARGETS="postgres15" PYTHON_SINGLE_TARGET="python3_11" PYTHON_TARGETS="python3_11" RUBY_TARGETS="ruby31" SANE_BACKENDS="hp" VIDEO_CARDS="nvidia" 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, CC, CCLD, CONFIG_SHELL, CPP, CPPFLAGS, CTARGET, CXX, CXXFILT, ELFEDIT, EMERGE_DEFAULT_OPTS, EXTRA_ECONF, F77FLAGS, FC, GCOV, GPROF, INSTALL_MASK, LC_ALL, LD, LFLAGS, LIBTOOL, LINGUAS, MAKE, MAKEFLAGS, NM, OBJCOPY, OBJDUMP, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, RANLIB, READELF, RUSTFLAGS, SIZE, STRINGS, STRIP, YACC, YFLAGS
Comment 1 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-09-01 15:00:26 UTC
Can you try get a backtrace with https://wiki.gentoo.org/wiki/Debugging#Per-package please? Thanks!
Comment 2 Matthew Smith gentoo-dev 2023-09-01 15:42:53 UTC
It looks like it's related to configuring the RandomX hash:

(gdb) bt
#0  0x00007ffff7889dbc in ?? () from /usr/lib64/libc.so.6
#1  0x00007ffff7839cc2 in raise () from /usr/lib64/libc.so.6
#2  0x00007ffff78224ed in abort () from /usr/lib64/libc.so.6
#3  0x00007ffff782355c in ?? () from /usr/lib64/libc.so.6
#4  0x00007ffff791a8c5 in __fortify_fail () from /usr/lib64/libc.so.6
#5  0x00007ffff791a270 in __chk_fail () from /usr/lib64/libc.so.6
#6  0x00005555557c8102 in memcpy (__len=16, __src=0x7ffff77fecf0, __dest=<optimized out>) at /usr/include/bits/string_fortified.h:29
#7  RandomX_ConfigurationBase::Apply (this=0x555555a03840 <RandomX_CurrentConfig>) at /usr/src/debug/net-misc/xmrig-6.20.0/xmrig-6.20.0/src/crypto/randomx/randomx.cpp:350
#8  0x00005555557cc8aa in randomx_apply_config<RandomX_ConfigurationBase> (config=...) at /usr/src/debug/net-misc/xmrig-6.20.0/xmrig-6.20.0/src/crypto/randomx/randomx.h:166
#9  xmrig::RxAlgo::apply (algorithm=xmrig::Algorithm::RX_0) at /usr/src/debug/net-misc/xmrig-6.20.0/xmrig-6.20.0/src/crypto/rx/RxAlgo.cpp:26
#10 0x00005555557ccc9f in xmrig::RxBasicStoragePrivate::setSeed (seed=..., this=0x555555ad6a50)
    at /usr/src/debug/net-misc/xmrig-6.20.0/xmrig-6.20.0/src/crypto/rx/RxBasicStorage.cpp:56
#11 xmrig::RxBasicStorage::init (this=0x555555adb620, seed=..., threads=24, hugePages=true, oneGbPages=false, mode=xmrig::RxConfig::AutoMode, priority=2)
    at /usr/src/debug/net-misc/xmrig-6.20.0/xmrig-6.20.0/src/crypto/rx/RxBasicStorage.cpp:168
#12 0x00005555557d0107 in xmrig::RxQueue::backgroundInit (this=0x555555adb170) at /usr/src/debug/net-misc/xmrig-6.20.0/xmrig-6.20.0/src/crypto/rx/RxQueue.cpp:149
#13 0x00005555558d66ff in execute_native_thread_routine ()
#14 0x00007ffff7888069 in ?? () from /usr/lib64/libc.so.6
#15 0x00007ffff790c548 in ?? () from /usr/lib64/libc.so.6
(gdb) frame 7
#7  RandomX_ConfigurationBase::Apply (this=0x555555a03840 <RandomX_CurrentConfig>) at /usr/src/debug/net-misc/xmrig-6.20.0/xmrig-6.20.0/src/crypto/randomx/randomx.cpp:350
350             INST_HANDLE(ISTORE, CFROUND);
Comment 3 Matthew Smith gentoo-dev 2023-09-01 15:59:09 UTC
I'm not familiar with the bowels of XMRig, but I think that this function is copying code out of .text (for its JIT) which deeply upsets the checks.

Is there a way to disable the FORTIFY_SOURCE checks just for this memcpy, or do we need to filter it for the whole package?
Comment 4 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-09-01 16:07:25 UTC
(In reply to Matthew Smith from comment #3)
> I'm not familiar with the bowels of XMRig, but I think that this function is
> copying code out of .text (for its JIT) which deeply upsets the checks.
> 
> Is there a way to disable the FORTIFY_SOURCE checks just for this memcpy, or
> do we need to filter it for the whole package?

I'm speechless at the discussion on that bug.

Anyway, no, you have to disable it entirely unfortunately, i.e. append-cppflags -U_FORTIFY_SOURCE (you can't do it partially because of ODR w/ C++ but also this package surely isn't going to be clean in other places anyway).
Comment 5 Larry the Git Cow gentoo-dev 2023-09-01 17:21:40 UTC
The bug has been closed via the following commit(s):

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

commit d094dd12e83313941d9936cdaa89b62dde62035e
Author:     Matthew Smith <matthew@gentoo.org>
AuthorDate: 2023-09-01 17:17:18 +0000
Commit:     Matthew Smith <matthew@gentoo.org>
CommitDate: 2023-09-01 17:21:15 +0000

    net-misc/xmrig: filter FORTIFY_SOURCE=3
    
    Closes: https://bugs.gentoo.org/913420
    Signed-off-by: Matthew Smith <matthew@gentoo.org>

 .../xmrig/{xmrig-6.18.1-r1.ebuild => xmrig-6.18.1-r2.ebuild}     | 9 ++++++++-
 net-misc/xmrig/{xmrig-6.20.0.ebuild => xmrig-6.20.0-r1.ebuild}   | 9 ++++++++-
 net-misc/xmrig/xmrig-9999.ebuild                                 | 9 ++++++++-
 3 files changed, 24 insertions(+), 3 deletions(-)
Comment 6 William Rabbermann 2023-09-01 19:39:01 UTC
Thank you, xmrig is working now. :)
Comment 7 Larry the Git Cow gentoo-dev 2024-03-23 07:36:37 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=9577efa11cca713f2e5b7e80ab07cb37365fba19

commit 9577efa11cca713f2e5b7e80ab07cb37365fba19
Author:     Matthew Smith <matthew@gentoo.org>
AuthorDate: 2024-03-23 07:32:32 +0000
Commit:     Matthew Smith <matthew@gentoo.org>
CommitDate: 2024-03-23 07:36:25 +0000

    net-misc/xmrig: stop filtering -D_FORTIFY_SOURCE=3
    
    Fixed upstream in commit f6c50b5393.
    
    Bug: https://bugs.gentoo.org/913420
    Signed-off-by: Matthew Smith <matthew@gentoo.org>

 net-misc/xmrig/xmrig-9999.ebuild | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)