Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 May 2024 13:59:23 GMT
From:      Zhenlei Huang <zlei@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 3ebd2b1c7308 - stable/14 - if_vxlan(4): Add checking for loops and nesting of tunnels
Message-ID:  <202405221359.44MDxNAP051517@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by zlei:

URL: https://cgit.FreeBSD.org/src/commit/?id=3ebd2b1c730834123a53b3eddcf9029fcf414782

commit 3ebd2b1c730834123a53b3eddcf9029fcf414782
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2024-05-20 12:14:07 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202405221359.44MDxNAP051517>