From nobody Tue Nov 17 17:01:57 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jTWH92t7Nz71QTN for ; Tue, 17 Nov 2026 17:01:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jTWH90gkQz3Py6 for ; Tue, 17 Nov 2026 17:01:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794934917; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jSLxnVDfAUJ1075+rhnMOvT8gmFLSWReDaqQfK4S48c=; b=uRD8i7e8FHGXmZWvMIONzJjLA92GL4yCVVqmAq/rb8si+fWiva6QFh8iMQyJKFMfwVbY/j QGig8GmEJEygiWmy3+F7Hx4hsBaADFyD89EoCZQhU229u8MkO2Xh002esW0yC4P/iqdJ9G wnNUEnZH8guvfHzZv7dEpxbA0cgI6EuwW7dTUSUZMbjT+ya3YDnTk8/VsAyjU8DUrfBZbo hBbueHCYAyEigsBzFGbs7aHN8tVfbkNF/dlrIATO9m1HBjJuRoonwN6k7E1/Ec5JEeVT2y 1wsnlvfQydfeC0smrSllLeH3nBCZom9vQQdErl61ayJY01XbOdY8xBAPK7sPuA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794934917; b=XelXEcWyFxqGsVJ1NNdcMQGwUTYGXXIYpqcKejcfyblwGydmwKFXl4wjDwUJFaVb69BBMH WsuoxjW2TabZ+MEhB8+SUHUlFZPNK0jh5cUuxCVDWb0tN2N9kw8baJlwm7L46C99Tz/raM U/3eB8khL8X5N8yzTkDxKbUzhIj0r/daJur/wc6ysW1GBZ/8QT54YXpk5bTb26vsfSxSqz sdW3vqjd5StGa+951H35vVjzAPJXIiN5DKj9jpmEjJEnGOCMar/+STvoEL5cwnk4//xo8O b1XCbo53o9N412K1n+ATW3BrBXRaX5oj0scIfISuQy4Bz0rDlUUmj8HEw27c0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794934917; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=jSLxnVDfAUJ1075+rhnMOvT8gmFLSWReDaqQfK4S48c=; b=H5ZoqSEWreFoE97couwt/bzDQCv8mir3NVyDVZ+N9WhgPOTiXoBu3ue8JQY6QGVtvPL42p nZGz6AdLora8Al3IjvnfmiytdBrlmQNaLvPJGDALWXQ0xRWtjkLHgI/cYbs2uZJxcEte0R p8GTel1RNtmueQZx7tMXeqv4jKDgVVvR2eKNMBgWtrQCFlS2/qyJ9U7NKF+btrWU8YlWtu oFQq8X8NtGWW7+x0pdyp6hcUUuU+UHG4aWgBNGQWhyVJOCKGLK26UOLW8PYvKucJ/6TkXO Qd9U88+RHeVwoscBZFcXac7Iu3vs/n6EcgoGqwRmNnThPkJjym9n/OTo4VHtQw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jTWH90LLdzr62 for ; Tue, 17 Nov 2026 17:01:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1e7dd by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 17 Nov 2026 17:01:57 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: Maxim Konovalov From: Mark Johnston Subject: git: 1f7a2497c2d6 - main - bsnmp: do not act on an SNMPv3 discovery message that carries bindings List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1f7a2497c2d6af2c61f69c6af4c19f03378d197d Auto-Submitted: auto-generated Date: Tue, 17 Nov 2026 17:01:57 +0000 Message-Id: <6afc8885.1e7dd.608b9fb@gitrepo.freebsd.org> The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=1f7a2497c2d6af2c61f69c6af4c19f03378d197d commit 1f7a2497c2d6af2c61f69c6af4c19f03378d197d Author: Maxim Konovalov AuthorDate: 2026-11-13 03:00:02 +0000 Commit: Mark Johnston CommitDate: 2026-11-17 16:57:01 +0000 bsnmp: do not act on an SNMPv3 discovery message that carries bindings An SNMPv3 message with an empty engine id and empty user name is handled as snmpEngineID discovery: snmp_pdu_auth_user() sets SNMP_MSG_AUTODISCOVER and returns without a USM user, and snmp_pdu_auth_access() then grants the message access. A genuine discovery request carries no variable bindings and only elicits a Report, but a discovery PDU that did carry bindings was executed anyway -- so a GET or SET ran with no authentication and without the VACM access check. This affects two cases. With an empty user name the message is wholly unauthenticated, so anyone able to reach the agent could issue a SET. It also affects a configured noAuthNoPriv user: such a user has no digest to verify, so it too can set the AUTODISCOVER flag (an authenticated request before time synchronisation) and have a bindings-carrying PDU bypass VACM and operate outside its views. Refuse any AUTODISCOVER message that arrives with variable bindings instead of acting on it. Empty-binding discovery, the authenticated time-window exchange, and ordinary authenticated SNMPv3 are unaffected. While here, free the PDU on the SNMPD_INPUT_FAILED path of snmpd_input(). Every other path releases it, but the failed path consumed the datagram and returned without freeing the decoded bindings -- so a rejected PDU leaked any heap they held, such as the buffer for an OCTET STRING in a SET. Rejecting a bindings-carrying discovery message now reaches that path, so an unauthenticated client could otherwise grow the agent's memory without bound. For that free to be safe, snmp_input_start() must leave the PDU in a defined state on every return. It zeroed the PDU only after the initial snmp_pdu_snoop() check, so a malformed datagram that failed the snoop returned SNMPD_INPUT_FAILED with the caller's PDU uninitialised; freeing it would then walk a garbage binding count. Zero the PDU up front, before the snoop, so all of these paths leave an empty PDU that frees cleanly. Approved by: so Security: FreeBSD-SA-26:89.bsnmp Security: CVE-2026-127742 Reviewed by: harti Fixes: 135f7de5ddb6 --- contrib/bsnmp/snmpd/main.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/contrib/bsnmp/snmpd/main.c b/contrib/bsnmp/snmpd/main.c index 933ab7aa655a..add9ec680eb1 100644 --- a/contrib/bsnmp/snmpd/main.c +++ b/contrib/bsnmp/snmpd/main.c @@ -496,6 +496,10 @@ snmp_input_start(const u_char *buf, size_t len, const char *source, ret = SNMPD_INPUT_OK; + /* Zero the PDU before anything can return, so a failure path that + * runs before the header is decoded still leaves it safe to free. */ + memset(pdu, 0, sizeof(*pdu)); + /* look whether we have enough bytes for the entire PDU. */ switch (sret = snmp_pdu_snoop(&b)) { @@ -508,7 +512,6 @@ snmp_input_start(const u_char *buf, size_t len, const char *source, } b.asn_len = *pdulen = (size_t)sret; - memset(pdu, 0, sizeof(*pdu)); if ((code = snmp_pdu_decode_header(&b, pdu)) != SNMP_CODE_OK) goto decoded; @@ -645,6 +648,17 @@ decoded: (pdu->engine.engine_boots == 0 || pdu->engine.engine_time == 0)) { snmpd_usmstats.not_in_time_windows++; ret = SNMPD_INPUT_FAILED; + } else if ((pdu->flags & SNMP_MSG_AUTODISCOVER) != 0) { + /* + * A discovery message (RFC 3414) may only elicit a Report and + * carries no variable bindings of its own. Reaching here with + * bindings means the message was not authenticated as a user + * (empty security name, or a noAuthNoPriv user): acting on it + * would run a GET or SET that bypasses USM authentication and + * the VACM access check. Refuse it. + */ + snmpd_usmstats.unknown_users++; + ret = SNMPD_INPUT_FAILED; } if ((code = snmp_pdu_auth_access(pdu, ip)) != SNMP_CODE_OK) @@ -1088,6 +1102,7 @@ snmpd_input(struct port_input *pi, struct tport *tport) * check the access first. We don't want to return an error response * to a proxy PDU with a wrong community */ if (ierr == SNMPD_INPUT_FAILED) { + snmp_pdu_free(&pdu); /* for streaming transports this is fatal */ if (pi->stream) return (-1);