Skip to content

Commit 69e16d0

Browse files
sishuaigongdavem330
authored andcommitted
net: fix a concurrency bug in l2tp_tunnel_register()
l2tp_tunnel_register() registers a tunnel without fully initializing its attribute. This can allow another kernel thread running l2tp_xmit_core() to access the uninitialized data and then cause a kernel NULL pointer dereference error, as shown below. Thread 1 Thread 2 //l2tp_tunnel_register() list_add_rcu(&tunnel->list, &pn->l2tp_tunnel_list); //pppol2tp_connect() tunnel = l2tp_tunnel_get(sock_net(sk), info.tunnel_id); // Fetch the new tunnel ... //l2tp_xmit_core() struct sock *sk = tunnel->sock; ... bh_lock_sock(sk); //Null pointer error happens tunnel->sock = sk; Fix this bug by initializing tunnel->sock before adding the tunnel into l2tp_tunnel_list. Reviewed-by: Cong Wang <cong.wang@bytedance.com> Signed-off-by: Sishuai Gong <sishuai@purdue.edu> Reported-by: Sishuai Gong <sishuai@purdue.edu> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 6fd6c48 commit 69e16d0

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

net/l2tp/l2tp_core.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,22 +1478,22 @@ int l2tp_tunnel_register(struct l2tp_tunnel *tunnel, struct net *net,
14781478
tunnel->l2tp_net = net;
14791479
pn = l2tp_pernet(net);
14801480

1481+
sk = sock->sk;
1482+
sock_hold(sk);
1483+
tunnel->sock = sk;
1484+
14811485
spin_lock_bh(&pn->l2tp_tunnel_list_lock);
14821486
list_for_each_entry(tunnel_walk, &pn->l2tp_tunnel_list, list) {
14831487
if (tunnel_walk->tunnel_id == tunnel->tunnel_id) {
14841488
spin_unlock_bh(&pn->l2tp_tunnel_list_lock);
1485-
1489+
sock_put(sk);
14861490
ret = -EEXIST;
14871491
goto err_sock;
14881492
}
14891493
}
14901494
list_add_rcu(&tunnel->list, &pn->l2tp_tunnel_list);
14911495
spin_unlock_bh(&pn->l2tp_tunnel_list_lock);
14921496

1493-
sk = sock->sk;
1494-
sock_hold(sk);
1495-
tunnel->sock = sk;
1496-
14971497
if (tunnel->encap == L2TP_ENCAPTYPE_UDP) {
14981498
struct udp_tunnel_sock_cfg udp_cfg = {
14991499
.sk_user_data = tunnel,

0 commit comments

Comments
 (0)