l2tp: do not use sock_hold() in pppol2tp_session_get_sock()
Subsystems (3)
PATCH 1/1 l2tp: do not use sock_hold() in pppol2tp_session_get_sock()
pppol2tp_session_get_sock() is using RCU, it must be ready for sk_refcnt being zero.
Commit ee40fb2e1eb5 ("l2tp: protect sock pointer of
struct pppol2tp_session with RCU") was correct because it
had a call_rcu(..., pppol2tp_put_sk) which was later removed in blamed commit.
pppol2tp_recv() can use pppol2tp_session_get_sock() as well.
--- net/l2tp/l2tp_ppp.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-)
net/l2tp/l2tp_ppp.c +8 -17
@@ -129,22 +129,12 @@ static const struct ppp_channel_ops pppol2tp_chan_ops = {static const struct proto_ops pppol2tp_ops; -/* Retrieves the pppol2tp socket associated to a session. -* A reference is held on the returned socket, so this function must be paired -* with sock_put(). -*/ +/* Retrieves the pppol2tp socket associated to a session. */ static struct sock *pppol2tp_session_get_sock (struct l2tp_session *session) {struct pppol2tp_session *ps =l2tp_session_priv (session); -struct sock *sk; - -rcu_read_lock (); - sk =rcu_dereference (ps->sk); -if (sk) -sock_hold (sk); -rcu_read_unlock (); -return sk; +return rcu_dereference (ps->sk); }/* Helpers to obtain tunnel/session contexts from sockets.
@@ -206,14 +196,13 @@ static int pppol2tp_recvmsg(struct socket *sock, struct msghdr *msg,static void pppol2tp_recv (struct l2tp_session *session,struct sk_buff *skb,int data_len) { -struct pppol2tp_session *ps =l2tp_session_priv (session); -struct sock *sk =NULL ; +struct sock *sk;/* If the socket is bound, send it in to PPP's input queue. Otherwise * queue it on the session socket. */ rcu_read_lock (); - sk =rcu_dereference (ps->sk); + sk =pppol2tp_session_get_sock (session);if (!sk) goto no_sock;
@@ -510,13 +499,14 @@ static void pppol2tp_show(struct seq_file *m, void *arg)struct l2tp_session *session = arg;struct sock *sk; +rcu_read_lock (); sk =pppol2tp_session_get_sock (session);if (sk) {struct pppox_sock *po =pppox_sk (sk);seq_printf (m," interface %s\n" ,ppp_dev_name (&po->chan)); -sock_put (sk); } +rcu_read_unlock (); }static void pppol2tp_session_init (struct l2tp_session *session)
@@ -1530,6 +1520,7 @@ static void pppol2tp_seq_session_show(struct seq_file *m, void *v) port =ntohs (inet->inet_sport); } +rcu_read_lock (); sk =pppol2tp_session_get_sock (session);if (sk) { state = sk->sk_state;
@@ -1565,8 +1556,8 @@ static void pppol2tp_seq_session_show(struct seq_file *m, void *v)struct pppox_sock *po =pppox_sk (sk);seq_printf (m," interface %s\n" ,ppp_dev_name (&po->chan)); -sock_put (sk); } +rcu_read_unlock (); }static int pppol2tp_seq_show (struct seq_file *m,void *v)
Signature · 1 line
2.51.0.261.g7ce5a0a67e-goog
Quoted 6 lines · Eric Dumazet
pppol2tp_session_get_sock()is using RCU, it must be ready forsk_refcntbeing zero.Commit
ee40fb2e1eb5("l2tp: protect sock pointer of
structpppol2tp_sessionwith RCU") was correct because it
had acall_rcu(..., pppol2tp_put_sk)which was later removed in blamed commit.
Thank!
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Tue, 26 Aug 2025 13:44:35 +0000 you wrote:
pppol2tp_session_get_sock()is using RCU, it must be ready forsk_refcntbeing zero.Commit
ee40fb2e1eb5("l2tp: protect sock pointer of
structpppol2tp_sessionwith RCU") was correct because it
had acall_rcu(..., pppol2tp_put_sk)which was later removed in blamed commit.[...]
Here is the summary with links:
- [net] l2tp: do not use sock_hold() in pppol2tp_session_get_sock()
https://git.kernel.org/netdev/net/c/9b8c88f875c0
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html