Bug 401627 - memcheck errors with glibc avx2 optimized wcsncmp
Summary: memcheck errors with glibc avx2 optimized wcsncmp
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: Mark Wielaard
URL: https://bugzilla.redhat.com/show_bug....
Keywords:
Depends on:
Blocks:
 
Reported: 2018-12-01 22:52 UTC by Mark Wielaard
Modified: 2018-12-06 15:43 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
Add wcsncmp override and testcase. (3.56 KB, text/plain)
2018-12-01 23:08 UTC, Mark Wielaard
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Wielaard 2018-12-01 22:52:10 UTC
With glibc 2.28 on an avx2 capable machine the wcsncmp function will produce the following error under valgrind:

==3667== Invalid read of size 32
==3667==    at 0x4F9CD61: __wcsncmp_avx2 (in /usr/lib64/libc-2.28.so)
==3667==    by 0x400A33: main (wcs.c:22)
==3667==  Address 0x5201110 is 208 bytes inside a block of size 216 alloc'd
==3667==    at 0x4C30E4B: malloc (vg_replace_malloc.c:299)
==3667==    by 0x4009CA: main (wcs.c:18)
==3667== 
==3667== Invalid read of size 32
==3667==    at 0x4F9CD66: __wcsncmp_avx2 (in /usr/lib64/libc-2.28.so)
==3667==    by 0x400A33: main (wcs.c:22)
==3667==  Address 0x5201130 is 16 bytes after a block of size 224 in arena "client"
==3667== 
==3667== Conditional jump or move depends on uninitialised value(s)
==3667==    at 0x4F9CE21: __wcsncmp_avx2 (in /usr/lib64/libc-2.28.so)
==3667==    by 0x400A33: main (wcs.c:22)
==3667== 


This probably comes from the following glibc commit glibc-2.27.9000-436-g1457016:

commit 1457016337072d1b6739f571846b619596990cb7
Author: Leonardo Sandoval <leonardo.sandoval.gonzalez@linux.intel.com>
Date:   Thu May 3 11:09:30 2018 -0500

    x86-64: Optimize strcmp/wcscmp and strncmp/wcsncmp with AVX2

strcmp, wcscmp and strncmp have overrides in valgrind shared/vg_replace_strmem.c.
But wcsncmp doesn't.
Comment 1 Mark Wielaard 2018-12-01 23:08:44 UTC
Created attachment 116617 [details]
Add wcsncmp override and testcase.

Proposed patch.
Comment 2 Mark Wielaard 2018-12-06 15:43:09 UTC
commit cf00e0e59def011e40e2c7993aab23970841dd03
Author: Mark Wielaard <mark@klomp.org>
Date:   Sat Dec 1 23:54:40 2018 +0100

    Bug 401627 - Add wcsncmp override and testcase.
    
    glibc 2.28 added an avx2 optimized variant of wstrncmp which memcheck
    cannot proof correct. Add a simple override in vg_replace_strmem.c.