Package: net-snmp Version: 5.7.3+dfsg-5 Severity: normal Tags: patch User: [email protected] Usertags: origin-ubuntu eoan ubuntu-patch
Dear Maintainer, Autofs direct map triggers are visible in /etc/mtab. On boot, when snmpd starts, it iterates over the entries in /etc/mtab and performs statfs() on them. This trigger automount to mount autofs mounts even if the user does not explicitly access them. To reproduce this behaviour the autofs has to be started before snmpd service. When there a few autofs mount points the impact is insignificant. However when there are thousands of them, this causes unnecessary overhead on operations such as df. For more information please refer to : https://launchpad.net/bugs/1835818 In Ubuntu, the attached patch was applied to achieve the following: The patch essentially adds support for autofs mounts in order to detect them and treat them separately when calling stafs; autofs entries are skipped to prevent them from being mounting every time snmpd is restarted. * Skip autofs entries when calling statfs to prevent autofs being mounted on snmpd startup (LP: #1835818): - d/p/autofs-skip-autofs-entries.patch - d/p/autofs-fix-a-recently-introduced-bug.patch Thanks for considering the patch. -- System Information: Debian Release: buster/sid APT prefers eoan APT policy: (500, 'eoan') Architecture: amd64 (x86_64) Foreign Architectures: i386 Kernel: Linux 5.0.0-16-generic (SMP w/2 CPU cores) Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8), LANGUAGE=en_GB:en (charmap=UTF-8) Shell: /bin/sh linked to /usr/bin/dash Init: systemd (via /run/systemd/system) LSM: AppArmor: enabled
diff -Nru net-snmp-5.7.3+dfsg/debian/control net-snmp-5.7.3+dfsg/debian/control --- net-snmp-5.7.3+dfsg/debian/control 2019-02-05 18:00:35.000000000 +0000 +++ net-snmp-5.7.3+dfsg/debian/control 2019-08-21 12:22:37.000000000 +0100 @@ -1,8 +1,7 @@ Source: net-snmp Section: net Priority: optional -Maintainer: Ubuntu Developers <[email protected]> -XSBC-Original-Maintainer: Net-SNMP Packaging Team <[email protected]> +Maintainer: Net-SNMP Packaging Team <[email protected]> Uploaders: Craig Small <[email protected]>, Thomas Anders <[email protected]>, Noah Meyerhans <[email protected]> diff -Nru net-snmp-5.7.3+dfsg/debian/patches/autofs-fix-a-recently-introduced-bug.patch net-snmp-5.7.3+dfsg/debian/patches/autofs-fix-a-recently-introduced-bug.patch --- net-snmp-5.7.3+dfsg/debian/patches/autofs-fix-a-recently-introduced-bug.patch 1970-01-01 01:00:00.000000000 +0100 +++ net-snmp-5.7.3+dfsg/debian/patches/autofs-fix-a-recently-introduced-bug.patch 2019-08-21 12:14:51.000000000 +0100 @@ -0,0 +1,27 @@ +From: Bart Van Assche <[email protected]> +Origin: Upstream, https://sourceforge.net/p/net-snmp/code/ci/a0df31c18c513a0d79f4d526b1af7fad48748e57/ +Bug: https://sourceforge.net/p/net-snmp/bugs/2968/ +Bug-Ubuntu: https://bugs.launchpad.net/bugs/1835818 +Date: Fri, 26 Jul 2019 21:40:12 -0700 +Subject: [PATCH] HOST-MIB: Fix a recently introduced bug + +Fixes: cf41e6e91015 ("HOST-MIB: Skip autofs entries") + +Note: this bug was not introduced by Josef but by me. +--- + agent/mibgroup/host/hrh_storage.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +Index: net-snmp-5.7.3+dfsg/agent/mibgroup/host/hrh_storage.c +=================================================================== +--- net-snmp-5.7.3+dfsg.orig/agent/mibgroup/host/hrh_storage.c ++++ net-snmp-5.7.3+dfsg/agent/mibgroup/host/hrh_storage.c +@@ -372,7 +372,7 @@ really_try_next: + NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES) && + Check_HR_FileSys_NFS()) + return NULL; +- if (Check_HR_FileSys_AutoFs()) ++ if (HRFS_entry && Check_HR_FileSys_AutoFs()) + return NULL; + if (store_idx <= NETSNMP_MEM_TYPE_MAX ) { + mem = (netsnmp_memory_info*)ptr; diff -Nru net-snmp-5.7.3+dfsg/debian/patches/autofs-skip-autofs-entries.patch net-snmp-5.7.3+dfsg/debian/patches/autofs-skip-autofs-entries.patch --- net-snmp-5.7.3+dfsg/debian/patches/autofs-skip-autofs-entries.patch 1970-01-01 01:00:00.000000000 +0100 +++ net-snmp-5.7.3+dfsg/debian/patches/autofs-skip-autofs-entries.patch 2019-08-21 12:14:24.000000000 +0100 @@ -0,0 +1,232 @@ +Description: Skip autofs entries when calling statfs +Backported from upstream commit cf41e6e910158fb4c4cb546c4 : +Remove parenthesis from last hunk to apply cleanly. +From: Josef Ridky <[email protected]> +Origin: Upstream, https://sourceforge.net/p/net-snmp/patches/1350/ +Bug: https://sourceforge.net/p/net-snmp/bugs/2968/ +Bug-Ubuntu: https://bugs.launchpad.net/bugs/1835818 +Date: Wed, 24 Jul 2019 07:23:47 -0700 +Subject: [PATCH] HOST-MIB: Skip autofs entries + +Do not call statfs() for autofs entries. + +See also https://sourceforge.net/p/net-snmp/patches/1350/. +See also https://sourceforge.net/p/net-snmp/bugs/2968/. + +[ bvanassche: Made several small edits ] +--- + agent/mibgroup/hardware/fsys/fsys_mntctl.c | 8 ++++++-- + agent/mibgroup/hardware/fsys/fsys_mntent.c | 11 +++++++++++ + agent/mibgroup/hardware/fsys/mnttypes.h | 3 +++ + agent/mibgroup/host/hr_filesys.c | 21 +++++++++++++++++++++ + agent/mibgroup/host/hr_filesys.h | 1 + + agent/mibgroup/host/hr_storage.c | 5 ++++- + agent/mibgroup/host/hrh_filesys.c | 6 ++++++ + agent/mibgroup/host/hrh_filesys.h | 1 + + agent/mibgroup/host/hrh_storage.c | 5 ++++- + include/net-snmp/agent/hardware/fsys.h | 1 + + 10 files changed, 58 insertions(+), 4 deletions(-) + +Index: net-snmp-5.7.3+dfsg/agent/mibgroup/hardware/fsys/fsys_mntctl.c +=================================================================== +--- net-snmp-5.7.3+dfsg.orig/agent/mibgroup/hardware/fsys/fsys_mntctl.c ++++ net-snmp-5.7.3+dfsg/agent/mibgroup/hardware/fsys/fsys_mntctl.c +@@ -43,8 +43,9 @@ _fsys_type( int type) + + case MNT_NFS: + case MNT_NFS3: +- case MNT_AUTOFS: + return NETSNMP_FS_TYPE_NFS; ++ case MNT_AUTOFS: ++ return NETSNMP_FS_TYPE_AUTOFS; + + /* + * The following code covers selected filesystems +@@ -155,12 +156,15 @@ netsnmp_fsys_arch_load( void ) + */ + + /* +- * Optionally skip retrieving statistics for remote mounts ++ * Skip retrieving statistics for AUTOFS and optionally for remote ++ * mounts. + */ + if ( (entry->flags & NETSNMP_FS_FLAG_REMOTE) && + netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, + NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES)) + continue; ++ if (entry->type == NETSNMP_FS_TYPE_AUTOFS) ++ continue; + + if ( statfs( entry->path, &stat_buf ) < 0 ) { + snprintf( tmpbuf, sizeof(tmpbuf), "Cannot statfs %s", entry->path ); +Index: net-snmp-5.7.3+dfsg/agent/mibgroup/hardware/fsys/fsys_mntent.c +=================================================================== +--- net-snmp-5.7.3+dfsg.orig/agent/mibgroup/hardware/fsys/fsys_mntent.c ++++ net-snmp-5.7.3+dfsg/agent/mibgroup/hardware/fsys/fsys_mntent.c +@@ -146,6 +146,13 @@ _fsys_type( char *typename ) + !strcmp(typename, MNTTYPE_LOFS)) + return NETSNMP_FS_TYPE_OTHER; + ++ /* Detection of AUTOFS. ++ * This file system will be ignored by default ++ */ ++ else if (!strcmp(typename, MNTTYPE_AUTOFS)) ++ return NETSNMP_FS_TYPE_AUTOFS; ++ ++ + /* + * All other types are silently skipped + */ +@@ -232,6 +239,10 @@ netsnmp_fsys_arch_load( void ) + NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES)) + continue; + ++ /* Skip AUTOFS entries */ ++ if (entry->type == NETSNMP_FS_TYPE_AUTOFS) ++ continue; ++ + #ifdef irix6 + if ( NSFS_STATFS( entry->path, &stat_buf, sizeof(struct statfs), 0) < 0 ) + #else +Index: net-snmp-5.7.3+dfsg/agent/mibgroup/hardware/fsys/mnttypes.h +=================================================================== +--- net-snmp-5.7.3+dfsg.orig/agent/mibgroup/hardware/fsys/mnttypes.h ++++ net-snmp-5.7.3+dfsg/agent/mibgroup/hardware/fsys/mnttypes.h +@@ -162,6 +162,9 @@ + #ifndef MNTTYPE_APP + #define MNTTYPE_APP "app" + #endif ++#ifndef MNTTYPE_AUTOFS ++#define MNTTYPE_AUTOFS "autofs" ++#endif + #ifndef MNTTYPE_DEVPTS + #define MNTTYPE_DEVPTS "devpts" + #endif +Index: net-snmp-5.7.3+dfsg/agent/mibgroup/host/hr_filesys.c +=================================================================== +--- net-snmp-5.7.3+dfsg.orig/agent/mibgroup/host/hr_filesys.c ++++ net-snmp-5.7.3+dfsg/agent/mibgroup/host/hr_filesys.c +@@ -839,6 +839,27 @@ Check_HR_FileSys_NFS (void) + return 0; /* no NFS file system */ + } + ++/* This function checks whether current file system is an AutoFs ++ * HRFS_entry must be valid prior to calling this function ++ * return 1 if AutoFs, 0 otherwise ++ */ ++int ++Check_HR_FileSys_AutoFs(void) ++{ ++#if HAVE_GETFSSTAT ++ if (HRFS_entry->HRFS_type != NULL && ++#if defined(MNTTYPE_AUTOFS) ++ !strcmp(HRFS_entry->HRFS_type, MNTTYPE_AUTOFS) ++#else ++ !strcmp(HRFS_entry->HRFS_type, "autofs") ++#endif ++ ) ++#endif /* HAVE_GETFSSTAT */ ++ return 1; /* AUTOFS */ ++ ++ return 0; /* no AUTOFS */ ++} ++ + void + End_HR_FileSys(void) + { +Index: net-snmp-5.7.3+dfsg/agent/mibgroup/host/hr_filesys.h +=================================================================== +--- net-snmp-5.7.3+dfsg.orig/agent/mibgroup/host/hr_filesys.h ++++ net-snmp-5.7.3+dfsg/agent/mibgroup/host/hr_filesys.h +@@ -10,6 +10,7 @@ extern void Init_HR_FileSys(void); + extern FindVarMethod var_hrfilesys; + extern int Get_Next_HR_FileSys(void); + extern int Check_HR_FileSys_NFS(void); ++extern int Check_HR_FileSys_AutoFs(void); + + extern int Get_FSIndex(char *); + extern long Get_FSSize(char *); /* Temporary */ +Index: net-snmp-5.7.3+dfsg/agent/mibgroup/host/hr_storage.c +=================================================================== +--- net-snmp-5.7.3+dfsg.orig/agent/mibgroup/host/hr_storage.c ++++ net-snmp-5.7.3+dfsg/agent/mibgroup/host/hr_storage.c +@@ -549,6 +549,8 @@ really_try_next: + NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES) && + Check_HR_FileSys_NFS()) + return NULL; /* or goto try_next; */ ++ if (Check_HR_FileSys_AutoFs()) ++ return NULL; + if (HRFS_statfs(HRFS_entry->HRFS_mount, &stat_buf) < 0) { + snmp_log_perror(HRFS_entry->HRFS_mount); + goto try_next; +@@ -688,7 +690,8 @@ Get_Next_HR_Store(void) + if (HRS_index >= 0) { + if (!(netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, + NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES) && +- Check_HR_FileSys_NFS())) { ++ Check_HR_FileSys_NFS()) && ++ !Check_HR_FileSys_AutoFs()) { + return HRS_index + NETSNMP_MEM_TYPE_MAX; + } + } else { +Index: net-snmp-5.7.3+dfsg/agent/mibgroup/host/hrh_filesys.c +=================================================================== +--- net-snmp-5.7.3+dfsg.orig/agent/mibgroup/host/hrh_filesys.c ++++ net-snmp-5.7.3+dfsg/agent/mibgroup/host/hrh_filesys.c +@@ -427,3 +427,9 @@ Check_HR_FileSys_NFS (void) + { + return (HRFS_entry->flags & NETSNMP_FS_FLAG_REMOTE) ? 1 : 0; + } ++ ++int ++Check_HR_FileSys_AutoFs (void) ++{ ++ return HRFS_entry->type == NETSNMP_FS_TYPE_AUTOFS; ++} +Index: net-snmp-5.7.3+dfsg/agent/mibgroup/host/hrh_filesys.h +=================================================================== +--- net-snmp-5.7.3+dfsg.orig/agent/mibgroup/host/hrh_filesys.h ++++ net-snmp-5.7.3+dfsg/agent/mibgroup/host/hrh_filesys.h +@@ -10,6 +10,7 @@ extern void Init_HR_FileSys(void); + extern FindVarMethod var_hrhfilesys; + extern int Get_Next_HR_FileSys(void); + extern int Check_HR_FileSys_NFS(void); ++extern int Check_HR_FileSys_AutoFs(void); + + extern int Get_FSIndex(char *); + extern long Get_FSSize(char *); /* Temporary */ +Index: net-snmp-5.7.3+dfsg/agent/mibgroup/host/hrh_storage.c +=================================================================== +--- net-snmp-5.7.3+dfsg.orig/agent/mibgroup/host/hrh_storage.c ++++ net-snmp-5.7.3+dfsg/agent/mibgroup/host/hrh_storage.c +@@ -372,6 +372,8 @@ really_try_next: + NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES) && + Check_HR_FileSys_NFS()) + return NULL; ++ if (Check_HR_FileSys_AutoFs()) ++ return NULL; + if (store_idx <= NETSNMP_MEM_TYPE_MAX ) { + mem = (netsnmp_memory_info*)ptr; + } +@@ -509,7 +511,8 @@ Get_Next_HR_Store(void) + if (HRS_index >= 0) { + if (!(netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, + NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES) && +- Check_HR_FileSys_NFS())) { ++ Check_HR_FileSys_NFS()) && ++ !Check_HR_FileSys_AutoFs()) { + return HRS_index + NETSNMP_MEM_TYPE_MAX; + } + } else { +Index: net-snmp-5.7.3+dfsg/include/net-snmp/agent/hardware/fsys.h +=================================================================== +--- net-snmp-5.7.3+dfsg.orig/include/net-snmp/agent/hardware/fsys.h ++++ net-snmp-5.7.3+dfsg/include/net-snmp/agent/hardware/fsys.h +@@ -41,6 +41,7 @@ typedef struct netsnmp_fsys_info_s netsn + #define NETSNMP_FS_TYPE_SYSFS 4 | _NETSNMP_FS_TYPE_LOCAL | _NETSNMP_FS_TYPE_SKIP_BIT + #define NETSNMP_FS_TYPE_TMPFS 5 | _NETSNMP_FS_TYPE_LOCAL + #define NETSNMP_FS_TYPE_USBFS 6 | _NETSNMP_FS_TYPE_LOCAL ++#define NETSNMP_FS_TYPE_AUTOFS 7 | _NETSNMP_FS_TYPE_LOCAL | _NETSNMP_FS_TYPE_SKIP_BIT + + #define NETSNMP_FS_FLAG_ACTIVE 0x01 + #define NETSNMP_FS_FLAG_REMOTE 0x02 diff -Nru net-snmp-5.7.3+dfsg/debian/patches/series net-snmp-5.7.3+dfsg/debian/patches/series --- net-snmp-5.7.3+dfsg/debian/patches/series 2019-02-05 18:00:35.000000000 +0000 +++ net-snmp-5.7.3+dfsg/debian/patches/series 2019-08-21 12:14:33.000000000 +0100 @@ -44,3 +44,5 @@ mysql8-headers.patch mysql-init.patch mysql-options.patch +autofs-skip-autofs-entries.patch +autofs-fix-a-recently-introduced-bug.patch

