Skip to content

Commit 2f16270

Browse files
committed
l2tp: Fix locking in l2tp_ip.c
Both l2tp_ip_connect() and l2tp_ip_sendmsg() must take the socket lock. They both modify socket state non-atomically, and in particular l2tp_ip_sendmsg() increments socket private counters without using atomic operations. Signed-off-by: David S. Miller <[email protected]>
1 parent da905bd commit 2f16270

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

net/l2tp/l2tp_ip.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ static int l2tp_ip_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len
311311
if (lsa->l2tp_family != AF_INET)
312312
goto out;
313313

314+
lock_sock(sk);
315+
314316
sk_dst_reset(sk);
315317

316318
oif = sk->sk_bound_dev_if;
@@ -356,6 +358,7 @@ static int l2tp_ip_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len
356358

357359
rc = 0;
358360
out:
361+
release_sock(sk);
359362
return rc;
360363
}
361364

@@ -420,18 +423,23 @@ static int l2tp_ip_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
420423
int connected = 0;
421424
__be32 daddr;
422425

426+
lock_sock(sk);
427+
428+
rc = -ENOTCONN;
423429
if (sock_flag(sk, SOCK_DEAD))
424-
return -ENOTCONN;
430+
goto out;
425431

426432
/* Get and verify the address. */
427433
if (msg->msg_name) {
428434
struct sockaddr_l2tpip *lip = (struct sockaddr_l2tpip *) msg->msg_name;
435+
rc = -EINVAL;
429436
if (msg->msg_namelen < sizeof(*lip))
430-
return -EINVAL;
437+
goto out;
431438

432439
if (lip->l2tp_family != AF_INET) {
440+
rc = -EAFNOSUPPORT;
433441
if (lip->l2tp_family != AF_UNSPEC)
434-
return -EAFNOSUPPORT;
442+
goto out;
435443
}
436444

437445
daddr = lip->l2tp_addr.s_addr;
@@ -510,12 +518,15 @@ static int l2tp_ip_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
510518
lsa->tx_errors++;
511519
}
512520

521+
out:
522+
release_sock(sk);
513523
return rc;
514524

515525
no_route:
516526
IP_INC_STATS(sock_net(sk), IPSTATS_MIB_OUTNOROUTES);
517527
kfree_skb(skb);
518-
return -EHOSTUNREACH;
528+
rc = -EHOSTUNREACH;
529+
goto out;
519530
}
520531

521532
static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,

0 commit comments

Comments
 (0)