Bug 2157662

Summary: Cannot execute valgrind due to lack of memory (which is not true)
Product: Red Hat Enterprise Linux 8 Reporter: Renaud Métrich <rmetrich>
Component: valgrindAssignee: Mark Wielaard <mjw>
valgrind sub component: system-version QA Contact: Jesus Checa <jchecahi>
Status: CLOSED ERRATA Docs Contact:
Severity: medium    
Priority: medium CC: fweimer, jakub, mcermak, ohudlick, wcohen
Version: 8.7Keywords: Triaged
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: valgrind-3.21.0-2.el8 Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-11-14 15:32:03 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:
Embargoed:

Description Renaud Métrich 2023-01-02 14:52:55 UTC
Description of problem:

When SELinux "deny_execmem" boolean is enabled, Valgrind always dies with not being able to allocate 32GB, e.g.:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
# /usr/bin/valgrind --tool=memcheck --leak-check=yes --trace-children=yes --track-origins=yes /usr/sbin/rsyslogd -n
[...]
==54482==     Valgrind's memory management: out of memory:
==54482==        newSuperblock's request for 4194304 bytes failed.
==54482==           27,475,968 bytes have already been mmap-ed ANONYMOUS.
==54482==     Valgrind cannot continue.  Sorry.
[...]
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

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

valgrind-3.19.0-1.el8

How reproducible:

Always

Comment 1 Mark Wielaard 2023-01-02 21:51:51 UTC
It looks like deny_execmem is off by default. At least on my setup:
$ getsebool deny_execmem
deny_execmem --> off

If I enable it my desktop crashes... both gnome-shell and firefox dump core.
Apparently both use a javascript JIT runtime.

Is this a supported setup?
valgrind needs a executable memory for its VEX jit.

Comment 2 Renaud Métrich 2023-01-03 07:32:52 UTC
It is supported, at least on non-GUI systems.
The issue here is more with dying with another message that not being able to allocate memory (it would be not being able to *execute* memory instead).

Comment 3 Mark Wielaard 2023-01-09 11:40:13 UTC
(In reply to Renaud Métrich from comment #2)
> It is supported, at least on non-GUI systems.
> The issue here is more with dying with another message that not being able
> to allocate memory (it would be not being able to *execute* memory instead).

Aha, ok, so it is about giving a better error message if deny_execmem is on. That should be doable.

Comment 4 Mark Wielaard 2023-01-23 09:04:30 UTC
Submitted a patch upstream https://bugs.kde.org/show_bug.cgi?id=464680
With that the error message will show Permission denied and includes a hint about selinux deny_execmem:

==509341== 
==509341==     Valgrind's memory management: out of memory: Permission denied
==509341==        newSuperblock's request for 4194304 bytes failed.
==509341==           27,480,064 bytes have already been mmap-ed ANONYMOUS.
==509341==     Valgrind cannot continue.  Sorry.
==509341== 
==509341==     There are several possible reasons for this.
==509341==     - You have some kind of memory limit in place.  Look at the
==509341==       output of 'ulimit -a'.  Is there a limit on the size of
==509341==       virtual memory or address space?
==509341==     - You have run out of swap space.
==509341==     - You have some policy enabled that denies memory to be
==509341==       executable (for example selinux deny_execmem) that causes
==509341==       mmap to fail with Permission denied.
==509341==     - Valgrind has a bug.  If you think this is the case or you are
==509341==     not sure, please let us know and we'll try to fix it.
==509341==     Please note that programs can take substantially more memory than
==509341==     normal when running under Valgrind tools, eg. up to twice or
==509341==     more, depending on the tool.  On a 64-bit machine, Valgrind
==509341==     should be able to make use of up 32GB memory.  On a 32-bit
==509341==     machine, Valgrind should be able to use all the memory available
==509341==     to a single process, up to 4GB if that's how you have your
==509341==     kernel configured.  Most 32-bit Linux setups allow a maximum of
==509341==     3GB per process.
==509341== 
==509341==     Whatever the reason, Valgrind cannot continue.  Sorry.

Comment 5 Renaud Métrich 2023-01-23 09:43:08 UTC
Thanks a lot, it's more explanatory now.

Comment 13 errata-xmlrpc 2023-11-14 15:32:03 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (valgrind bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2023:6953