From nobody Mon May 20 12:15:11 2024 X-Original-To: dev-commits-src-main@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 4Vjc2l5bZgz5L7yw; Mon, 20 May 2024 12:15:11 +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 4Vjc2l3vJ7z4Fg6; Mon, 20 May 2024 12:15:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716207311; 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=TLij/l1vEELjeTm00Fd0tIxudMJb/vpHfjNKt2lQ21E=; b=bHyAuxvx5RyeejAMwiP/ejPX8LbPnRqpkAacvEEROuGKpNqIC6l7l5TJQxzWLrpL4c18Gx HakbFxCwQXkuolDSBMClsXBj+EM+4iRENqn02y/xIjXZHNrizyW9NklpUWmvffm+Rdtv6n 9Vy13dAJv+v8yzcDNYYDfd6b0+MOvL6PhqvFAlTvE7h4HH0R9j2JoRrDYlj0Epj31MEv+9 vnZ1aE8iy7Liufwh0WepEDKMtRY7bLaR+rrSPZwE2VxaSrDzUm0XX+d/wBlxPZyUHZs4bO UQGT10/f2L0bkA7WwULGgTI8tKlhzykGND0gSbS1no4FuxK04jUsguDyisrSmg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716207311; a=rsa-sha256; cv=none; b=bljGBMCkY4NWUABx+4u+FPgwRW88IDlfEtV7mSqdtFW+xtuWFjLqg7ABAYJN+IAsTS5InV oSVaEFfr1JcjVXErE6q59GAmgb16DvKW8wzgTBZVPQkAeN7RfICBeemcmF0DbwzIFYInAy gNdfcAwJG6DbbC3+x8RbyI8hHFxEKScyXuTmF0j7Wcl/72yqUw12KN/hdBpG/ifOAc/vwv 7l13OCETd/bEWUkAOqM0/4oxPIDd52AWMhwHa1deLOD/DBT44oojcpPQ7Cf40ADGOr+z0U 6+RHx2uFhwLX35k37qEiyrsSEWToIfvCOnp7tqegCjS15SIZSBqJad2MzbOxCQ== 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=1716207311; 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=TLij/l1vEELjeTm00Fd0tIxudMJb/vpHfjNKt2lQ21E=; b=xkTgU8Y1c2WUjx/yHdSIBFGte2VsqRvHphyz1KGy7cAlIwvKV6YZkz1eJ2oD2OQliGoDIB xcH6e2bvJ4vXCA9K4UdyqYTJEOaMGsg+/e+eRnD18Ym56xVS7gLdD72Hj7q0M+ADw79Cdc BEh2DzmPmYZrfqMCyPWSzSxMWYuLe9q6gvZEjT9iPn7+FjbOdTNi3/KQloEJGWjJHVok/s bH2BARvQHJcxgrv1xf2bTDJWN9GOSvu+y2Jf8KqoEFJGf6lLeiJxWooBjUafFI6DceL3Tu JZBi9lo2/7zZ18x3TE61OEuoujNBPqAuWsowPuPbx8y1r3XQQ7oStPgQYWxrmg== 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 4Vjc2l2Gv8zdLT; Mon, 20 May 2024 12:15:11 +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 44KCFBZ3011724; Mon, 20 May 2024 12:15:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44KCFBNZ011721; Mon, 20 May 2024 12:15:11 GMT (envelope-from git) Date: Mon, 20 May 2024 12:15:11 GMT Message-Id: <202405201215.44KCFBNZ011721@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Zhenlei Huang Subject: git: 93fbfef0b503 - main - if_vxlan(4): Add checking for loops and nesting of tunnels List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 93fbfef0b50354b7a1620822454ef29cd415cb2d Auto-Submitted: auto-generated The branch main has been updated by zlei: URL: https://cgit.FreeBSD.org/src/commit/?id=93fbfef0b50354b7a1620822454ef29cd415cb2d commit 93fbfef0b50354b7a1620822454ef29cd415cb2d Author: Zhenlei Huang AuthorDate: 2024-05-20 12:14:07 +0000 Commit: Zhenlei Huang CommitDate: 2024-05-20 12:14:07 +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 --- 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 c6c3af57c78b..9153adf64cfc 100644 --- a/sys/net/if_vxlan.c +++ b/sys/net/if_vxlan.c @@ -432,6 +432,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 @@ -2721,6 +2736,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) { @@ -2746,6 +2762,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);