Bug 220943

Summary: devel/valgrind Segmentation fault
Product: Ports & Packages Reporter: Martin Filla <freebsd>
Component: Individual Port(s)Assignee: Niclas Zeising <zeising>
Status: Closed Overcome By Events    
Severity: Affects Only Me CC: code, jdc, lwhsu, paulf, w.schwarzenfeld
Priority: ---    
Version: Latest   
Hardware: amd64   
OS: Any   
Attachments:
Description Flags
Mention additional requirements in pkg-message none

Description Martin Filla 2017-07-23 13:29:18 UTC
Hello i installed valgrind but cannot launch.

Version - valgrind-3.10.1.20160113_4,1
OS - FreeBSD  11.0-RELEASE-p9

$ valgrind --version 
Segmentation fault (core dumped)
Comment 1 Martin Filla 2017-07-23 14:43:25 UTC
From gdb

There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd"...
(gdb) run 
Starting program: /usr/local/bin/valgrind 

Program terminated with signal SIGSEGV, Segmentation fault.

Then i compiled with WITH_DEBUG=yes but result is same
Comment 2 Martin Filla 2017-08-10 15:05:46 UTC
Valgrind need root permits :-)
Comment 3 Bryan Drewery freebsd_committer freebsd_triage 2017-08-10 17:43:04 UTC
Valgrind does not need root!
Comment 4 Martin Filla 2017-08-21 21:59:43 UTC
Hi , do you need some logs or any information about this problem ?
Comment 5 Brad Sliger 2017-08-23 15:00:42 UTC
It looks like this just happened to me on FreeBSD 11, with a custom kernel config and the installer-provided hardening options enabled.  I enabled unprivileged debugging (sysctl security.bsd.unprivileged_proc_debug=1) and rebuilt my kernel to include FreeBSD 10 compatibility (options COMPAT_FREEBSD10), then valgrind started working better.  A reconstructed session looks like this:

% sudo sysctl security.bsd.unprivileged_proc_debug
security.bsd.unprivileged_proc_debug: 0
% valgrind ./sample
zsh: segmentation fault  valgrind ./sample
% sudo sysctl security.bsd.unprivileged_proc_debug=1
security.bsd.unprivileged_proc_debug: 0 -> 1
% valgrind ./sample
==5611== Memcheck, a memory error detector
==5611== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==5611== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==5611== Command: ./sample
==5611==
zsh: invalid system call  valgrind ./sample
% truss valgrind ./sample
(Lots of output elided.)
pread(0x3,0x4028f0d70,0x2000,0x63e000)     = 8192 (0x2000)
close(3)           = 0 (0x0)
compat10.pipe()          ERR#78 'Function not implemented'
SIGNAL 12 (SIGSYS)
process killed, signal = 12
(Kernel rebuild, install, and reboot elided.)
% valgrind ./sample
==67066== Memcheck, a memory error detector
==67066== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==67066== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==67066== Command: ./sample
==67066== 
(Output elided.)
==67066== 
==67066== HEAP SUMMARY:
==67066==     in use at exit: 0 bytes in 0 blocks
==67066==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==67066== 
==67066== All heap blocks were freed -- no leaks are possible
==67066== 
==67066== For counts of detected and suppressed errors, rerun with: -v
==67066== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Comment 6 Brad Sliger 2017-08-23 15:50:33 UTC
Created attachment 185695 [details]
Mention additional requirements in pkg-message

In case it helps, I've included a patch to pkg-message that mentions what I found.
Comment 7 Martin Filla 2017-08-24 15:31:48 UTC
I tested % sudo sysctl security.bsd.unprivileged_proc_debug=1, yes this change is  a functional change.
Comment 8 Bryan Drewery freebsd_committer freebsd_triage 2017-10-18 17:25:52 UTC
(In reply to Brad Sliger from comment #5)
> It looks like this just happened to me on FreeBSD 11, with a custom kernel
> config and the installer-provided hardening options enabled.  I enabled
> unprivileged debugging (sysctl security.bsd.unprivileged_proc_debug=1) and
> rebuilt my kernel to include FreeBSD 10 compatibility (options
> COMPAT_FREEBSD10), then valgrind started working better.  A reconstructed
> session looks like this:
> 
> % sudo sysctl security.bsd.unprivileged_proc_debug
> security.bsd.unprivileged_proc_debug: 0
> % valgrind ./sample
> zsh: segmentation fault  valgrind ./sample
> % sudo sysctl security.bsd.unprivileged_proc_debug=1
> security.bsd.unprivileged_proc_debug: 0 -> 1
> % valgrind ./sample
> ==5611== Memcheck, a memory error detector

valgrind really shouldn't be crashing here. We should show a message about
the issue.

Thanks for the investigation, I'll write up a patch to fix the
crash and show a message.
Comment 9 Jeremy Chadwick 2018-03-06 08:46:29 UTC
I ran into this today on stable/11 (r330260).  I tried three separate times, including a final time via "sudo valgrind ...".

security.bsd.unprivileged_proc_debug was 1 (default), but my custom kernel intentionally omits "options COMPAT_FREEBSD10".

The crashes I got were not SIGSEGV (11) but SIGSYS (12) as demonstrated in c#5 (it's easy to overlook that line).  Kernel logged these as such:

pid 33167 (memcheck-amd64-free), uid 1000: exited on signal 12 (core dumped)
pid 33245 (memcheck-amd64-free), uid 0: exited on signal 12 (core dumped)
pid 33244 (sudo), uid 0: exited on signal 12

Just noting all this here as a form of "this is still a problem 7 months later".
Comment 10 Bryan Drewery freebsd_committer freebsd_triage 2018-03-06 18:19:41 UTC
(In reply to Jeremy Chadwick from comment #9)
> I ran into this today on stable/11 (r330260).  I tried three separate times,
> including a final time via "sudo valgrind ...".
> 
> security.bsd.unprivileged_proc_debug was 1 (default), but my custom kernel
> intentionally omits "options COMPAT_FREEBSD10".
> 
> The crashes I got were not SIGSEGV (11) but SIGSYS (12) as demonstrated in
> c#5 (it's easy to overlook that line).  Kernel logged these as such:
> 
> pid 33167 (memcheck-amd64-free), uid 1000: exited on signal 12 (core dumped)
> pid 33245 (memcheck-amd64-free), uid 0: exited on signal 12 (core dumped)
> pid 33244 (sudo), uid 0: exited on signal 12
> 
> Just noting all this here as a form of "this is still a problem 7 months
> later".

Thanks for the reminder. I don't consider this high priority since
COMPAT_FREEBSD10 is all-but-required in general IMO.  But I do consider
this a bug worth fixing.
Comment 11 Walter Schwarzenfeld freebsd_triage 2018-03-07 16:25:11 UTC
Possible duplicate of Bug #209886.
Comment 12 Walter Schwarzenfeld freebsd_triage 2019-03-10 11:48:51 UTC
Assign to new maintainer.
Comment 13 Martin Filla 2019-10-13 22:31:53 UTC
Hello, 
and result this bug ?
Comment 14 Martin Filla 2019-11-20 22:37:03 UTC
ping
Comment 15 Paul Floyd 2020-04-17 05:34:31 UTC
(In reply to Martin FIlla from comment #14)

Can you try the code in my github repo (https://github.com/paulfloyd/freebsd_valgrind)?

I'll add a check for the security.bsd.unprivileged_proc_debug soon.
Comment 16 Paul Floyd 2020-04-17 21:03:17 UTC
This is now fixed in my github repo(https://github.com/paulfloyd/freebsd_valgrind)

With the sysctl set

root@euler:/usr/include # sysctl security.bsd.unprivileged_proc_debug=1
security.bsd.unprivileged_proc_debug: 0 -> 1


paulf> ./vg-in-place --tool=none ./leakcpp.clang++
==2894== Nulgrind, the minimal Valgrind tool
==2894== Copyright (C) 2002-2017, and GNU GPL'd, by Nicholas Nethercote.
==2894== Using Valgrind-3.16.0.GIT and LibVEX; rerun with -h for copyright info
==2894== Command: ./leakcpp.clang++
==2894== 
==2894== 
euler:/usr/home/paulf/scratch/valgrind

With the sysctl cleared

paulf> ./vg-in-place --tool=none ./leakcpp.clang++
--6443:0:    main Valgrind: FATAL:
--6443:0:    main security.bsd.unprivileged_proc_debug sysctl is 0.
--6443:0:    main    Set this sysctl with
--6443:0:    main    'sysctl security.bsd.unprivileged_proc_debug=1'.
--6443:0:    main    Cannot continue.
euler:/usr/home/paulf/scratch/valgrind

This has to be very early in the tool execution, before the address space manager starts.
Comment 17 Paul Floyd 2020-07-30 11:40:32 UTC
This should now be fixed in devel/valgrind-devel and this item can be closed.
Comment 18 Kubilay Kocak freebsd_committer freebsd_triage 2020-09-20 09:42:45 UTC
^Triage: Unless a specific change (usually commit) can be identified that resolved the issue, OBE is more appropriate.