Fix snmpd crash (#3312)

* Enable debug image build for kvm image.

* Fix a bug in cleaning up requests referring the netsmp_session being closed to avoid a crash, during netsnmp_session close/abort due to timeout.
RCA:
The netsnmp_agent_session requests use netsmp_subtree objects that matches the associated variable name.
The netsnmp_subtrees created through a netsnmp_session are tied to that session.
When a subagent connection is closed/dropped due to timeout, all associated netsnmp_subtree objects are fred.
Hence during a netsnmp_session close, all the delegated netsnmp_agent_sessions are scanned for requets that could be using netsnmp_subtree objects associated with this netsnmp_sesssion or its subsession. For each of the found request, they are explicitly marked to fail and a call is made to complete them.

But due to the bug in scanning, it leaves behind requests and hence later when the requests get processed, they refer the *now* freed netsnmp_subtree. As often these requests gets completed pretty soon, they escape crashing. But if it so happens that the freed memory happened to complete a memory unit, hence returned to kernel or it got reallocated & changed enough to crash, the snmpd crashes.

* Revert the changes

* Revert
This commit is contained in:
Renuka Manavalan 2019-08-09 10:29:16 -07:00 committed by GitHub
parent 3e6e037d67
commit c035be688c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,26 @@
From 84846206c7ee230bd7b6274af98513952c4a7a7f Mon Sep 17 00:00:00 2001
From: Renuka Manavalan <remanava@microsoft.com>
Date: Wed, 7 Aug 2019 21:48:33 +0000
Subject: [PATCH] Release all requests that use this session.
---
agent/snmp_agent.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/agent/snmp_agent.c b/agent/snmp_agent.c
index b96d650..ee3b0da 100644
--- a/agent/snmp_agent.c
+++ b/agent/snmp_agent.c
@@ -1542,7 +1542,8 @@ netsnmp_remove_delegated_requests_for_session(netsnmp_session *sess)
* check each request
*/
netsnmp_request_info *request;
- for(request = asp->requests; request; request = request->next) {
+ int i;
+ for(i = 0, request = asp->requests; i < asp->vbcount; ++i, ++request) {
/*
* check session
*/
--
2.17.1

View File

@ -3,3 +3,4 @@
0003-CHANGES-BUG-2743-snmpd-crashes-when-receiving-a-GetN.patch 0003-CHANGES-BUG-2743-snmpd-crashes-when-receiving-a-GetN.patch
0004-Disable-SNMPv1.patch 0004-Disable-SNMPv1.patch
0005-Port-OpenSSL-1.1.0-with-support-for-1.0.2.patch 0005-Port-OpenSSL-1.1.0-with-support-for-1.0.2.patch
0006-Release-all-requests-that-use-this-session.patch