l2tp: free sessions using rcu
authorJames Chapman <jchapman@katalix.com>
Mon, 29 Jul 2024 15:38:08 +0000 (16:38 +0100)
committerDavid S. Miller <davem@davemloft.net>
Wed, 31 Jul 2024 08:25:13 +0000 (09:25 +0100)
l2tp sessions may be accessed under an rcu read lock. Have them freed
via rcu and remove the now unneeded synchronize_rcu when a session is
removed.

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>
net/l2tp/l2tp_core.c
net/l2tp/l2tp_core.h

index f6ae18c180bfbafc196b85727e3aeab6be0ef7b1..4cf4aa2713535b49e39ad886b6ecb3e908f1d8c4 100644 (file)
@@ -166,7 +166,7 @@ static void l2tp_session_free(struct l2tp_session *session)
        trace_free_session(session);
        if (session->tunnel)
                l2tp_tunnel_dec_refcount(session->tunnel);
-       kfree(session);
+       kfree_rcu(session, rcu);
 }
 
 struct l2tp_tunnel *l2tp_sk_to_tunnel(const struct sock *sk)
@@ -1269,8 +1269,6 @@ static void l2tp_session_unhash(struct l2tp_session *session)
 
                spin_unlock_bh(&pn->l2tp_session_idr_lock);
                spin_unlock_bh(&tunnel->list_lock);
-
-               synchronize_rcu();
        }
 }
 
index 8d7a589ccd2ad758a13683037b55e9fb46aa0e97..58d3977870de4b5b67267be41194a2a78363bdfa 100644 (file)
@@ -66,6 +66,7 @@ struct l2tp_session_coll_list {
 struct l2tp_session {
        int                     magic;          /* should be L2TP_SESSION_MAGIC */
        long                    dead;
+       struct rcu_head         rcu;
 
        struct l2tp_tunnel      *tunnel;        /* back pointer to tunnel context */
        u32                     session_id;