Bug 445941

Summary: valgrind 3.18.1 crashes on RHEL 6.7 debuginfo Assertion 'in_rx' failed in libmagic.so
Product: [Developer tools] valgrind Reporter: bug.reporter42
Component: memcheckAssignee: Julian Seward <jseward>
Status: REPORTED ---    
Severity: crash CC: grzegorz.roszak, pjfloyd
Priority: NOR    
Version First Reported In: 3.18.1   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: Valgrind 3.18.1 crash trachback in debug info on RHEL 6.7

Description bug.reporter42 2021-11-22 19:56:06 UTC
Created attachment 143848 [details]
Valgrind 3.18.1 crash trachback in debug info on RHEL 6.7

SUMMARY
***
NOTE: If you are reporting a crash, please try to attach a backtrace with debug symbols.
See https://community.kde.org/Guidelines_and_HOWTOs/Debugging/How_to_create_useful_crash_reports
***


STEPS TO REPRODUCE
1. login to RHEL 6.7 box.
2.   export VALGRIND_OPTS=-v --trace-symtab=yes --trace-symtab-patt=*libmagic*
3. valgrind <binary>

OBSERVED RESULT
valgrind crashes with the following error:
valgrind: ../../coregrind/m_debuginfo/readelf.c:717 (get_elf_symbol_info): Assertion 'in_rx' failed.

EXPECTED RESULT
valgrind does not crash

SOFTWARE/OS VERSIONS
RHEL 6.7 - running valgrind in an xterm window

ADDITIONAL INFORMATION
Valgrind 3.18.1 was compiled on RHEL 6.7.
Valgrind 3.17.0 does NOT exhibit this problem, nor do earlier versions of valgrind. It seems specific to 3.18.1 on RHEL6.
The same valgrind 3.18.1 binary and same profiled binary run on RHEL7 and RHEL8 does NOT crash. The problem only occurs when running on RHEL6 with no other changes.
Comment 1 Paul Floyd 2021-11-23 06:22:02 UTC
Which compiler are you using?
Comment 2 Grzegorz Roszak 2021-11-24 20:09:22 UTC
(In reply to Paul Floyd from comment #1)
> Which compiler are you using?

(In reply to Paul Floyd from comment #1)
> Which compiler are you using?

I can confirm the same issue on RHEL6.8 (Santiago) with both code under test and valgrind compiled with GCC 11.1.0.
Comment 3 bug.reporter42 2021-11-29 22:49:12 UTC
(In reply to Paul Floyd from comment #1)
> Which compiler are you using?

gcc 4.4.7; however, I also tried using gcc 4.8, 4.9 and 7.4 with the same results.
Comment 4 Paul Floyd 2021-11-29 22:51:36 UTC
I'll see if I can access a RHEL 6.7 machine.
Comment 5 Paul Floyd 2021-12-02 14:40:08 UTC
I tried this on a machine
Red Hat Enterprise Linux Workstation release 6.7 (Santiago)

$ gcc --version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-16)

I had difficulty building Valgrind due to as not understanding rdseed (https://bugs.kde.org/show_bug.cgi?id=440502). I made a few changes to hard code out rdseed.

The result was no problem running valgrind.
Comment 6 bug.reporter42 2021-12-02 18:52:05 UTC
(In reply to Paul Floyd from comment #5)
> I tried this on a machine
> Red Hat Enterprise Linux Workstation release 6.7 (Santiago)
> 
> $ gcc --version
> gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-16)
> 
> I had difficulty building Valgrind due to as not understanding rdseed
> (https://bugs.kde.org/show_bug.cgi?id=440502). I made a few changes to hard
> code out rdseed.
> 
> The result was no problem running valgrind.

Agreed, I can run valgrind with some binaries just fine, but on a more complicated program that accesses libmagic, I get the failure. A simple test program using libmagic succeeds. (Like the "file" command). I'm not a liberty to provide you with the binary that produces the problem which is why I attached the debug log from valgrind running the problematic program.
Comment 7 bug.reporter42 2021-12-13 11:00:26 UTC
Is there any further information that I can provide to help track down this issue? We are unable to use the latest version of valgrind due to this problem. Thank you.
Comment 8 Paul Floyd 2021-12-14 11:56:59 UTC
Again I can't reproduce this with 'file'. git HEAD with this small change

$ git diff
diff --git a/VEX/priv/guest_amd64_helpers.c b/VEX/priv/guest_amd64_helpers.c
index ba71c1b..5269d78 100644
--- a/VEX/priv/guest_amd64_helpers.c
+++ b/VEX/priv/guest_amd64_helpers.c
@@ -3951,7 +3951,7 @@ ULong amd64g_dirtyhelper_RDRAND ( void ) {
 }

 ULong amd64g_dirtyhelper_RDSEED ( void ) {
-#  if defined(__x86_64__)
+#  if defined(__x86_64__) && 0
    ULong res   = 0;
    ULong cflag = 0;
    __asm__ __volatile__(


$ cat /etc/redhat-release
Red Hat Enterprise Linux Workstation release 6.7 (Santiago)

$ ./vg-in-place -q file ./build.ksh
./build.ksh: Korn shell script text executable

$ ls -al  /usr/lib64/libmagic.so.1.0.0
-rwxr-xr-x 1 root root 118112 Aug  4  2014 /usr/lib64/libmagic.so.1.0.0

$ rpm -q --whatprovides /usr/lib64/libmagic.so.1.0.0
file-libs-5.04-21.el6.x86_64