Skip to contentSkip to conversation

net-snmp: Fix CVE-2020-15861 and CVE-2020-15862

PATCH New Ovidiu Panait 1 participant 1 message Sep 1, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net-snmp: Fix CVE-2020-15861 and CVE-2020-15862

Net-SNMP through 5.7.3 allows Escalation of Privileges because of UNIX symbolic link (symlink) following.

Net-SNMP through 5.7.3 has Improper Privilege Management because SNMP WRITE access to the EXTEND MIB provides the ability to run arbitrary commands as root.

References:
https://nvd.nist.gov/vuln/detail/CVE-2020-15861
https://nvd.nist.gov/vuln/detail/CVE-2020-15862

Upstream patches:
https://github.com/net-snmp/net-snmp/commit/2b3e300ade4add03b889e61d610b0db77d300fc3
https://github.com/net-snmp/net-snmp/commit/9cfb38b0aa95363da1466ca81dd929989ba27c1f
https://github.com/net-snmp/net-snmp/commit/114e4c2cec2601ca56e8afb1f441520f75a9a312
https://github.com/net-snmp/net-snmp/commit/2968b455e6f182f329746e2bca1043f368618c73
https://github.com/net-snmp/net-snmp/commit/4fd9a450444a434a993bc72f7c3486ccce41f602
https://github.com/net-snmp/net-snmp/commit/77f6c60f57dba0aaea5d8ef1dd94bcd0c8e6d205

CVE-2020-15861-0005.patch is the actual fix for CVE-2020-15861 and CVE-2020-15861-0001.patch through CVE-2020-15861-0004.patch are context patches needed by the fix to apply cleanly.

---
 .../net-snmp/CVE-2020-15861-0001.patch        | 164 ++++++++
 .../net-snmp/CVE-2020-15861-0002.patch        |  44 +++
 .../net-snmp/CVE-2020-15861-0003.patch        |  40 ++
 .../net-snmp/CVE-2020-15861-0004.patch        |  33 ++
 .../net-snmp/CVE-2020-15861-0005.patch        | 349 ++++++++++++++++++
 .../net-snmp/net-snmp/CVE-2020-15862.patch    |  87 +++++
 .../net-snmp/net-snmp_5.8.bb                  |   6 +
 7 files changed, 723 insertions(+)
 create mode 100644 meta-networking/recipes-protocols/net-snmp/net-snmp/CVE-2020-15861-0001.patch
 create mode 100644 meta-networking/recipes-protocols/net-snmp/net-snmp/CVE-2020-15861-0002.patch
 create mode 100644 meta-networking/recipes-protocols/net-snmp/net-snmp/CVE-2020-15861-0003.patch
 create mode 100644 meta-networking/recipes-protocols/net-snmp/net-snmp/CVE-2020-15861-0004.patch
 create mode 100644 meta-networking/recipes-protocols/net-snmp/net-snmp/CVE-2020-15861-0005.patch
 create mode 100644 meta-networking/recipes-protocols/net-snmp/net-snmp/CVE-2020-15862.patch
meta-networking/recipes-protocols/net-snmp/net-snmp/CVE-2020-15861-0001.patch new file +164 -0
new file mode 100644
index 000000000..f43803a66
@@ -0,0 +1,164 @@
+From c449946b9d06571b447fce3fc0dcad89e8df05b5 Mon Sep 17 00:00:00 2001
+From: Bart Van Assche <[email protected]>
+Date: Wed, 15 May 2019 14:09:25 +0200
+Subject: [PATCH 1/5] CHANGES: libsnmp: Scan MIB directories in alphabetical
+ order
+
+This guarantees that e.g. mibs/RFC1213-MIB.txt is read before mibs/SNMPv2-MIB.txt.
+The order in which these MIBs is read matters because both define sysLocation but
+with different attributes.
+
+CVE: CVE-2020-15861
+Upstream-Status: Backport [https://github.com/net-snmp/net-snmp/commit/2b3e300ade4add03b889e61d610b0db77d300fc3]
+
+Signed-off-by: Ovidiu Panait <[email protected]>
+---
+ snmplib/parse.c | 113 +++++++++++++++++++++++++++++++++++-------------
+ 1 file changed, 82 insertions(+), 31 deletions(-)
+
+diff --git a/snmplib/parse.c b/snmplib/parse.c
+index 7678b35..51d119b 100644
+--- a/snmplib/parse.c
++++ b/snmplib/parse.c
+@@ -4894,6 +4894,79 @@ add_mibfile(const char* tmpstr, const char* d_name, FILE *ip )
+     }
+ }
+ 
++static int elemcmp(const void *a, const void *b)
++{
++    const char *const *s1 = a, *const *s2 = b;
++
++    return strcmp(*s1, *s2);
++}
++
++/*
++ * Scan a directory and return all filenames found as an array of pointers to
++ * directory entries (@result).
++ */
++static int scan_directory(char ***result, const char *dirname)
++{
++    DIR            *dir, *dir2;
++    struct dirent  *file;
++    char          **filenames = NULL;
++    int             fname_len, i, filename_count = 0, array_size = 0;
++    char           *tmpstr;
++
++    *result = NULL;
++
++    dir = opendir(dirname);
++    if (!dir)
++        return -1;
++
++    while ((file = readdir(dir))) {
++        /*
++         * Only parse file names that don't begin with a '.'
++         * Also skip files ending in '~', or starting/ending
++         * with '#' which are typically editor backup files.
++         */
++        fname_len = strlen(file->d_name);
++        if (fname_len > 0 && file->d_name[0] != '.'
++            && file->d_name[0] != '#'
++            && file->d_name[fname_len-1] != '#'
++            && file->d_name[fname_len-1] != '~') {
++            if (asprintf(&tmpstr, "%s/%s", dirname, file->d_name) < 0)
++                continue;
++            dir2 = opendir(tmpstr);
++            if (dir2) {
++                /* file is a directory, don't read it */
++                closedir(dir2);
++            } else {
++                if (filename_count >= array_size) {
++                    char **new_filenames;
++
++                    array_size = (array_size + 16) * 2;
++                    new_filenames = realloc(filenames,
++                                        array_size * sizeof(filenames[0]));
++                    if (!new_filenames) {
++                        free(tmpstr);
++                        for (i = 0; i < filename_count; i++)
++                            free(filenames[i]);
++                        free(filenames);
++                        closedir(dir);
++                        return -1;
++                    }
++                    filenames = new_filenames;
++                }
++                filenames[filename_count++] = tmpstr;
++                tmpstr = NULL;
++            }
++            free(tmpstr);
++        }
++    }
++    closedir(dir);
++
++    qsort(filenames, filename_count, sizeof(filenames[0]), elemcmp);
++    *result = filenames;
++
++    return filename_count;
++}
++
+ /* For Win32 platforms, the directory does not maintain a last modification
+  * date that we can compare with the modification date of the .index file.
+  * Therefore there is no way to know whether any .index file is valid.
+@@ -4904,12 +4977,11 @@ int
+ add_mibdir(const char *dirname)
+ {
+     FILE           *ip;
+-    DIR            *dir, *dir2;
+     const char     *oldFile = File;
+-    struct dirent  *file;
++    char          **filenames;
+     char            tmpstr[300];
+     int             count = 0;
+-    int             fname_len = 0;
++    int             filename_count, i;
+ #if !(defined(WIN32) || defined(cygwin))
+     char           *token;
+     char space;
+@@ -4957,36 +5029,15 @@ add_mibdir(const char *dirname)
+         DEBUGMSGTL(("parse-mibs", "No index\n"));
+ #endif
+ 
+-    if ((dir = opendir(dirname))) {
+-        ip = netsnmp_mibindex_new( dirname );
+-        while ((file = readdir(dir))) {
+-            /*
+-             * Only parse file names that don't begin with a '.' 
+-             * Also skip files ending in '~', or starting/ending
+-             * with '#' which are typically editor backup files.
+-             */
+-            if (file->d_name != NULL) {
+-              fname_len = strlen( file->d_name );
+-              if (fname_len > 0 && file->d_name[0] != '.' 
+-                                && file->d_name[0] != '#'
+-                                && file->d_name[fname_len-1] != '#'
+-                                && file->d_name[fname_len-1] != '~') {
+-                snprintf(tmpstr, sizeof(tmpstr), "%s/%s", dirname, file->d_name);
+-                tmpstr[ sizeof(tmpstr)-1 ] = 0;
+-                if ((dir2 = opendir(tmpstr))) {
+-                    /*
+-                     * file is a directory, don't read it 
+-                     */
+-                    closedir(dir2);
+-                } else {
+-                    if ( !add_mibfile( tmpstr, file->d_name, ip ))
+-                        count++;
+-                }
+-              }
+-            }
++    filename_count = scan_directory(&filenames, dirname);
++
++    if (filename_count >= 0) {
++        ip = netsnmp_mibindex_new(dirname);
++        for (i = 0; i < filename_count; i++) {
++            if (add_mibfile(filenames[i], strrchr(filenames[i], '/'), ip) == 0)
++                count++;
+         }
+         File = oldFile;
+-        closedir(dir);
+         if (ip)
+             fclose(ip);
+         return (count);
+-- 
+2.17.1
+
meta-networking/recipes-protocols/net-snmp/net-snmp/CVE-2020-15861-0002.patch new file +44 -0

44 lines not on this page · raw message

meta-networking/recipes-protocols/net-snmp/net-snmp/CVE-2020-15861-0003.patch new file +40 -0
new file mode 100644
index 000000000..03acbbab9
@@ -0,0 +1,40 @@
+From c98808036c86a4ac4877ea13dbcef096b57e49f8 Mon Sep 17 00:00:00 2001
+From: Bart Van Assche <[email protected]>
+Date: Wed, 22 May 2019 10:08:53 +0200
+Subject: [PATCH 3/5] libsnmp: Fix a compiler warning
+
+Avoid that the compiler complains on Windows systems that tmpstr[] is not used.
+
+Fixes: 2b3e300ade4a ("CHANGES: libsnmp: Scan MIB directories in alphabetical order")
+
+CVE: CVE-2020-15861
+Upstream-Status: Backport [https://github.com/net-snmp/net-snmp/commit/114e4c2cec2601ca56e8afb1f441520f75a9a312]
+
+Signed-off-by: Ovidiu Panait <[email protected]>
+---
+ snmplib/parse.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/snmplib/parse.c b/snmplib/parse.c
+index 200ba25..0414337 100644
+--- a/snmplib/parse.c
++++ b/snmplib/parse.c
+@@ -4980,7 +4980,6 @@ add_mibdir(const char *dirname)
+     FILE           *ip;
+     const char     *oldFile = File;
+     char          **filenames;
+-    char            tmpstr[300];
+     int             count = 0;
+     int             filename_count, i;
+ #if !(defined(WIN32) || defined(cygwin))
+@@ -4988,6 +4987,7 @@ add_mibdir(const char *dirname)
+     char space;
+     char newline;
+     struct stat     dir_stat, idx_stat;
++    char            tmpstr[300];
+     char            tmpstr1[300];
+ #endif
+ 
+-- 
+2.17.1
+
meta-networking/recipes-protocols/net-snmp/net-snmp/CVE-2020-15861-0004.patch new file +33 -0
new file mode 100644
index 000000000..f0e709636
@@ -0,0 +1,33 @@
+From 545742d1867d70a645a63161ede4a391456691fc Mon Sep 17 00:00:00 2001
+From: Bill Fenner <[email protected]>
+Date: Mon, 3 Jun 2019 10:01:08 -0700
+Subject: [PATCH 4/5] libsnmp: free filenames from directory listing
+
+Free each filename as we use it, as well as freeing the
+list of filenames.
+
+Fixes: 2b3e300ade4a ("CHANGES: libsnmp: Scan MIB directories in alphabetical order")
+
+CVE: CVE-2020-15861
+Upstream-Status: Backport [https://github.com/net-snmp/net-snmp/commit/2968b455e6f182f329746e2bca1043f368618c73]
+
+Signed-off-by: Ovidiu Panait <[email protected]>
+---
+ snmplib/parse.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/snmplib/parse.c b/snmplib/parse.c
+index 0414337..7f98542 100644
+--- a/snmplib/parse.c
++++ b/snmplib/parse.c
+@@ -5037,6 +5037,7 @@ add_mibdir(const char *dirname)
+         for (i = 0; i < filename_count; i++) {
+             if (add_mibfile(filenames[i], strrchr(filenames[i], '/'), ip) == 0)
+                 count++;
++	    free(filenames[i]);
+         }
+         File = oldFile;
+         if (ip)
+-- 
+2.17.1
+
meta-networking/recipes-protocols/net-snmp/net-snmp/CVE-2020-15861-0005.patch new file +349 -0

349 lines not on this page · raw message

meta-networking/recipes-protocols/net-snmp/net-snmp/CVE-2020-15862.patch new file +87 -0

87 lines not on this page · raw message

meta-networking/recipes-protocols/net-snmp/net-snmp_5.8.bb +6 -0
index 192b6b506..2a95cd108 100644
@@ -27,6 +27,12 @@ SRC_URI = "${SOURCEFORGE_MIRROR}/net-snmp/net-snmp-${PV}.tar.gz \
            file://reproducibility-have-printcap.patch \
            file://reproducibility-accept-configure-options-from-env.patch \
            file://0001-net-snmp-fix-compile-error-disable-des.patch \
+           file://CVE-2020-15861-0001.patch \
+           file://CVE-2020-15861-0002.patch \
+           file://CVE-2020-15861-0003.patch \
+           file://CVE-2020-15861-0004.patch \
+           file://CVE-2020-15861-0005.patch \
+           file://CVE-2020-15862.patch \
            "
 SRC_URI[md5sum] = "63bfc65fbb86cdb616598df1aff6458a"
 SRC_URI[sha256sum] = "b2fc3500840ebe532734c4786b0da4ef0a5f67e51ef4c86b3345d697e4976adf"
Signature · 1 line
2.17.1