Skip to content

Commit

Permalink
l2tp: Support different protocol versions with same IP/port quadruple
Browse files Browse the repository at this point in the history
628bc3e ("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 <samuel.thibault@ens-lyon.org>
Reviewed-by: James Chapman <jchapman@katalix.com>
Link: https://lore.kernel.org/r/20240509205812.4063198-1-samuel.thibault@ens-lyon.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Samuel Thibault authored and Jakub Kicinski committed May 13, 2024
1 parent ec8c257 commit 3647980
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions net/l2tp/l2tp_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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) {
Expand Down

0 comments on commit 3647980

Please sign in to comment.