From nobody Wed May 22 14:01:47 2024 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 4VktJq3JpLz5Lmbd; Wed, 22 May 2024 14:01:47 +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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VktJq2pxPz4F0M; Wed, 22 May 2024 14:01:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716386507; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=uxTVDSdmB1fMUWmysa0nfDaizJYCyMTq66c9N2EyIfg=; b=TPy/9w7WKTPdPaxrLtHrYhaA881TwEOQU0uveojD5y9qMdYB2iC+diaNCgVWSpE+FCt3fV BBHNtL3pkk60aZB/VJ8czxqMn+RVLeAioj5vSauof0wFaAqvL9/ttmFnaFUe+3ozp4tM7R PwsRwOQ5egTBJTRhy5tfedDMOkKn+k29zR3e4GVGMsn98cfOTAGco8d0hyiebESwasJHDX yGDXEjFdXgy0jkz8uN4llIVlzsMLd7SirUwW8tT7mLiTvALPFVklVAKQ/EYRSfB4Lyn5vD awIXTg4buwqonwSDmkYun3RZJHShzE3Y4mvc+1fcULbVGZ1dvLqa0pY6AAEunw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716386507; a=rsa-sha256; cv=none; b=LdAnzqnHiVJ2pVNcKBCdpWDUOnG4I7OOcPuV9RSy6SREEMS12Q1hPj03OAGdNNIpG/gB4O hD12sry8E/Z9Vdjcd6z2UdGRtyQgOnjbhAMU3DdRJ5Azgb4BXMm+sK1XdQoI7RnG8UKvkx r67rjN0TLh3//JftAsqWn7gD1bas71vGMtAIy0QovHgnOeWhyEPVBovOk1UOnK5fmHDfMK ZhvPx3upWm+AoJ2OhH2eNU9i2zJUJOttjsUMjhMTpW6Rqi3Rul0BF+VTnqVhKwU4iSzIDD fKmk5WIJwC1RJPCMqxM2mkAHC81QPGKT3+c+zicZLIsJt5L8PXhRf00HJkw9nw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716386507; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=uxTVDSdmB1fMUWmysa0nfDaizJYCyMTq66c9N2EyIfg=; b=QpcbBJiz7tD2OrUjZFTDPsJrbZlgcA0YYB6sRgxtSeBj9sIyfMFtJdO+pAXhFZ2R/adtZh ZYw5XZbkjLADeTPGJlcjm3U/2xDJTFrnk95ZCaWRPUc0vJDMsYrwefWASSeimE0djskOQ3 dhv8bsALts/KD0ypoqHK0Xgoalxosng9FQ0SHuDBxzX83jsdOlodREjWLILosjDKf+5CF2 vCDywjdqu/BlzJw2Fy/gj+zbsL0es3yBJ5dOKQW1aaRF/OPwOBB5qkSAQZUEjaXxOBvH8A q8nwmCN+rJTwj6xgunZTg5nYt+Dm18qSh1NDpzQF2Z4Gzf4M7ACPK8QY/ds6Ag== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VktJq2470z17dB; Wed, 22 May 2024 14:01:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 44ME1lIC066879; Wed, 22 May 2024 14:01:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44ME1lhb066876; Wed, 22 May 2024 14:01:47 GMT (envelope-from git) Date: Wed, 22 May 2024 14:01:47 GMT Message-Id: <202405221401.44ME1lhb066876@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Zhenlei Huang Subject: git: 9d653a52f899 - stable/13 - if_vxlan(4): Add checking for loops and nesting of tunnels List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: zlei X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 9d653a52f899c420f00e23401c3ff44b493d4d32 Auto-Submitted: auto-generated The branch stable/13 has been updated by zlei: URL: https://cgit.FreeBSD.org/src/commit/?id=9d653a52f899c420f00e23401c3ff44b493d4d32 commit 9d653a52f899c420f00e23401c3ff44b493d4d32 Author: Zhenlei Huang AuthorDate: 2024-05-20 12:14:07 +0000 Commit: Zhenlei Huang CommitDate: 2024-05-22 14:01:00 +0000 if_vxlan(4): Add checking for loops and nesting of tunnels User misconfiguration, either tunnel loops, or a large number of different nested tunnels, can overflow the kernel stack. Prevent that by using if_tunnel_check_nesting(). PR: 278394 Diagnosed by: markj Reviewed by: kp MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D45197 (cherry picked from commit 93fbfef0b50354b7a1620822454ef29cd415cb2d) (cherry picked from commit 3ebd2b1c730834123a53b3eddcf9029fcf414782) --- sys/net/if_vxlan.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/sys/net/if_vxlan.c b/sys/net/if_vxlan.c index 9ab46a36545c..3802ebe4bfbe 100644 --- a/sys/net/if_vxlan.c +++ b/sys/net/if_vxlan.c @@ -431,6 +431,21 @@ TUNABLE_INT("net.link.vxlan.legacy_port", &vxlan_legacy_port); static int vxlan_reuse_port = 0; TUNABLE_INT("net.link.vxlan.reuse_port", &vxlan_reuse_port); +/* + * This macro controls the default upper limitation on nesting of vxlan + * tunnels. By default it is 3, as the overhead of IPv6 vxlan tunnel is 70 + * bytes, this will create at most 210 bytes overhead and the most inner + * tunnel's MTU will be 1290 which will meet IPv6 minimum MTU size 1280. + * Be careful to configure the tunnels when raising the limit. A large + * number of nested tunnels can introduce system crash. + */ +#ifndef MAX_VXLAN_NEST +#define MAX_VXLAN_NEST 3 +#endif +static int max_vxlan_nesting = MAX_VXLAN_NEST; +SYSCTL_INT(_net_link_vxlan, OID_AUTO, max_nesting, CTLFLAG_RW, + &max_vxlan_nesting, 0, "Max nested tunnels"); + /* Default maximum number of addresses in the forwarding table. */ #ifndef VXLAN_FTABLE_MAX #define VXLAN_FTABLE_MAX 2000 @@ -2718,6 +2733,7 @@ vxlan_encap6(struct vxlan_softc *sc, const union vxlan_sockaddr *fvxlsa, #endif } +#define MTAG_VXLAN_LOOP 0x7876706c /* vxlp */ static int vxlan_transmit(struct ifnet *ifp, struct mbuf *m) { @@ -2743,6 +2759,13 @@ vxlan_transmit(struct ifnet *ifp, struct mbuf *m) m_freem(m); return (ENETDOWN); } + if (__predict_false(if_tunnel_check_nesting(ifp, m, MTAG_VXLAN_LOOP, + max_vxlan_nesting) != 0)) { + VXLAN_RUNLOCK(sc, &tracker); + m_freem(m); + if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); + return (ELOOP); + } if ((m->m_flags & (M_BCAST | M_MCAST)) == 0) fe = vxlan_ftable_entry_lookup(sc, eh->ether_dhost);