Skip to contentSkip to conversation

net: l2tp: unlock socket lock before returning from l2tp_ip_sendmsg

PATCH Superseded Sasha Levin 2 participants 3 messages May 2, 2012

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: l2tp: unlock socket lock before returning from l2tp_ip_sendmsg

l2tp_ip_sendmsg could return without releasing socket lock, making it all the way to userspace, and generating the following warning:

[  130.891594] ================================================
[  130.894569] [ BUG: lock held when returning to user space! ]
[  130.897257] 3.4.0-rc5-next-20120501-sasha #104 Tainted: G        W
[  130.900336] ------------------------------------------------
[  130.902996] trinity/8384 is leaving the kernel with locks still held!
[  130.906106] 1 lock held by trinity/8384:
[  130.907924]  #0:  (sk_lock-AF_INET){+.+.+.}, at: [<ffffffff82b9503f>] l2tp_ip_sendmsg+0x2f/0x550
---
 net/l2tp/l2tp_ip.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
net/l2tp/l2tp_ip.c +4 -2
index 585d93e..a4d8364 100644
@@ -442,8 +442,10 @@ static int l2tp_ip_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
 
 		daddr = lip->l2tp_addr.s_addr;
 	} else {
-		if (sk->sk_state != TCP_ESTABLISHED)
-			return -EDESTADDRREQ;
+		if (sk->sk_state != TCP_ESTABLISHED) {
+			rc = -EDESTADDRREQ;
+			goto out;
+		}
 
 		daddr = inet->inet_daddr;
 		connected = 1;
Signature · 1 line
1.7.8.5
#1 lore raw
Quoted 23 lines · Sasha Levin

l2tp_ip_sendmsg could return without releasing socket lock, making it all the way to userspace, and generating the following warning:

[  130.891594] ================================================
[  130.894569] [ BUG: lock held when returning to user space! ]
[  130.897257] 3.4.0-rc5-next-20120501-sasha #104 Tainted: G        W
[  130.900336] ------------------------------------------------
[  130.902996] trinity/8384 is leaving the kernel with locks still held!
[  130.906106] 1 lock held by trinity/8384:
[  130.907924]  #0:  (sk_lock-AF_INET){+.+.+.}, at: [<ffffffff82b9503f>] l2tp_ip_sendmsg+0x2f/0x550
---
 net/l2tp/l2tp_ip.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
net/l2tp/l2tp_ip.c +0 -0
index 585d93e..a4d8364 100644
@@ -442,8 +442,10 @@ static int l2tp_ip_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
 
 		daddr = lip->l2tp_addr.s_addr;

net/l2tp/l2tp_ip.c static int l2tp_ip_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m · line 451

Quoted 10 lines
net/l2tp/l2tp_ip.c +4 -2
 	} else {
-		if (sk->sk_state != TCP_ESTABLISHED)
-			return -EDESTADDRREQ;
+		if (sk->sk_state != TCP_ESTABLISHED) {
+			rc = -EDESTADDRREQ;
+			goto out;
+		}
 
 		daddr = inet->inet_daddr;
 		connected = 1;

Good catch, but please use existing code style in this function.

rc = -EDESTADDRREQ;
if (sk->sk_state != TCP_ESTABLISHED)

	goto out;

Also, please add in your commit message bug origin to ease stable team work (not counting reviewers work)

Bug added in commit 2f16270f41e1 (l2tp: Fix locking in l2tp_ip.c)

Really, given the amount of patches you already sent, you should already know that.

Thanks

#2 lore raw
Quoted 9 lines · Eric Dumazet

Good catch, but please use existing code style in this function.

rc = -EDESTADDRREQ;
if (sk->sk_state != TCP_ESTABLISHED)
       goto out;

Also, please add in your commit message bug origin to ease stable team work (not counting reviewers work)

Quoted 8 lines

Bug added in commit 2f16270f41e1 (l2tp: Fix locking in l2tp_ip.c)

Really, given the amount of patches you already sent, you should already know that.

Thanks

Understood. I'll resend.