Skip to contentSkip to conversation

fix broken locking in x25 ioctl error paths

PATCH Dave Jones 3 participants 5 messages Jun 28, 2013 – Jul 2, 2013

Subsystems (3)
lore
Share & tools
lore

Dave Jones

author
#0 lore raw

Two of the x25 ioctl cases have error paths that break out of the function without unlocking the socket, leading to this warning:

================================================
[ BUG: lock held when returning to user space! ]
3.10.0-rc7+ #36 Not tainted
------------------------------------------------
trinity-child2/31407 is leaving the kernel with locks still held!
1 lock held by trinity-child2/31407:
#0: (sk_lock-AF_X25){+.+.+.}, at: [<ffffffffa024b6da>] x25_ioctl+0x8a/0x740 [x25]

net/x25/af_x25.c +7 -5
index 37ca969..2c1e633 100644
@@ -1584,10 +1584,11 @@ out_cud_release:
 		rc = -EINVAL;
 		lock_sock(sk);
 		if (sk->sk_state != TCP_CLOSE)
-			break;
+			goto out_callaccpt_release;
 		clear_bit(X25_ACCPT_APPRV_FLAG, &x25->flags);
-		release_sock(sk);
 		rc = 0;
+out_callaccpt_release:
+		release_sock(sk);
 		break;
 	}
 
@@ -1595,14 +1596,15 @@ out_cud_release:
 		rc = -EINVAL;
 		lock_sock(sk);
 		if (sk->sk_state != TCP_ESTABLISHED)
-			break;
+			goto out_sendcallaccpt_release;
 		/* must call accptapprv above */
 		if (test_bit(X25_ACCPT_APPRV_FLAG, &x25->flags))
-			break;
+			goto out_sendcallaccpt_release;
 		x25_write_internal(sk, X25_CALL_ACCEPTED);
 		x25->state = X25_STATE_3;
-		release_sock(sk);
 		rc = 0;
+out_sendcallaccpt_release:
+		release_sock(sk);
 		break;
 	}
 
#1 lore raw
Quoted 21 lines · Dave Jones

Two of the x25 ioctl cases have error paths that break out of the function without unlocking the socket, leading to this warning:

================================================
[ BUG: lock held when returning to user space! ]
3.10.0-rc7+ #36 Not tainted
------------------------------------------------
trinity-child2/31407 is leaving the kernel with locks still held!
1 lock held by trinity-child2/31407:
#0: (sk_lock-AF_X25){+.+.+.}, at: [<ffffffffa024b6da>] x25_ioctl+0x8a/0x740 [x25]

net/x25/af_x25.c +0 -0
index 37ca969..2c1e633 100644
@@ -1584,10 +1584,11 @@ out_cud_release:
 		rc = -EINVAL;
 		lock_sock(sk);

net/x25/af_x25.c out_cud_release: · line 1593

Quoted 10 lines
net/x25/af_x25.c +3 -2
 		if (sk->sk_state != TCP_CLOSE)
-			break;
+			goto out_callaccpt_release;
 		clear_bit(X25_ACCPT_APPRV_FLAG, &x25->flags);
-		release_sock(sk);
 		rc = 0;
+out_callaccpt_release:
+		release_sock(sk);
 		break;
 	}

Or :

lock_sock(sk);

if (sk->sk_state == TCP_CLOSE) {
    clear_bit(X25_ACCPT_APPRV_FLAG, &x25->flags);
    rc = 0;
}

release_sock(sk);
break;

author
#2 lore raw
Quoted 35 lines · Eric Dumazet
Quoted 21 lines · Dave Jones

Two of the x25 ioctl cases have error paths that break out of the function without unlocking the socket, leading to this warning:

================================================
[ BUG: lock held when returning to user space! ]
3.10.0-rc7+ #36 Not tainted
------------------------------------------------
trinity-child2/31407 is leaving the kernel with locks still held!
1 lock held by trinity-child2/31407:
#0: (sk_lock-AF_X25){+.+.+.}, at: [<ffffffffa024b6da>] x25_ioctl+0x8a/0x740 [x25]

net/x25/af_x25.c +0 -0
index 37ca969..2c1e633 100644
@@ -1584,10 +1584,11 @@ out_cud_release:
 		rc = -EINVAL;
 		lock_sock(sk);

net/x25/af_x25.c out_cud_release: · line 1593

Quoted 10 lines
net/x25/af_x25.c +3 -2
 		if (sk->sk_state != TCP_CLOSE)
-			break;
+			goto out_callaccpt_release;
 		clear_bit(X25_ACCPT_APPRV_FLAG, &x25->flags);
-		release_sock(sk);
 		rc = 0;
+out_callaccpt_release:
+		release_sock(sk);
 		break;
 	}

Or :

Quoted 7 lines

lock_sock(sk);

if (sk->sk_state == TCP_CLOSE) {
    clear_bit(X25_ACCPT_APPRV_FLAG, &x25->flags);
    rc = 0;
}

release_sock(sk);
break;

I can do that if it's preferred. I just copied the same style as the existing cases.

Dave

author
#3 lore raw
In reply to Dave Jones

Two of the x25 ioctl cases have error paths that break out of the function without unlocking the socket, leading to this warning:

================================================
[ BUG: lock held when returning to user space! ]
3.10.0-rc7+ #36 Not tainted
------------------------------------------------
trinity-child2/31407 is leaving the kernel with locks still held!
1 lock held by trinity-child2/31407:
#0: (sk_lock-AF_X25){+.+.+.}, at: [<ffffffffa024b6da>] x25_ioctl+0x8a/0x740 [x25]

net/x25/af_x25.c +8 -7
index 37ca969..22c88d2 100644
@@ -1583,11 +1583,11 @@ out_cud_release:
 	case SIOCX25CALLACCPTAPPRV: {
 		rc = -EINVAL;
 		lock_sock(sk);
-		if (sk->sk_state != TCP_CLOSE)
-			break;
-		clear_bit(X25_ACCPT_APPRV_FLAG, &x25->flags);
+		if (sk->sk_state == TCP_CLOSE) {
+			clear_bit(X25_ACCPT_APPRV_FLAG, &x25->flags);
+			rc = 0;
+		}
 		release_sock(sk);
-		rc = 0;
 		break;
 	}
 
@@ -1595,14 +1595,15 @@ out_cud_release:
 		rc = -EINVAL;
 		lock_sock(sk);
 		if (sk->sk_state != TCP_ESTABLISHED)
-			break;
+			goto out_sendcallaccpt_release;
 		/* must call accptapprv above */
 		if (test_bit(X25_ACCPT_APPRV_FLAG, &x25->flags))
-			break;
+			goto out_sendcallaccpt_release;
 		x25_write_internal(sk, X25_CALL_ACCEPTED);
 		x25->state = X25_STATE_3;
-		release_sock(sk);
 		rc = 0;
+out_sendcallaccpt_release:
+		release_sock(sk);
 		break;
 	}
 
maintainer
#4 lore raw

From: Dave Jones <[email protected]>
Date: Fri, 28 Jun 2013 12:13:52 -0400

Quoted 11 lines

Two of the x25 ioctl cases have error paths that break out of the function without unlocking the socket, leading to this warning:

================================================
[ BUG: lock held when returning to user space! ]
3.10.0-rc7+ #36 Not tainted
------------------------------------------------
trinity-child2/31407 is leaving the kernel with locks still held!
1 lock held by trinity-child2/31407:
#0: (sk_lock-AF_X25){+.+.+.}, at: [<ffffffffa024b6da>] x25_ioctl+0x8a/0x740 [x25]

Quoted 1 line

Applied and queued up for -stable, thanks Dave.

In the future please prefix your patch subject lines with "$subsystem: ", for this I rewrote it as:

x25: Fix broken locking in ioctl error paths.

Thanks!