The patch below resolves a "Arithmetic exception (core dumped)" when
performing once snmwalk or snmpget access agent hardware memory
information. Also, on sparc64 the unpatched snmpd consumes all CPU and
memory resources within minutes after starting as in the background.
Interestingly, if run in the foreground (snmpd -f)., it does not hog
those resources and behaves.

Without this patch, these problems occur on sparc64-current, whereas
on i386-current I did not observe them. I noticed the problems already
in 4.1 and before upgrading to net-snmp-5.4.1, but back then, I never
got around to track it down.

Please test and propose improvements for my somewhat naive,
quick&dirty patch before committing. I do not understand the details
of sysctl and uvmexp yet, thus just used getpagesize(3).

OK on sparc64.

Thanks,
Rolf


# diff -urN net-snmp net-snmp-5.4.1p1
diff -urN net-snmp/Makefile net-snmp-5.4.1p1/Makefile
--- net-snmp/Makefile   Wed Sep 26 22:03:42 2007
+++ net-snmp-5.4.1p1/Makefile   Sun Oct  7 09:40:05 2007
@@ -4,7 +4,7 @@
 COMMENT-perl=  SNMP modules for Perl

 DISTNAME=      net-snmp-5.4.1
-PKGNAME-main=  ${DISTNAME}
+PKGNAME-main=  ${DISTNAME}p1
 PKGNAME-perl=  p5-SNMP-5.4.1
 SHARED_LIBS=   netsnmp         7.0     \
                netsnmpagent    7.0     \
diff -urN net-snmp/patches/patch-agent_mibgroup_hardware_memory_memory_netbsd_c
net-snmp-5.4.1p1/patches/patch-agent_mibgroup_hardware_memory_memory_netbsd_c
--- net-snmp/patches/patch-agent_mibgroup_hardware_memory_memory_netbsd_c
      Thu Jan  1 01:00:00 1970
+++ 
net-snmp-5.4.1p1/patches/patch-agent_mibgroup_hardware_memory_memory_netbsd_c
      Sun Oct  7 09:42:54 2007
@@ -0,0 +1,29 @@
+--- agent/mibgroup/hardware/memory/memory_netbsd.c.orig Mon Mar  6
17:23:52 2006
++++ agent/mibgroup/hardware/memory/memory_netbsd.c      Sun Oct  7
09:33:56 2007
+@@ -30,7 +30,11 @@
+     long           pagesize;
+
+     struct uvmexp  uvmexp;
+-    int            uvmexp_size  = sizeof(uvmexp);
++    #ifdef __OpenBSD__
++     size_t        uvmexp_size  = sizeof(uvmexp);
++    #else
++     int           uvmexp_size  = sizeof(uvmexp);
++    #endif
+     int            uvmexp_mib[] = { CTL_VM, VM_UVMEXP };
+
+     struct vmtotal total;
+@@ -50,7 +54,11 @@
+     sysctl(total_mib,    2, &total,    &total_size,    NULL, 0);
+     sysctl(phys_mem_mib, 2, &phys_mem, &mem_size,      NULL, 0);
+     sysctl(user_mem_mib, 2, &user_mem, &mem_size,      NULL, 0);
+-    pagesize = uvmexp.pagesize;
++    #ifdef __OpenBSD__
++     pagesize = getpagesize();
++    #else
++     pagesize = uvmexp.pagesize;
++    #endif
+
+     /*
+      * ... and save this in a standard form.
+
#


Here is an illustration of the problem on sparc64-current

A) snmpd.conf is minimal:

# cat /etc/snmp/snmpd.conf
rocommunity  public


B) snmpd run in the foreground within gdb

[EMAIL PROTECTED]:snmp]# gdb /usr/local/sbin/snmpd
GNU gdb 6.3
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "sparc64-unknown-openbsd4.2"...(no
debugging symbols found)

(gdb) run -f -Lo -D
..
verbose:sess_select: timer due in 4.996670 sec
verbose:sess_select: setting timer to 4.996670 sec, clear block (was 0)
trace: receive(): snmpd.c, 1144:
snmpd/select: select( numfds=12, ..., tvp=0xfffffffffffead10)
trace: receive(): snmpd.c, 1146:
timer: tvp 4.996670
trace: receive(): snmpd.c, 1148:
snmpd/select: returned, count = 0
trace: run_alarms(): snmp_alarm.c, 251:
snmp_alarm: run alarm 2
trace: netsnmp_cpu_get_byIdx(): hardware/cpu/cpu.c, 69:
cpu: cpu_get_byIdx -1 (found)
trace: netsnmp_cpu_get_byIdx(): hardware/cpu/cpu.c, 69:
cpu: cpu_get_byIdx 0 (found)
trace: run_alarms(): snmp_alarm.c, 253:
snmp_alarm: alarm 2 completed
trace: snmp_sess_select_info(): snmp_api.c, 5868:
sess_select: for all sessions: 11 7
sess_select: next alarm 4.996349 sec
verbose:sess_select: timer due in 4.996349 sec
verbose:sess_select: setting timer to 4.996349 sec, clear block (was 0)
trace: receive(): snmpd.c, 1144:
snmpd/select: select( numfds=12, ..., tvp=0xfffffffffffead10)
trace: receive(): snmpd.c, 1146:
timer: tvp 4.996349
..
{
 C) the above repeats until we launch from another host:
  $ snmpwalk -v 2c -c public 172.16.71.6 .
}
..
trace: netsnmp_view_subtree_check(): vacm.c, 532:
9:vacm:checkSubtree: view _all_
trace: netsnmp_view_subtree_check(): vacm.c, 569:
9:vacm:checkSubtree:  _all_ matched?
trace: netsnmp_view_subtree_check(): vacm.c, 630:
9:vacm:checkSubtree:  (null) matched
trace: netsnmp_view_subtree_check(): vacm.c, 653:
vacm:checkSubtree: , included
trace: snmp_call_callbacks(): callback.c, 336:
callback: END calling callbacks for maj=1 min=12 (1 called)
trace: _callback_unlock(): callback.c, 152:
9:callback:lock: unlocked (APP,null)
trace: netsnmp_add_varbind_to_cache(): snmp_agent.c, 1941:
snmp_agent: tp->start HOST-RESOURCES-MIB::hrMemorySize, tp->end
HOST-RESOURCES-MIB::hrStorageTable,
trace: netsnmp_add_varbind_to_cache(): snmp_agent.c, 1961:
verbose:asp: asp 0x41e5fd00 reqinfo 0x47329ea0 assigned to request
trace: netsnmp_add_varbind_to_cache(): snmp_agent.c, 1968:
verbose:asp: asp 0x41e5fd00 reqinfo 0x47329ea0 assigned to request
trace: netsnmp_call_handlers(): agent_handler.c, 510:
handler:calling: main handler bulk_to_next
trace: netsnmp_call_handler(): agent_handler.c, 430:
handler:calling: calling handler bulk_to_next for mode GETNEXT
trace: netsnmp_call_handler(): agent_handler.c, 438:
handler:returned: handler bulk_to_next returned 0
trace: netsnmp_call_handler(): agent_handler.c, 430:
handler:calling: calling handler old_api for mode GETNEXT
trace: header_hrstore(): host/hr_storage.c, 342:
host/hr_storage: var_hrstore: HOST-RESOURCES-MIB::hrSystemProcesses.0 0

Program received signal SIGFPE, Arithmetic exception.
0x0000000048813e3c in netsnmp_mem_arch_load () from
/usr/local/lib/libnetsnmpmibs.so.7.0
(gdb)  bt
#0  0x0000000048813e3c in netsnmp_mem_arch_load () from
/usr/local/lib/libnetsnmpmibs.so.7.0
#1  0x000000004d59cc28 in _cache_load () from
/usr/local/lib/libnetsnmphelpers.so.7.0
#2  0x00000000487c9fa0 in var_hrstore () from
/usr/local/lib/libnetsnmpmibs.so.7.0
#3  0x000000004d5a0ff4 in netsnmp_old_api_helper ()
   from /usr/local/lib/libnetsnmphelpers.so.7.0
#4  0x000000004f9321d8 in netsnmp_call_handler () from
/usr/local/lib/libnetsnmpagent.so.7.0
#5  0x000000004f932428 in netsnmp_call_handlers () from
/usr/local/lib/libnetsnmpagent.so.7.0
#6  0x000000004f927618 in handle_var_requests () from
/usr/local/lib/libnetsnmpagent.so.7.0
#7  0x000000004f9280c0 in handle_getnext_loop () from
/usr/local/lib/libnetsnmpagent.so.7.0
#8  0x000000004f928b80 in handle_pdu () from
/usr/local/lib/libnetsnmpagent.so.7.0
#9  0x000000004f9286c0 in netsnmp_handle_request () from
/usr/local/lib/libnetsnmpagent.so.7.0
#10 0x000000004f925e10 in handle_snmp_packet () from
/usr/local/lib/libnetsnmpagent.so.7.0
#11 0x0000000042203b1c in _sess_process_packet () from
/usr/local/lib/libnetsnmp.so.7.0
#12 0x00000000422049a0 in _sess_read () from /usr/local/lib/libnetsnmp.so.7.0
#13 0x000000004220507c in snmp_sess_read () from
/usr/local/lib/libnetsnmp.so.7.0
#14 0x0000000042203fb0 in snmp_read () from /usr/local/lib/libnetsnmp.so.7.0
#15 0x000000000010584c in main ()
(gdb)



D) last  output lines of the snmpwalk:
...
SNMPv2-MIB::snmpInReadOnlys.0 = Counter32: 0
SNMPv2-MIB::snmpInGenErrs.0 = Counter32: 0
SNMPv2-MIB::snmpInTotalReqVars.0 = Counter32: 515
SNMPv2-MIB::snmpInTotalSetVars.0 = Counter32: 0
SNMPv2-MIB::snmpInGetRequests.0 = Counter32: 44
SNMPv2-MIB::snmpInGetNexts.0 = Counter32: 475
SNMPv2-MIB::snmpInSetRequests.0 = Counter32: 0
SNMPv2-MIB::snmpInGetResponses.0 = Counter32: 0
SNMPv2-MIB::snmpInTraps.0 = Counter32: 0
SNMPv2-MIB::snmpOutTooBigs.0 = Counter32: 0
SNMPv2-MIB::snmpOutNoSuchNames.0 = Counter32: 0
SNMPv2-MIB::snmpOutBadValues.0 = Counter32: 0
SNMPv2-MIB::snmpOutGenErrs.0 = Counter32: 0
SNMPv2-MIB::snmpOutGetRequests.0 = Counter32: 0
SNMPv2-MIB::snmpOutGetNexts.0 = Counter32: 0
SNMPv2-MIB::snmpOutSetRequests.0 = Counter32: 0
SNMPv2-MIB::snmpOutGetResponses.0 = Counter32: 529
SNMPv2-MIB::snmpOutTraps.0 = Counter32: 0
SNMPv2-MIB::snmpEnableAuthenTraps.0 = INTEGER: disabled(2)
SNMPv2-MIB::snmpSilentDrops.0 = Counter32: 0
SNMPv2-MIB::snmpProxyDrops.0 = Counter32: 0
HOST-RESOURCES-MIB::hrSystemUptime.0 = Timeticks: (40599635) 4 days, 16:46:36.35
HOST-RESOURCES-MIB::hrSystemDate.0 = STRING: 2007-10-7,10:53:29.0,-190:26
HOST-RESOURCES-MIB::hrSystemInitialLoadDevice.0 = INTEGER: 1536
HOST-RESOURCES-MIB::hrSystemNumUsers.0 = Gauge32: 3
HOST-RESOURCES-MIB::hrSystemProcesses.0 = Gauge32: 20
Timeout: No Response from 172.16.71.6
$


E) inspecting the source
/usr/ports/net/net-snmp/w-net-snmp-5.4.1/net-snmp-5.4.1/agent/mibgroup/hardware/memory/memory_netbsd.c
reveals a division by zero, because pagesize was assigned 0.

Reply via email to