git: 1725a5fc022b - releng/15.1 - bsnmp: let an SNMPv3 discovery message elicit only a Report

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Tue, 17 Nov 2026 17:08:30 UTC
The branch releng/15.1 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=1725a5fc022bda7afcfb4525d37643cfa61948bd

commit 1725a5fc022bda7afcfb4525d37643cfa61948bd
Author:     Maxim Konovalov <maxim@FreeBSD.org>
AuthorDate: 2026-11-12 00:43:06 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-11-16 21:25:06 +0000

    bsnmp: let an SNMPv3 discovery message elicit only a Report
    
    An SNMPv3 message with no variable bindings is treated as RFC 3414
    engineID (or time-window) discovery: snmp_input_start() appends a
    single usmStats counter to the request, and snmp_pdu_auth_access()
    skips the VACM check because the AUTODISCOVER flag is set.  The
    request's verb was then still dispatched by type.  A genuine discovery
    is a GET and simply reads that counter back -- the intended Report --
    but a zero-binding GETNEXT or GETBULK instead walks forward from the
    appended OID, and with VACM skipped it returns the next registered
    object(s): an unauthenticated read of the agent's USM and VACM
    configuration (objects at or after 1.3.6.1.6.3.15).
    
    Force the verb of a discovery message to GET, so the appended counter
    is read as-is and no walk (or SET) can run under the skipped-VACM
    state.  Genuine discovery, which already uses GET, is unaffected.
    
    This complements the earlier change that rejects an AUTODISCOVER
    message carrying its own bindings; that guard is never reached on this
    path, because the offending binding is appended by the agent after the
    zero-binding test.
    
    Approved by:    so
    Security:       FreeBSD-SA-26:89.bsnmp
    Reviewed by:    harti
    Fixes:          135f7de5ddb6
---
 contrib/bsnmp/snmpd/main.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/contrib/bsnmp/snmpd/main.c b/contrib/bsnmp/snmpd/main.c
index add9ec680eb1..526fbb38b8f8 100644
--- a/contrib/bsnmp/snmpd/main.c
+++ b/contrib/bsnmp/snmpd/main.c
@@ -644,6 +644,15 @@ decoded:
 			pdu->engine.engine_boots = snmpd_engine.engine_boots;
 			pdu->engine.engine_time = snmpd_engine.engine_time;
 		}
+		/*
+		 * A discovery message may only elicit a Report.  Force GET
+		 * so the appended usmStats counter is read back as-is: a
+		 * GETNEXT or GETBULK would otherwise walk forward from it,
+		 * and a SET act on it, all with VACM skipped for the
+		 * AUTODISCOVER flag.
+		 */
+		if ((pdu->flags & SNMP_MSG_AUTODISCOVER) != 0)
+			pdu->type = SNMP_PDU_GET;
 	} else if (pdu->user.auth_proto != SNMP_AUTH_NOAUTH &&
 	     (pdu->engine.engine_boots == 0 || pdu->engine.engine_time == 0)) {
 		snmpd_usmstats.not_in_time_windows++;