Bug 501348 - glibc built with -march=x86-64-v3 does not work due to ld.so memcmp
Summary: glibc built with -march=x86-64-v3 does not work due to ld.so memcmp
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: memcheck (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-03-11 11:22 UTC by Florian Weimer
Modified: 2025-03-12 13:59 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Proposed memcmp interceptor (1.98 KB, text/plain)
2025-03-11 11:22 UTC, Florian Weimer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Weimer 2025-03-11 11:22:56 UTC
Created attachment 179295 [details]
Proposed memcmp interceptor

Same issue as bug 485487, but this time for `memcmp` instead of `strcmp`.
Comment 1 Mark Wielaard 2025-03-12 13:05:45 UTC
Replicated with a dlopen of a library using RPATH.

# Invalid read of size 32
# at 0x40242D9: bcmp (memcmp-avx2-movbe.S:415)
# by 0x40069BD: fillin_rpath.isra.0 (dl-load.c:510)
# by 0x4006C6A: decompose_rpath (dl-load.c:654)
# by 0x4009375: _dl_map_object (dl-load.c:2040)
# by 0x4002934: openaux (dl-deps.c:64)
# by 0x40014E0: _dl_catch_exception (dl-catch.c:237)
# by 0x4002D97: _dl_map_object_deps (dl-deps.c:232)
# by 0x400CB70: dl_open_worker_begin (dl-open.c:613)
# by 0x40014E0: _dl_catch_exception (dl-catch.c:237)
# by 0x400C256: dl_open_worker (dl-open.c:778)
# by 0x40014E0: _dl_catch_exception (dl-catch.c:237)
# by 0x400C6B0: _dl_open (dl-open.c:880)

The string being compared is just 11 chars long.

It is pretty hard to replicate though any change in environment seems to hide it again.
But the patch does look correct and does resolve the issue by always using a simpler memcmp implementation.
Comment 2 Mark Wielaard 2025-03-12 13:59:56 UTC
commit 9ffdeb4927b8505cc5a9ea54f608f4972166bb0e
Author: Mark Wielaard <mark@klomp.org>
Date:   Wed Mar 12 13:57:19 2025 +0100

    add_hardwired_spec for ld-linux-x86-64.so.2 memcmp
    
    With RPATH processing ld.so compiled for x86-64-v3 uses an optimized
    avx2 memcmp (bcmp) which causes (false postive) memcheck invalid reads
    of size 32 warnings.
    
    Fix this my adding a hardwire spec with a simpler memcmp for
    ld-linux-x86-64.so.2.
    
    https://bugs.kde.org/show_bug.cgi?id=501348
    
    Authored-by: Florian Weimer <fweimer@redhat.com>

And also on the VALGRIND_3_24_0_BRANCH as

commit 2c17a8a3e865816ee48e7f78148bbc7240c2a38c
Author: Mark Wielaard <mark@klomp.org>
Date:   Wed Mar 12 13:57:19 2025 +0100

    add_hardwired_spec for ld-linux-x86-64.so.2 memcmp
    
    With RPATH processing ld.so compiled for x86-64-v3 uses an optimized
    avx2 memcmp (bcmp) which causes (false postive) memcheck invalid reads
    of size 32 warnings.
    
    Fix this my adding a hardwire spec with a simpler memcmp for
    ld-linux-x86-64.so.2.
    
    https://bugs.kde.org/show_bug.cgi?id=501348
    
    Authored-by: Florian Weimer <fweimer@redhat.com>
    
    (cherry picked from commit 9ffdeb4927b8505cc5a9ea54f608f4972166bb0e)