From nobody Wed May 22 23:02:03 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 4Vl6JC6fp2z5LCNt; Wed, 22 May 2024 23:02:03 +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 4Vl6JC5qMgz4XR8; Wed, 22 May 2024 23:02:03 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716418923; 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=f8lybhmjlD3UPDNHphrjKA7qeS4s8DZKJ9DDbRWknGc=; b=biuSRbVlfMGS4dVZ4d0befgdl1mcl7ocUFYpMIE8CCoIKmwBRI+slcqgt9RAQUUqRcCoR8 etmHogMKR3vu0BPXIkcamGoPZyK8C/8nsRFWDz4GznY0eER9WFxXJ3U2q6I3FAjXVyZaZ1 JCH2c8zBGS2/sUDKQKBdlvRsIhdAWwX/yWvnV9SuT7nRR6/rtOxprCsL0NiVevTQIPLP7z MDfDd+Tiobn89Y5IyB5FJY4OkVOz07fmCj84eOvEKqAH+d6oK+eRZ9KzQC42tt9mim0LKz V+oJ8KYgi+RMtRWnZN6NBw9uT6QvoHhJfRplcjk3pL5TC/Nw73rErY/32owTiw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716418923; a=rsa-sha256; cv=none; b=q2D9hVA2EOmtVMA+O0lwFdP3AIUn9yKG16Qp7OyvF7HMunyssX1jysZOybNpn9WmKRmynM MdXHV9nfRXZlQ7683nsAwAdLoxUZCe3HKSXegh4FCplrpHt5eTrsjHbo4Fywky1xuOWthR K8ok4JfNNYw10f8QetUP8cJhdaOHupjIaZpnanhaR/REYj0WYYSSSTV5MZSghSYa5rDJn9 9OCa/9BDUld/SnABDxxyDP8cmNOMEc1da8JBUVtDLBlz0x3maynNBq8SwLNLu83wJczj+/ z0wGaQJgyTncBo+d2Y1w/w4MyuiJMgiFdUCYXwnvX5RXyy11zyJMBDAvDkbSPw== 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=1716418923; 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=f8lybhmjlD3UPDNHphrjKA7qeS4s8DZKJ9DDbRWknGc=; b=RuUeiXkcAB6cvHbhuU+l2C0vMCi8YAkV3JMNyKlW76V9jretdIukCo5OWwhg/3Lwobx/hm iwm79hhUZDRHctS01UPMVH/nom+IGg3WHbou6Qr4fYjR4loLqBgjpZAPq9oAD/ufd8LFUO WvTkM8hTX7DPjyxd+AN1VsO/8Va1M78PPfYMxKGQaebk16jnczvNdPwF+5Ns824qc7sqER W5ULQJ90qk9C46YWt+ine1uPdw+xUffxvc0CWIS5ckF5q/h4rWSbtJRYz8iNqEpHBxecZG PBcSjZbOA0DcQ470/KOvOOupYTQ/iVn5x/Hif9DXlVn7b73NQPPmpZLUiGA8DA== 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 4Vl6JC5RQFzPDg; Wed, 22 May 2024 23:02:03 +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 44MN23Dh085356; Wed, 22 May 2024 23:02:03 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44MN236A085353; Wed, 22 May 2024 23:02:03 GMT (envelope-from git) Date: Wed, 22 May 2024 23:02:03 GMT Message-Id: <202405222302.44MN236A085353@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: 34db75d21876 - releng/14.1 - 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/releng/14.1 X-Git-Reftype: branch X-Git-Commit: 34db75d21876ae406ff57fdc594f151fc4214109 Auto-Submitted: auto-generated The branch releng/14.1 has been updated by zlei: URL: https://cgit.FreeBSD.org/src/commit/?id=34db75d21876ae406ff57fdc594f151fc4214109 commit 34db75d21876ae406ff57fdc594f151fc4214109 Author: Zhenlei Huang AuthorDate: 2024-05-20 12:14:07 +0000 Commit: Zhenlei Huang CommitDate: 2024-05-22 23:00:03 +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 Approved by: re (cperciva) 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 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);