Bug 678314

Summary: snmptrapd leaks memory when NetSNMP::TrapReceiver is used for trap handlers
Product: Red Hat Enterprise Linux 6 Reporter: Jan Safranek <jsafrane>
Component: net-snmpAssignee: Jan Safranek <jsafrane>
Status: CLOSED ERRATA QA Contact: BaseOS QE Security Team <qe-baseos-security>
Severity: medium Docs Contact:
Priority: medium    
Version: 6.0CC: ksrot, mgrimm, rvokal, vineela048
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
The previous version of snmptrapd, the Net-SNMP daemon for processing traps, leaked memory when processing incoming SNMP traps in embedded Perl. This caused the amount of consumed memory to grow over time, making the memory consumption was even larger if the daemon was processing SNMPv1 traps. With this update, the underlying source code has been adapted to prevent such memory leaks, and processing incoming SNMP traps in embedded Perl no longer increases the memory consumption. (BZ#678314).
Story Points: ---
Clone Of: 676955
: 1086761 (view as bug list) Environment:
Last Closed: 2011-12-06 17:11:33 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 676955    
Bug Blocks: 1086761    

Description Jan Safranek 2011-02-17 14:54:16 UTC
+++ This bug was initially created as a clone of Bug #676955 +++

Description of problem:
The NetSNMP::TrapReceiver Perl module distributed in the net-snmp-perl package leaks memory when it is used to register an SNMP trap handler with the snmptrapd process.

Version-Release number of selected component (if applicable):
net-snmp-perl 5.3.2.2-9.el5_5.1
NetSNMP::TrapReceiver 5.03022

How reproducible:
Every time.

Steps to Reproduce:
1. Create a no-op Perl trap handler with this code:

#!/usr/bin/perl
use SNMP;
sub my_receiver {}
NetSNMP::TrapReceiver::register("all", \&my_receiver)
    or warn "Failed to register Perl trap handler\n";
print "Registered Perl trap handler\n";

2. Configure snmptrapd using this line in /etc/snmp/snmptrapd.conf:

perl do "/path/to/subagent";

3. Run snmptrapd with valgrind's memcheck tool:

valgrind -v --leak-check=yes /usr/sbin/snmptrapd -Lsd -p /var/run/snmptrapd.pid -f

4. When the "Registered Perl trap handler" message appears, send one or more traps to the server.

5. Quit valgrind and snmptrapd with ctrl-c. This will display the memcheck report.
  
Actual results:
snmptrapd leaks memory. This is amplified the more traps are sent to the receiver. Eventually, on a busy server, snmptrapd consumes all available memory on the system.

Expected results:
snmptrapd runs memcheck-clean (does not leak memory). Remove the "perl do" line from /etc/snmp/snmptrapd.conf and run the valgrind command in step 3 again and the result will be memcheck-clean.

Comment 1 Jan Safranek 2011-02-17 14:55:01 UTC
The leak appears only when processing V1 traps and it has been fixed upstream:
http://net-snmp.svn.sourceforge.net/viewvc/net-snmp?view=revision&revision=19335

Comment 4 Jan Safranek 2011-08-11 11:32:14 UTC
    Technical note added. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    New Contents:
The previous version of snmptrapd, the Net-SNMP daemon for processing traps, leaked memory when processing incoming SNMP traps in embedded Perl. This caused the amount of consumed memory to grow over time, making the memory consumption was even larger if the daemon was processing SNMPv1 traps. With this update, the underlying source code has been adapted to prevent such memory leaks, and processing incoming SNMP traps in embedded Perl no longer increases the memory consumption. (BZ#678314).

Comment 7 errata-xmlrpc 2011-12-06 17:11:33 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, and where to find the updated
files, follow the link below.

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

http://rhn.redhat.com/errata/RHBA-2011-1524.html

Comment 8 vineela048 2014-01-23 07:01:33 UTC
Hi,

I have tried with all the versions of net-snmp from net-snmp-5.4 till net-snmp-5.7.2 and I still see the memory leak issue for V1 traps. My CPU usage goes quite high with %MEM keeps getting accumulated. 

Below are the statistics -

%CPU Usage - 56.0
%MEM - 8.1
VIRT - 811m
RES - 637m
SHR - 2124

Can you please confirm if this issue has been truly fixed? If so, what is the correct resolution?


Thanks,
Vineela

Comment 9 Jan Safranek 2014-03-06 13:19:26 UTC
(In reply to vineela048 from comment #8)
> Hi,
> 
> I have tried with all the versions of net-snmp from net-snmp-5.4 till
> net-snmp-5.7.2 and I still see the memory leak issue for V1 traps. My CPU
> usage goes quite high with %MEM keeps getting accumulated. 
> 
> Below are the statistics -
> 
> %CPU Usage - 56.0
> %MEM - 8.1
> VIRT - 811m
> RES - 637m
> SHR - 2124
> 
> Can you please confirm if this issue has been truly fixed? If so, what is


The issue described in this bug has been truly fixed, tested today with net-snmp-5.5-49.el6.x86_64. Maybe you experience some other leak or bug. Please keep in mind that bugzilla is not a support tool or means of accessing support. If you would like technical support please visit our support portal at access.redhat.com or