* [PATCH net] l2tp: only return sessions of the given tunnel in l2tp_session_get()
@ 2026-10-25 14:58 Hengyu Liang
2026-10-25 15:01 ` netdev-bot+sinfo
0 siblings, 1 reply; 2+ messages in thread
From: Hengyu Liang @ 2026-10-25 14:58 UTC (permalink / raw)
To: davem, edumazet, kuba, pabeni, netdev
Cc: horms, jchapman, tparkin, gnault, linux-kernel, stable
Commit 5f77c18ea556 ("l2tp: use IDR for all session lookups") made
pppol2tp_connect() and the netlink session commands find sessions with
l2tp_session_get(), which takes a tunnel ID and a session ID.
However, for L2TPv3, l2tp_session_get() does not use the tunnel ID. If
no other session has the same session ID, it returns that session,
whichever tunnel it belongs to. As of now, a session command that names
the wrong tunnel acts on a session of another tunnel, and a PPPoL2TP
socket for a second L2TPv3 tunnel fails with EEXIST, because it finds
session 0 of the first tunnel.
The issue can be reproduced with:
ip l2tp add tunnel tunnel_id 3 peer_tunnel_id 3 encap udp \
local 127.0.0.1 remote 127.0.0.1 udp_sport 5003 udp_dport 6003
ip l2tp add tunnel tunnel_id 4 peer_tunnel_id 4 encap udp \
local 127.0.0.1 remote 127.0.0.1 udp_sport 5004 udp_dport 6004
ip l2tp add session tunnel_id 3 session_id 7 peer_session_id 7
ip l2tp del session tunnel_id 4 session_id 7
ip l2tp show session
Before that commit, the delete fails with "No such device", and session
7 of tunnel 3 is still listed. After that commit, the delete succeeds,
and session 7 of tunnel 3 is gone.
This patch will make l2tp_session_get() return NULL when the L2TPv3
session it finds belongs to another tunnel.
Fixes: 5f77c18ea556 ("l2tp: use IDR for all session lookups")
Cc: stable@vger.kernel.org
Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu>
---
The first commit that shows the problem is d18d3f0a24fc ("l2tp: replace
hlist with simple list for per-tunnel session list"), two patches later
in the same series. Before it, these L2TPv3 lookups found no session at
all.
The receive path still looks up L2TPv3 sessions by session ID only. Only
the lookups that name a tunnel change.
Tested with the commands above, the same session ID in two UDP tunnels
(still allowed) and in two IP tunnels (still refused), and two PPPoL2TP
tunnel sockets.
net/l2tp/l2tp_core.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c
index 7e042a3e648c..f509750f80d5 100644
--- a/net/l2tp/l2tp_core.c
+++ b/net/l2tp/l2tp_core.c
@@ -315,10 +315,19 @@ EXPORT_SYMBOL_GPL(l2tp_v2_session_get);
struct l2tp_session *l2tp_session_get(const struct net *net, struct sock *sk, int pver,
u32 tunnel_id, u32 session_id)
{
+ struct l2tp_session *session;
+
if (pver == L2TP_HDR_VER_2)
return l2tp_v2_session_get(net, tunnel_id, session_id);
- else
- return l2tp_v3_session_get(net, sk, session_id);
+
+ /* An L2TPv3 session ID that has not collided may be in any tunnel */
+ session = l2tp_v3_session_get(net, sk, session_id);
+ if (session && session->tunnel->tunnel_id != tunnel_id) {
+ l2tp_session_put(session);
+ return NULL;
+ }
+
+ return session;
}
EXPORT_SYMBOL_GPL(l2tp_session_get);
base-commit: 7076f684d5132e6a6145e1da2fa74771ecd052e5
--
2.53.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH net] l2tp: only return sessions of the given tunnel in l2tp_session_get()
2026-10-25 14:58 [PATCH net] l2tp: only return sessions of the given tunnel in l2tp_session_get() Hengyu Liang
@ 2026-10-25 15:01 ` netdev-bot+sinfo
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sinfo @ 2026-10-25 15:01 UTC (permalink / raw)
To: Hengyu Liang
Cc: davem, edumazet, kuba, pabeni, netdev, horms, jchapman, tparkin,
gnault, linux-kernel, stable
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during
development, syzbot report, manual code inspection, LLM or static
analysis tool scan.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account. If the series needs another revision for
other reasons, please include the information in the commit messages
then.
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-25 15:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-25 14:58 [PATCH net] l2tp: only return sessions of the given tunnel in l2tp_session_get() Hengyu Liang
2026-10-25 15:01 ` netdev-bot+sinfo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®