From nobody Wed May 22 13:59:23 2024 X-Original-To: dev-commits-src-branches@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 4VktG40C8pz5LmDL; Wed, 22 May 2024 13:59:24 +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 4VktG36X4Tz4D5V; Wed, 22 May 2024 13:59:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716386363; 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=/nY7nopUCbJ89NoBxmM8NoqvkX49Y61vk9Ml0lrdbBY=; b=wb9rxCxOqiXEiaXTr6/A3qtbhJB6YZMwNBGkZz1IFCV4OH9MLfi3wDHcCdAWw3Hm/74/UO xbavuhOjGpOKqte2CT5p7iro/PRdbOBQrZecknWO1h5qjB/vvTai/OXrGVECBGLmHRUJu7 AkL3oSjohS/gxpoUW7CPa3hB3W2uyfuDZYWA88d29DChK34dBoFSzVqTQyPT8pCpof5tt1 IQXiUebqIibBCTY7v4lnreuaRxj+P8KzMvgi7DVNv7x97paFHqFGCt4R6AG0+Pir+lAEpA PGCVR6TnEx2mgyNzwFPxtLrG9liJDdHKEpdqFvv7z9wm2hpFTOsTlVh2hG4oQA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716386363; a=rsa-sha256; cv=none; b=gqxycC1M/XHD7+/RIxdO9VHRuwPtkWvmjmQifnpRt2Rc3vmIGkWuhx0r9mhR+/3jqOyUUU IotI2YziL/B64P2G37ZZb3q+wh4ezmHLjnr7S/AKzc+fEXWIrvupVWxgLZf0W7tJEQzFlo FLHrznXisFnxJ4sCeAB9+/oJ8IeFp8f2yN+cbvzF7JyPI/t3PRUScUiwJa8GhYbyL7sX+8 HhdhMYy3LJqycF5CA2EKbkbLsxn2zMAMyqxVnGhAiKWMCrU9qiMdfYaFf7l2CvuOCuJsIX J7IK9pVE4vz7kdsEYWwl5vQ80aTXGa7aXC5EVQT4qNQ/3h6/yXanbVrf2WuzqQ== 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=1716386363; 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=/nY7nopUCbJ89NoBxmM8NoqvkX49Y61vk9Ml0lrdbBY=; b=jdvxFn8utxZESVYlDU2Uro4L2h7YfYJWU7ROcSO9WpCnZRWYXOErY3l/iEpdzk7NN1ONxd dB1mLh0uu9nJ0pYetTo6Ym+yFwffiipwB3Zw/KAzKE5+P1WgapdMQqWWY1/9JT6R/XQOZK MLzQAfAYSQ2AXgL0GpjaqWb4BidpKGSZKr7x3RLfHgSHeDawCYnpqK33CYjiS8goTH7UUE gQDX5mCeetpMGeOAfeeIeLygm4bhNe0Vi2qaq4zGnQVGjdSBS/tgpcDYRbM83GMOrgsyks Td54pakYazr5DMarbZwBJYSAnEbRlGRuv6gQOKWdrlqsNI/aURAwYY8oV7f5mA== 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 4VktG35kt1z17Ps; Wed, 22 May 2024 13:59:23 +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 44MDxN32051520; Wed, 22 May 2024 13:59:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44MDxNAP051517; Wed, 22 May 2024 13:59:23 GMT (envelope-from git) Date: Wed, 22 May 2024 13:59:23 GMT Message-Id: <202405221359.44MDxNAP051517@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: 3ebd2b1c7308 - stable/14 - if_vxlan(4): Add checking for loops and nesting of tunnels List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/14 X-Git-Reftype: branch X-Git-Commit: 3ebd2b1c730834123a53b3eddcf9029fcf414782 Auto-Submitted: auto-generated The branch stable/14 has been updated by zlei: URL: https://cgit.FreeBSD.org/src/commit/?id=3ebd2b1c730834123a53b3eddcf9029fcf414782 commit 3ebd2b1c730834123a53b3eddcf9029fcf414782 Author: Zhenlei Huang AuthorDate: 2024-05-20 12:14:07 +0000 Commit: Zhenlei Huang CommitDate: 2024-05-22 13:58:31 +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) --- 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 e6949bb5dc9a..87648abd116b 100644 --- a/sys/net/if_vxlan.c +++ b/sys/net/if_vxlan.c @@ -433,6 +433,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 @@ -2722,6 +2737,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) { @@ -2747,6 +2763,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);