Bug 705790 - memcpy/memmove read out of bounds
Summary: memcpy/memmove read out of bounds
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: valgrind
Version: 15
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2011-05-18 13:33 UTC by Dan Winship
Modified: 2011-06-24 03:40 UTC (History)
4 users (show)

Fixed In Version: valgrind-3.6.1-4.fc15
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2011-06-24 03:40:09 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)
seward suggests this as a quick-fix to make valgrind usable again (615 bytes, patch)
2011-06-08 13:25 UTC, Caolan McNamara
no flags Details | Diff


Links
System ID Private Priority Status Summary Last Updated
KDE Software Compilation 275212 0 None None None Never
KDE Software Compilation 275284 0 None None None Never

Description Dan Winship 2011-05-18 13:33:20 UTC
glibc-2.13.90-11.x86_64's memcpy/memmove seem to be doing 8-byte copies in some situations where there are fewer than 8 bytes left in the source buffer. Eg, running "valgrind epiphany", you see lots of:

==326== Invalid read of size 8
==326==    at 0x31A9B35BD0: __memcpy_ssse3_back (memcpy-ssse3-back.S:513)
...
==326==  Address 0xcabd658 is 424 bytes inside a block of size 431 alloc'd
==326==    at 0x4A0640D: malloc (vg_replace_malloc.c:236)


and

==326== Invalid read of size 8
==326==    at 0x31A9B3AC68: __memmove_ssse3_back (memcpy-ssse3-back.S:236)
...
==326==  Address 0x1643ca78 is 1,592 bytes inside a block of size 1,599 alloc'd
==326==    at 0x4A064F2: realloc (vg_replace_malloc.c:525)

etc

On F14, with glibc-2.13-1.x86_64, and building the same version of epiphany and other GNOME dependencies by hand, these warnings do not appear.

I haven't been able to come up with a trivial test case.

Comment 1 Andreas Schwab 2011-05-18 13:43:14 UTC
This is a false positive, the address is correctly aligned.

Comment 2 Dan Winship 2011-05-18 14:09:32 UTC
I'm pretty sure it's not claiming incorrect alignment, it's claiming that glibc is doing an (aligned) 8-byte read when there are only 7 bytes left in the buffer, and so it is reading 1 byte beyond the end of the buffer.

Comment 3 Jakub Jelinek 2011-05-18 14:15:46 UTC
There is nothing wrong in reading that 1 byte beyond the end of the buffer, if you know the read won't trap because of that and if you don't actualy use it.

valgrind overrides glibc's memmove (and many other functions) though, so it is strange that glibc memmove has been called.

Comment 4 Caolan McNamara 2011-06-08 13:25:49 UTC
Created attachment 503686 [details]
seward suggests this as a quick-fix to make valgrind usable again

Comment 5 Jakub Jelinek 2011-06-08 16:30:35 UTC
I don't think the patch is correct, after all there are 3 different memmove implementations.  As it worked in F14 and valgrind already has IFUNC support, I bet this is related to the glibc workaround for lame apps.

readelf -Ws /lib64/libc.so.6 | grep 'memcpy\|memmove' | grep -v 'LOCAL\|wmem\|_chk'
  1103: 00000035e7a83160    71 IFUNC   GLOBAL DEFAULT   12 memcpy.5
  1104: 00000035e7a88d40    60 IFUNC   GLOBAL DEFAULT   12 memcpy@@GLIBC_2.14
  1944: 00000035e7a83160    71 IFUNC   GLOBAL DEFAULT   12 memmove@@GLIBC_2.2.5
  5575: 00000035e7a83160    71 IFUNC   GLOBAL DEFAULT   12 memcpy.5
  6284: 00000035e7a83160    71 IFUNC   GLOBAL DEFAULT   12 memmove
  7443: 00000035e7a88d40    60 IFUNC   GLOBAL DEFAULT   12 memcpy@@GLIBC_2.14

shows that in glibc 2.14+ memcpy.5 is IFUNC aliased to memmove, while
memcpy@@GLIBC_2.14 is a real memcpy (again, IFUNC).

Comment 6 Caolan McNamara 2011-06-09 08:57:06 UTC
Well, we could stick in the other two implementation too. The crucial bit for me is that locally I get sane useful results out of valgrind again.

Comment 7 Jakub Jelinek 2011-06-13 16:10:24 UTC
Please try rawhide valgrind (3.6.1-4.fc16), if that works, will build the same for f15 updates-testing too.

Comment 8 Fedora Update System 2011-06-14 12:04:55 UTC
valgrind-3.6.1-4.fc15 has been submitted as an update for Fedora 15.
https://admin.fedoraproject.org/updates/valgrind-3.6.1-4.fc15

Comment 9 Fedora Update System 2011-06-15 18:28:06 UTC
Package valgrind-3.6.1-4.fc15:
* should fix your issue,
* was pushed to the Fedora 15 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing valgrind-3.6.1-4.fc15'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/valgrind-3.6.1-4.fc15
then log in and leave karma (feedback).

Comment 10 Caolan McNamara 2011-06-16 09:22:13 UTC
It solves that. I do however get new warnings of...

==6241== Conditional jump or move depends on uninitialised value(s)
==6241==    at 0x3771217476: index (strchr.S:56)
==6241==    by 0x37712078F2: expand_dynamic_string_token (dl-load.c:326)
==6241==    by 0x3771208241: _dl_map_object (dl-load.c:2193)
==6241==    by 0x37712017DD: map_doit (rtld.c:629)
==6241==    by 0x377120E8A5: _dl_catch_error (dl-error.c:178)
==6241==    by 0x3771200F16: do_preload (rtld.c:813)
==6241==    by 0x37712048A0: dl_main (rtld.c:1696)
==6241==    by 0x3771214F83: _dl_sysdep_start (dl-sysdep.c:244)
==6241==    by 0x377120512E: _dl_start (rtld.c:334)
==6241==    by 0x3771201607: ??? (in /lib64/ld-2.13.90.so)
==6241==    by 0x1: ???
==6241==    by 0x7FEFFD496: ???
==6241==    by 0x7FEFFD4BA: ???
==6241==
==6241== Conditional jump or move depends on uninitialised value(s)
==6241==    at 0x377121747B: index (strchr.S:59)
==6241==    by 0x37712078F2: expand_dynamic_string_token (dl-load.c:326)
==6241==    by 0x3771208241: _dl_map_object (dl-load.c:2193)
==6241==    by 0x37712017DD: map_doit (rtld.c:629)
==6241==    by 0x377120E8A5: _dl_catch_error (dl-error.c:178)
==6241==    by 0x3771200F16: do_preload (rtld.c:813)
==6241==    by 0x37712048A0: dl_main (rtld.c:1696)
==6241==    by 0x3771214F83: _dl_sysdep_start (dl-sysdep.c:244)
==6241==    by 0x377120512E: _dl_start (rtld.c:334)
==6241==    by 0x3771201607: ??? (in /lib64/ld-2.13.90.so)
==6241==    by 0x1: ???
==6241==    by 0x7FEFFD496: ???
==6241==    by 0x7FEFFD4BA: ???

Comment 11 Jakub Jelinek 2011-06-16 09:31:01 UTC
Forgotten yum update?  F14 now has glibc-2.14, instead of glibc-2.13.90.

Comment 12 Caolan McNamara 2011-06-16 10:36:23 UTC
Ah, indeed. Yup, noiseless now.

Comment 13 Fedora Update System 2011-06-24 03:39:52 UTC
valgrind-3.6.1-4.fc15 has been pushed to the Fedora 15 stable repository.  If problems still persist, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.