Skip to content

Commit

Permalink
l2tp: handle hash key collisions in l2tp_v3_session_get
Browse files Browse the repository at this point in the history
To handle colliding l2tpv3 session IDs, l2tp_v3_session_get searches a
hashed list keyed by ID and sk. Although unlikely, if hash keys
collide, it is possible that hash_for_each_possible loops over a
session which doesn't have the ID that we are searching for. So check
for session ID match when looping over possible hash key matches.

Signed-off-by: James Chapman <jchapman@katalix.com>
Signed-off-by: Tom Parkin <tparkin@katalix.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
James Chapman authored and David S. Miller committed Aug 11, 2024
1 parent ebed660 commit b0a8ded
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion net/l2tp/l2tp_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ struct l2tp_session *l2tp_v3_session_get(const struct net *net, struct sock *sk,
*/
struct l2tp_tunnel *tunnel = READ_ONCE(session->tunnel);

if (tunnel && tunnel->sock == sk &&
if (session->session_id == session_id &&
tunnel && tunnel->sock == sk &&
refcount_inc_not_zero(&session->ref_count)) {
rcu_read_unlock_bh();
return session;
Expand Down

0 comments on commit b0a8ded

Please sign in to comment.