Bug 377376

Summary: memcheck/tests/linux/getregset fails with glibc2.24
Product: [Developer tools] valgrind Reporter: Aleksandra Karadzic <aleksandra.karadzic>
Component: memcheckAssignee: Julian Seward <jseward>
Status: RESOLVED FIXED    
Severity: normal CC: ivosh, mips32r2
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: Fix ptrace(traceme)
Test case
Fix ptrace(traceme)
Fix for broken build on Solaris and Mac

Description Aleksandra Karadzic 2017-03-08 12:30:00 UTC
Created attachment 104448 [details]
Fix ptrace(traceme)

In glibc2.24 implementation of function raise() is changed, so this test crashes when it is run under Valgrind. 
Signal SIGUSR1 should stop the process, but when it is called with ptrace(traceme), expected behaviour is to stop process. In Valgrind there is no valid support for ptrace(traceme) syscall.
I propose fix for this problem.
Comment 1 Aleksandra Karadzic 2017-03-08 12:35:01 UTC
Created attachment 104449 [details]
Test case

This is example that shows problem on boards that have version of glibc older then glibc2.24.

$ gcc -g traceme.c -o traceme

$ ./vg-in-place --tool=none ./traceme
==23581== Nulgrind, the minimal Valgrind tool
==23581== Copyright (C) 2002-2015, and GNU GPL'd, by Nicholas Nethercote.
==23581== Using Valgrind-3.13.0.SVN and LibVEX; rerun with -h for copyright info
==23581== Command: /home/aca/test-primeri/traceme
==23581==
==23582==
==23582== Process terminating with default action of signal 10 (SIGUSR1)
==23582==    at 0x4C5CEE0: sigprocmask (sigprocmask.c:39)
==23582==    by 0x400736: do_child (traceme.c:17)
==23582==    by 0x400758: main (traceme.c:26)
==23582==
==23581==

valgrind: the 'impossible' happened:
   main(): signal was supposed to be fatal

host stacktrace:
==23582==    at 0x380E15D3: show_sched_status_wrk (m_libcassert.c:378)

sched status:
  running_tid=1
Comment 2 Aleksandra Karadzic 2017-03-08 14:29:55 UTC
Created attachment 104456 [details]
Fix ptrace(traceme)
Comment 3 Petar Jovanovic 2017-03-14 15:05:09 UTC
The patch looks good to me. Anyone has any objections?
Comment 4 Ivo Raisr 2017-03-14 17:18:11 UTC
Please could you point me to a resource which describes interaction between tracer and tracee with respect to PTRACE_TRACEME.
In particular, I'd like to know when flag tst->ptrace (as set in  linux_POST_traceme()) gets reset back to 0?

Are you going to incorporate the provided test case into Valgrind regression test suite? That would be useful!
Comment 5 Aleksandra Karadzic 2017-03-15 12:49:21 UTC
I don`t have any specific documentation, I was looking implementation in kernel, file kernel/ptrace.c:339.
It looks like flag tst->ptrace is reset only when the tracer exits, I am afraid that we can not implement this in Valgrind.
This test is already in test suits memcheck/linux/getregset.c, we just add masking signal before calling raise(), which exists in wrapper for raise in glibc-2.24.
Comment 6 Ivo Raisr 2017-03-15 13:04:47 UTC
Fair enough. Thank you for the explanation.
Comment 7 Petar Jovanovic 2017-03-15 15:25:18 UTC
(In reply to Aleksandra Karadzic from comment #2)
> Created attachment 104456 [details]
> Fix ptrace(traceme)

The patch committed in r16273.
Thank you.
Comment 8 Aleksandra Karadzic 2017-03-16 10:14:47 UTC
Created attachment 104596 [details]
Fix for broken build on Solaris and Mac

We have some complains from Solaris and Mac developers about this patch, this is our fix for broken build. Ivo can you test this patch on Solaris?
Comment 9 Ivo Raisr 2017-03-16 13:12:14 UTC
Thank you for the patch. Indeed, it unbreaks the build.

"some complaints" is an euphemism here :-)
Valgrind build was effectively broken on two thirds of supported OSes :-)
Comment 10 Petar Jovanovic 2017-03-16 13:14:47 UTC
I have committed the build fix as r16275.