Blame SOURCES/net-snmp-5.7.2-icmp-mib.patch

9a6c41
1072092 - net-snmp: denial of service flaw in Linux implementation of ICMP-MIB
9a6c41
9a6c41
commit 8407b6ce46ca7159b3c816d1024e20a53f9a1c6c
9a6c41
Author: Wes Hardaker <hardaker@users.sourceforge.net>
9a6c41
Date:   Wed Feb 19 15:21:57 2014 -0800
9a6c41
9a6c41
    bug fix from fenner: fix ICMP mib table handling on linux
9a6c41
9a6c41
diff --git a/agent/mibgroup/mibII/icmp.c b/agent/mibgroup/mibII/icmp.c
9a6c41
index 14c73a6..6d10426 100644
9a6c41
--- a/agent/mibgroup/mibII/icmp.c
9a6c41
+++ b/agent/mibgroup/mibII/icmp.c
9a6c41
@@ -106,10 +106,20 @@ struct icmp_msg_stats_table_entry {
9a6c41
         int flags;
9a6c41
 };
9a6c41
 
9a6c41
+#ifdef linux
9a6c41
+/* Linux keeps track of all possible message types */
9a6c41
+#define ICMP_MSG_STATS_IPV4_COUNT 256
9a6c41
+#else
9a6c41
 #define ICMP_MSG_STATS_IPV4_COUNT 11
9a6c41
+#endif
9a6c41
 
9a6c41
 #ifdef NETSNMP_ENABLE_IPV6
9a6c41
+#ifdef linux
9a6c41
+/* Linux keeps track of all possible message types */
9a6c41
+#define ICMP_MSG_STATS_IPV6_COUNT 256
9a6c41
+#else
9a6c41
 #define ICMP_MSG_STATS_IPV6_COUNT 14
9a6c41
+#endif
9a6c41
 #else
9a6c41
 #define ICMP_MSG_STATS_IPV6_COUNT 0
9a6c41
 #endif /* NETSNMP_ENABLE_IPV6 */
9a6c41
@@ -177,7 +187,7 @@ icmp_msg_stats_load(netsnmp_cache *cache, void *vmagic)
9a6c41
     inc = 0;
9a6c41
     linux_read_icmp_msg_stat(&v4icmp, &v4icmpmsg, &flag;;
9a6c41
     if (flag) {
9a6c41
-        while (254 != k) {
9a6c41
+        while (255 >= k) {
9a6c41
             if (v4icmpmsg.vals[k].InType) {
9a6c41
                 icmp_msg_stats_table[i].ipVer = 1;
9a6c41
                 icmp_msg_stats_table[i].icmpMsgStatsType = k;
9a6c41
@@ -267,7 +277,7 @@ icmp_msg_stats_load(netsnmp_cache *cache, void *vmagic)
9a6c41
     inc = 0;
9a6c41
     linux_read_icmp6_msg_stat(&v6icmp, &v6icmpmsg, &flag;;
9a6c41
     if (flag) {
9a6c41
-        while (254 != k) {
9a6c41
+        while (255 >= k) {
9a6c41
             if (v6icmpmsg.vals[k].InType) {
9a6c41
                 icmp_msg_stats_table[i].ipVer = 2;
9a6c41
                 icmp_msg_stats_table[i].icmpMsgStatsType = k;
9a6c41
@@ -1050,6 +1060,12 @@ icmp_stats_table_handler(netsnmp_mib_handler  *handler,
9a6c41
 					continue;
9a6c41
 				table_info = netsnmp_extract_table_info(request);
9a6c41
 				subid      = table_info->colnum;
9a6c41
+				DEBUGMSGTL(( "mibII/icmpStatsTable", "oid: " ));
9a6c41
+				DEBUGMSGOID(( "mibII/icmpStatsTable", request->requestvb->name,
9a6c41
+						 request->requestvb->name_length ));
9a6c41
+				DEBUGMSG(( "mibII/icmpStatsTable", " In %d InErr %d Out %d OutErr %d\n",
9a6c41
+					      entry->icmpStatsInMsgs, entry->icmpStatsInErrors,
9a6c41
+					      entry->icmpStatsOutMsgs, entry->icmpStatsOutErrors ));
9a6c41
 
9a6c41
 				switch (subid) {
9a6c41
 					case ICMP_STAT_INMSG:
9a6c41
@@ -1117,6 +1133,11 @@ icmp_msg_stats_table_handler(netsnmp_mib_handler          *handler,
9a6c41
                     continue;
9a6c41
                 table_info = netsnmp_extract_table_info(request);
9a6c41
                 subid = table_info->colnum;
9a6c41
+                DEBUGMSGTL(( "mibII/icmpMsgStatsTable", "oid: " ));
9a6c41
+                DEBUGMSGOID(( "mibII/icmpMsgStatsTable", request->requestvb->name,
9a6c41
+                                 request->requestvb->name_length ));
9a6c41
+                DEBUGMSG(( "mibII/icmpMsgStatsTable", " In %d Out %d Flags 0x%x\n",
9a6c41
+                                 entry->icmpMsgStatsInPkts, entry->icmpMsgStatsOutPkts, entry->flags ));
9a6c41
 
9a6c41
                 switch (subid) {
9a6c41
                     case ICMP_MSG_STAT_IN_PKTS:
9a6c41
diff --git a/agent/mibgroup/mibII/kernel_linux.c b/agent/mibgroup/mibII/kernel_linux.c
9a6c41
index b21a166..ba320c7 100644
9a6c41
--- a/agent/mibgroup/mibII/kernel_linux.c
9a6c41
+++ b/agent/mibgroup/mibII/kernel_linux.c
9a6c41
@@ -81,9 +81,9 @@ decode_icmp_msg(char *line, char *data, struct icmp4_msg_mib *msg)
9a6c41
             index = strtol(token, &delim, 0);
9a6c41
             if (ERANGE == errno) {
9a6c41
                 continue;
9a6c41
-            } else if (index > LONG_MAX) {
9a6c41
+            } else if (index > 255) {
9a6c41
                 continue;
9a6c41
-            } else if (index < LONG_MIN) {
9a6c41
+            } else if (index < 0) {
9a6c41
                 continue;
9a6c41
             }
9a6c41
             if (NULL == (token = strtok_r(dataptr, " ", &saveptr1)))
9a6c41
@@ -94,9 +94,9 @@ decode_icmp_msg(char *line, char *data, struct icmp4_msg_mib *msg)
9a6c41
             index = strtol(token, &delim, 0);
9a6c41
             if (ERANGE == errno) {
9a6c41
                 continue;
9a6c41
-            } else if (index > LONG_MAX) {
9a6c41
+            } else if (index > 255) {
9a6c41
                 continue;
9a6c41
-            } else if (index < LONG_MIN) {
9a6c41
+            } else if (index < 0) {
9a6c41
                 continue;
9a6c41
             }
9a6c41
             if(NULL == (token = strtok_r(dataptr, " ", &saveptr1)))
9a6c41
@@ -426,14 +426,21 @@ linux_read_icmp6_parse(struct icmp6_mib *icmp6stat,
9a6c41
 
9a6c41
         vals = name;
9a6c41
         if (NULL != icmp6msgstat) {
9a6c41
+            int type;
9a6c41
             if (0 == strncmp(name, "Icmp6OutType", 12)) {
9a6c41
                 strsep(&vals, "e");
9a6c41
-                icmp6msgstat->vals[atoi(vals)].OutType = stats;
9a6c41
+                type = atoi(vals);
9a6c41
+                if ( type < 0 || type > 255 )
9a6c41
+                    continue;
9a6c41
+                icmp6msgstat->vals[type].OutType = stats;
9a6c41
                 *support = 1;
9a6c41
                 continue;
9a6c41
             } else if (0 == strncmp(name, "Icmp6InType", 11)) {
9a6c41
                 strsep(&vals, "e");
9a6c41
-                icmp6msgstat->vals[atoi(vals)].InType = stats;
9a6c41
+                type = atoi(vals);
9a6c41
+                if ( type < 0 || type > 255 )
9a6c41
+                    continue;
9a6c41
+                icmp6msgstat->vals[type].InType = stats;
9a6c41
                 *support = 1;
9a6c41
                 continue;
9a6c41
             }
9a6c41
diff --git a/agent/mibgroup/mibII/kernel_linux.h b/agent/mibgroup/mibII/kernel_linux.h
9a6c41
index 6bf5d47..c6dfca9 100644
9a6c41
--- a/agent/mibgroup/mibII/kernel_linux.h
9a6c41
+++ b/agent/mibgroup/mibII/kernel_linux.h
9a6c41
@@ -121,11 +121,11 @@ struct icmp_msg_mib {
9a6c41
 
9a6c41
 /* Lets use wrapper structures for future expansion */
9a6c41
 struct icmp4_msg_mib {
9a6c41
-    struct icmp_msg_mib vals[255];
9a6c41
+    struct icmp_msg_mib vals[256];
9a6c41
 };
9a6c41
 
9a6c41
 struct icmp6_msg_mib {
9a6c41
-    struct icmp_msg_mib vals[255];
9a6c41
+    struct icmp_msg_mib vals[256];
9a6c41
 };
9a6c41
 
9a6c41
 struct udp_mib {