Bug 1029465

Summary: ltrace -f dies when tracing threads with pointers inside
Product: Red Hat Enterprise Linux 7 Reporter: Michael Petlan <mpetlan>
Component: ltraceAssignee: Petr Machata <pmachata>
Status: CLOSED CURRENTRELEASE QA Contact: Michael Petlan <mpetlan>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.0CC: mnewsome, ohudlick
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-06-13 11:00:36 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Attachments:
Description Flags
Reproducer script with necessary data none

Description Michael Petlan 2013-11-12 12:41:36 UTC
Description of problem:

When 'ltrace -f' is run on a binary which uses pointers in the thread function, the ltrace dies with 134 errorcode.

======= Here is the nesty thread function: ========

void *TaskCode(void *argument)
{
   unsigned int a = 0xDEADBEEF;
   unsigned int *ptr = &a;

   printf("I am a thread... a = %u  *ptr = %u  ptr = %p  \n", a, *ptr, ptr);

   return NULL;
}

======= Here is another thread function, which passes well: =======

void *TaskCode(void *argument)
{
   unsigned int a = 0xDEADBEEF;
   unsigned int *ptr = &a;

   printf("I am a thread... a = %u  *ptr = %u  \n", a, *ptr);

   return NULL;
}

======= The difference: =======

--- wrong.c	2013-11-12 13:09:04.870404143 +0100
+++ right.c	2013-11-12 13:12:02.108676760 +0100
@@ -12,7 +12,7 @@
    unsigned int a = 0xDEADBEEF;
    unsigned int *ptr = &a;
 
-   printf("I am a thread... a = %u  *ptr = %u  ptr = %p  \n", a, *ptr, ptr);
+   printf("I am a thread... a = %u  *ptr = %u  \n", a, *ptr);
 
    return NULL;
 }

........ so it seems that when I want to print the pointer's value (the target address), it causes ltrace to crash...

The attached reproducer contains both files - right.c and wrong.c - and this is the diff between them. The reproducer.sh script compiles them both and runs ltrace on them. The ltrace in the second case (wrong.c) falls down with 134 exitcode and some dump.


Version-Release number of selected component (if applicable):

ltrace-0.7.2-5.el7.x86_64
kernel-3.10.0-33.el7.x86_64

How reproducible:

Unpack & run the attached reproducer... or ...

Steps to Reproduce:
1. gcc -o wrong -lpthread wrong.c
2. ltrace -o ltrace.log -f ./wrong

Actual results:

ltrace dies with 134 and dump like this:

*** glibc detected *** ltrace: free(): invalid pointer: 0x0000000000629120 ***
======= Backtrace: =========
/lib64/libc.so.6[0x394ee7cb3e]
ltrace[0x409b28]
ltrace[0x40a3ab]
ltrace[0x40c041]
ltrace[0x40b3ee]
ltrace[0x416db8]
ltrace[0x417a79]
ltrace[0x4034ec]
ltrace[0x402f2e]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x394ee21a05]
ltrace[0x402f61]
======= Memory map: ========
00400000-00426000 r-xp 00000000 08:01 668887    /usr/bin/ltrace
00625000-00626000 r--p 00025000 08:01 668887    /usr/bin/ltrace
00626000-00628000 rw-p 00026000 08:01 668887    /usr/bin/ltrace
00628000-0062a000 rw-p 00000000 00:00 0 
00827000-00829000 rw-p 00027000 08:01 668887    /usr/bin/ltrace
00e42000-00ea5000 rw-p 00000000 00:00 0         [heap]
... 

Expected results:

The ltrace don't crash and traces as expected.

Additional info:

* When traced under strace, everything goes well.
* The bug occurs also on Fedora 18 with ltrace-0.7.2-1.fc18.x86_64

Comment 1 Michael Petlan 2013-11-12 12:48:25 UTC
Created attachment 822938 [details]
Reproducer script with necessary data

Comment 3 Michael Petlan 2013-11-12 14:57:39 UTC
The problem probably is somewhere in the printf-tracing.

This code is enough to cause the ltrace's fail, no threads are necessary:

-----------
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
   unsigned int a = 0xDEADBEEF;
   unsigned int *ptr = &a;
   printf("a = %u  *ptr = %u  ptr = %p  \n", a, *ptr, ptr);
   return 0;
}
-----------

gcc wrong.c
ltrace ./a.out

....

Comment 4 Petr Machata 2013-11-12 15:22:06 UTC
I believe this is fixed in ltrace-0.7.91-1.el7.  Upstream this was fixed in commits cae76962 (the fix) and cb943f1d (test cases).

Comment 7 Ludek Smid 2014-06-13 11:00:36 UTC
This request was resolved in Red Hat Enterprise Linux 7.0.

Contact your manager or support representative in case you have further questions about the request.

Comment 9 Fedora Update System 2015-11-09 13:08:49 UTC
filezilla-3.7.3-3.el6 has been submitted as an update to Fedora EPEL 6. https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2015-e180c5b56d