Skip to content

Commit ca66be3

Browse files
author
Guillaume Nault
committed
l2tp: do not use sock_hold() in pppol2tp_session_get_sock()
JIRA: https://issues.redhat.com/browse/RHEL-115595 Upstream Status: linux.git commit 9b8c88f Author: Eric Dumazet <edumazet@google.com> Date: Tue Aug 26 13:44:35 2025 +0000 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 ee40fb2 ("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: c5cbaef ("l2tp: refactor ppp socket/session relationship") Signed-off-by: Eric Dumazet <edumazet@google.com> Cc: James Chapman <jchapman@katalix.com> Reviewed-by: Guillaume Nault <gnault@redhat.com> Link: https://patch.msgid.link/20250826134435.1683435-1-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Guillaume Nault <gnault@redhat.com>
1 parent 1338eff commit ca66be3

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

net/l2tp/l2tp_ppp.c

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,12 @@ static const struct ppp_channel_ops pppol2tp_chan_ops = {
129129

130130
static const struct proto_ops pppol2tp_ops;
131131

132-
/* Retrieves the pppol2tp socket associated to a session.
133-
* A reference is held on the returned socket, so this function must be paired
134-
* with sock_put().
135-
*/
132+
/* Retrieves the pppol2tp socket associated to a session. */
136133
static struct sock *pppol2tp_session_get_sock(struct l2tp_session *session)
137134
{
138135
struct pppol2tp_session *ps = l2tp_session_priv(session);
139-
struct sock *sk;
140-
141-
rcu_read_lock();
142-
sk = rcu_dereference(ps->sk);
143-
if (sk)
144-
sock_hold(sk);
145-
rcu_read_unlock();
146136

147-
return sk;
137+
return rcu_dereference(ps->sk);
148138
}
149139

150140
/* Helpers to obtain tunnel/session contexts from sockets.
@@ -206,14 +196,13 @@ static int pppol2tp_recvmsg(struct socket *sock, struct msghdr *msg,
206196

207197
static void pppol2tp_recv(struct l2tp_session *session, struct sk_buff *skb, int data_len)
208198
{
209-
struct pppol2tp_session *ps = l2tp_session_priv(session);
210-
struct sock *sk = NULL;
199+
struct sock *sk;
211200

212201
/* If the socket is bound, send it in to PPP's input queue. Otherwise
213202
* queue it on the session socket.
214203
*/
215204
rcu_read_lock();
216-
sk = rcu_dereference(ps->sk);
205+
sk = pppol2tp_session_get_sock(session);
217206
if (!sk)
218207
goto no_sock;
219208

@@ -510,13 +499,14 @@ static void pppol2tp_show(struct seq_file *m, void *arg)
510499
struct l2tp_session *session = arg;
511500
struct sock *sk;
512501

502+
rcu_read_lock();
513503
sk = pppol2tp_session_get_sock(session);
514504
if (sk) {
515505
struct pppox_sock *po = pppox_sk(sk);
516506

517507
seq_printf(m, " interface %s\n", ppp_dev_name(&po->chan));
518-
sock_put(sk);
519508
}
509+
rcu_read_unlock();
520510
}
521511

522512
static void pppol2tp_session_init(struct l2tp_session *session)
@@ -1529,6 +1519,7 @@ static void pppol2tp_seq_session_show(struct seq_file *m, void *v)
15291519
port = ntohs(inet->inet_sport);
15301520
}
15311521

1522+
rcu_read_lock();
15321523
sk = pppol2tp_session_get_sock(session);
15331524
if (sk) {
15341525
state = sk->sk_state;
@@ -1564,8 +1555,8 @@ static void pppol2tp_seq_session_show(struct seq_file *m, void *v)
15641555
struct pppox_sock *po = pppox_sk(sk);
15651556

15661557
seq_printf(m, " interface %s\n", ppp_dev_name(&po->chan));
1567-
sock_put(sk);
15681558
}
1559+
rcu_read_unlock();
15691560
}
15701561

15711562
static int pppol2tp_seq_show(struct seq_file *m, void *v)

0 commit comments

Comments
 (0)