Skip to content

Commit 069eb65

Browse files
edumazetgregkh
authored andcommitted
l2tp: do not use sock_hold() in pppol2tp_session_get_sock()
[ Upstream commit 9b8c88f ] 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: Sasha Levin <sashal@kernel.org>
1 parent f6c2cc9 commit 069eb65

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)
@@ -1530,6 +1520,7 @@ static void pppol2tp_seq_session_show(struct seq_file *m, void *v)
15301520
port = ntohs(inet->inet_sport);
15311521
}
15321522

1523+
rcu_read_lock();
15331524
sk = pppol2tp_session_get_sock(session);
15341525
if (sk) {
15351526
state = sk->sk_state;
@@ -1565,8 +1556,8 @@ static void pppol2tp_seq_session_show(struct seq_file *m, void *v)
15651556
struct pppox_sock *po = pppox_sk(sk);
15661557

15671558
seq_printf(m, " interface %s\n", ppp_dev_name(&po->chan));
1568-
sock_put(sk);
15691559
}
1560+
rcu_read_unlock();
15701561
}
15711562

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

0 commit comments

Comments
 (0)