Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp99649lqo; Thu, 9 May 2024 13:58:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVyEW25QYGeh66lNTKtmqwNX/c2PwLRl6QiwDAD4x7S3R9LL7Iw22XJah5khTPwJe8bNTv9QhAJhg1W0MPVuqT0II0SvJNsj/XsheB+PQ== X-Google-Smtp-Source: AGHT+IFuY1Fqs9UAWIfgt4NTbwen2ZJLL0gwg12vBNo65pBUnol1cqdR93zj6zVHrVMsSX4Lh3pQ X-Received: by 2002:a50:9353:0:b0:56c:5990:813e with SMTP id 4fb4d7f45d1cf-5734d5bfbd8mr474621a12.13.1715288327162; Thu, 09 May 2024 13:58:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715288327; cv=pass; d=google.com; s=arc-20160816; b=SPz+k2vKgjX6vlMpgJR2TFjhuU7DsAP29FpEAGeX8wbB2lAZoSwPeNGxYWIlg5vyHg 4uNb49lIXw1QXEo8i3Me48Fw4jQO+CFaMpkVBFg8cjkcEX7e7kCVRQv2aVch14alDO8g zHZuv01oZqYCD8UAO3QtdzimTf1GTk/lue6ONQGRQ8HtgMwTr58MvRW2oyEc20JnEPvF RSC86+QHja89pW0KNLV1+5q4bMg5I8lBi/1JPtFFvZ/N11E3+xSHCZXM2tM1wa+4Y182 Nn5b10WfEG2mvjBpUPJaxBxESs/S/hQ0JbsiBJF+ox6siRDUveCQybYqRII1jsZd7JBY ancQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=maPTV/VSqsJWviKXVrsm+KkutTtXbLfIQVtuLHCQb/Q=; fh=iQdkx44VJ2cVbiuZ/f2+CVIxpjCmHJ7f6o+cQbAn0mo=; b=WA4bjj7zWLB4/JwC/tzZlDXIqTWYVVaA1aiNefIRD+imJq9ayfrSMAsBMcMvQCEDo9 cUJV29hNpkPVXOFpdyRSzGdwQgs/0WDfUG7LTuWKth++AK/HmIfiD1k1DZjDVNuma0oT NxUhBeM7KiMTB1YcTe5eo1TvBTa+Ao3G/1Wa6bDLCeJiQ/Q/SItBAm5awk04t8OmDUuB xh95juJEAxQKRI014grpQCnJzQdM1tSdJw5kur223Gp77edeQQO39prgd1SkoXgZyvx5 /MZ+E9/nzHqe3BwBj4wwmwpkHb9ousdiel9s/bzqqeO43cn3q/N28V4c9zZNXrVG7i7F /lNQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=bounce.ens-lyon.org); spf=pass (google.com: domain of linux-kernel+bounces-174959-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174959-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733c2e3e76si1100035a12.248.2024.05.09.13.58.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 13:58:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-174959-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=bounce.ens-lyon.org); spf=pass (google.com: domain of linux-kernel+bounces-174959-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174959-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D1DCA1F22020 for ; Thu, 9 May 2024 20:58:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E8CBF8528D; Thu, 9 May 2024 20:58:25 +0000 (UTC) Received: from sonata.ens-lyon.org (domu-toccata.ens-lyon.fr [140.77.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B85F384DEE; Thu, 9 May 2024 20:58:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=140.77.166.138 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715288305; cv=none; b=YS4b8fSUtBSUGmQdgtLUlLpjpVgAlfC63I0aoZnrW8m8gKzY7XB8cM1nU+IBFtUEfEPNyWmOozo384UDJyrHWkbT9mOf5Tb5LcEV+LXJ1Z7rcKaKFYp2Z6NNPq7DicM9LplcqLj0aZoIHIRByn5ZI0POay6kp1eQCT+bZ5DFcOQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715288305; c=relaxed/simple; bh=C67xdYWkBGECbhZb4PGQ2m356x1NuCq2vdcx75RdNeQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=l5NHHXX+WsDoTo339JkTDyFMSxC1U9z2BhLRq4bD65B9YKZbhLXPzAnAhGnUzmQa5yRxjd3aMRm9IRTPziBFIGm+aWZNbG3sg4XUu/p8QS5cDrXxnIkA9kwWUsMec00r/lME1hKyN5f47J+VsMCsUdj/JDk97sXwKsRG23VnFgc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org; spf=pass smtp.mailfrom=bounce.ens-lyon.org; arc=none smtp.client-ip=140.77.166.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bounce.ens-lyon.org Received: from localhost (localhost [127.0.0.1]) by sonata.ens-lyon.org (Postfix) with ESMTP id D8533A0336; Thu, 9 May 2024 22:58:15 +0200 (CEST) Received: from sonata.ens-lyon.org ([127.0.0.1]) by localhost (sonata.ens-lyon.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xslR1qoH_xYw; Thu, 9 May 2024 22:58:15 +0200 (CEST) Received: from begin (aamiens-653-1-111-57.w83-192.abo.wanadoo.fr [83.192.234.57]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by sonata.ens-lyon.org (Postfix) with ESMTPSA id AB897A0332; Thu, 9 May 2024 22:58:15 +0200 (CEST) Received: from samy by begin with local (Exim 4.97) (envelope-from ) id 1s5AqF-0000000H31a-0DdT; Thu, 09 May 2024 22:58:15 +0200 From: Samuel Thibault To: linux-kernel@vger.kernel.org, tparkin@katalix.com, Eric Dumazet , Jakub Kicinski , Paolo Abeni , James Chapman Cc: Samuel Thibault , netdev@vger.kernel.org Subject: [PATCH] l2tp: Support different protocol versions with same IP/port quadruple Date: Thu, 9 May 2024 22:58:12 +0200 Message-ID: <20240509205812.4063198-1-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 628bc3e5a1be ("l2tp: Support several sockets with same IP/port quadruple") added support for several L2TPv2 tunnels using the same IP/port quadruple, but if an L2TPv3 socket exists it could eat all the trafic. We thus have to first use the version from the packet to get the proper tunnel, and only then check that the version matches. Signed-off-by: Samuel Thibault --- net/l2tp/l2tp_core.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c index 2ab45e3f48bf..7d519a46a844 100644 --- a/net/l2tp/l2tp_core.c +++ b/net/l2tp/l2tp_core.c @@ -820,13 +820,8 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb) /* Get L2TP header flags */ hdrflags = ntohs(*(__be16 *)ptr); - /* Check protocol version */ + /* Get protocol version */ version = hdrflags & L2TP_HDR_VER_MASK; - if (version != tunnel->version) { - pr_debug_ratelimited("%s: recv protocol version mismatch: got %d expected %d\n", - tunnel->name, version, tunnel->version); - goto invalid; - } /* Get length of L2TP packet */ length = skb->len; @@ -838,7 +833,7 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb) /* Skip flags */ ptr += 2; - if (tunnel->version == L2TP_HDR_VER_2) { + if (version == L2TP_HDR_VER_2) { /* If length is present, skip it */ if (hdrflags & L2TP_HDRFLAG_L) ptr += 2; @@ -855,7 +850,7 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb) struct l2tp_tunnel *alt_tunnel; alt_tunnel = l2tp_tunnel_get(tunnel->l2tp_net, tunnel_id); - if (!alt_tunnel || alt_tunnel->version != L2TP_HDR_VER_2) + if (!alt_tunnel) goto pass; tunnel = alt_tunnel; } @@ -869,6 +864,13 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb) ptr += 4; } + /* Check protocol version */ + if (version != tunnel->version) { + pr_debug_ratelimited("%s: recv protocol version mismatch: got %d expected %d\n", + tunnel->name, version, tunnel->version); + goto invalid; + } + /* Find the session context */ session = l2tp_tunnel_get_session(tunnel, session_id); if (!session || !session->recv_skb) { -- 2.43.0