netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] l2tp: do not use sock_hold() in pppol2tp_session_get_sock()
@ 2025-08-26 13:44 Eric Dumazet
  2025-08-27 12:05 ` Guillaume Nault
  2025-08-28  0:30 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Eric Dumazet @ 2025-08-26 13:44 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, netdev, eric.dumazet, Eric Dumazet, James Chapman,
	Guillaume Nault

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.

Fixes: c5cbaef992d6 ("l2tp: refactor ppp socket/session relationship")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: James Chapman <jchapman@katalix.com>
Cc: Guillaume Nault <gnault@redhat.com>
---
 net/l2tp/l2tp_ppp.c | 25 ++++++++-----------------
 1 file changed, 8 insertions(+), 17 deletions(-)

diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
index fc5c2fd8f34c7ec23e6f5ab978ea96c9f48ac81d..5e12e7ce17d8a7cf4afc2486f1c3c42f98feddf1 100644
--- a/net/l2tp/l2tp_ppp.c
+++ b/net/l2tp/l2tp_ppp.c
@@ -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)
-- 
2.51.0.261.g7ce5a0a67e-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] l2tp: do not use sock_hold() in pppol2tp_session_get_sock()
  2025-08-26 13:44 [PATCH net] l2tp: do not use sock_hold() in pppol2tp_session_get_sock() Eric Dumazet
@ 2025-08-27 12:05 ` Guillaume Nault
  2025-08-28  0:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Guillaume Nault @ 2025-08-27 12:05 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
	netdev, eric.dumazet, James Chapman

On Tue, Aug 26, 2025 at 01:44:35PM +0000, Eric Dumazet wrote:
> 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.

Reviewed-by: Guillaume Nault <gnault@redhat.com>

Thank!


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] l2tp: do not use sock_hold() in pppol2tp_session_get_sock()
  2025-08-26 13:44 [PATCH net] l2tp: do not use sock_hold() in pppol2tp_session_get_sock() Eric Dumazet
  2025-08-27 12:05 ` Guillaume Nault
@ 2025-08-28  0:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-08-28  0:30 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: davem, kuba, pabeni, horms, netdev, eric.dumazet, jchapman,
	gnault

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue, 26 Aug 2025 13:44:35 +0000 you wrote:
> 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.
> 
> [...]

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-08-28  0:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-26 13:44 [PATCH net] l2tp: do not use sock_hold() in pppol2tp_session_get_sock() Eric Dumazet
2025-08-27 12:05 ` Guillaume Nault
2025-08-28  0:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).