aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth/l2cap_sock.c
diff options
context:
space:
mode:
authorDean Jenkins <Dean_Jenkins@mentor.com>2015-06-23 12:59:32 -0400
committerMarcel Holtmann <marcel@holtmann.org>2015-07-23 11:10:50 -0400
commit2baea85dec1aebe0b100d4836dee8bcf29a51e94 (patch)
tree4e64ae9832fb263dd317b89e424456a98838ff56 /net/bluetooth/l2cap_sock.c
parentd10270ce941ee89afd74076ea3ed8dbef8a0ff25 (diff)
Bluetooth: L2CAP ERTM shutdown protect sk and chan
During execution of l2cap_sock_shutdown() which might sleep, the sk and chan structures can be in an unlocked condition which potentially allows the structures to be freed by other running threads. Therefore, there is a possibility of a malfunction or memory reuse after being freed. Keep the sk and chan structures alive during the execution of l2cap_sock_shutdown() by using their respective hold and put functions. This allows the structures to be freeable at the end of l2cap_sock_shutdown(). Signed-off-by: Kautuk Consul <Kautuk_Consul@mentor.com> Signed-off-by: Dean Jenkins <Dean_Jenkins@mentor.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net/bluetooth/l2cap_sock.c')
-rw-r--r--net/bluetooth/l2cap_sock.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 244287706f91..3794c2386c21 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -1098,7 +1098,12 @@ static int l2cap_sock_shutdown(struct socket *sock, int how)
1098 if (!sk) 1098 if (!sk)
1099 return 0; 1099 return 0;
1100 1100
1101 /* prevent sk structure from being freed whilst unlocked */
1102 sock_hold(sk);
1103
1101 chan = l2cap_pi(sk)->chan; 1104 chan = l2cap_pi(sk)->chan;
1105 /* prevent chan structure from being freed whilst unlocked */
1106 l2cap_chan_hold(chan);
1102 conn = chan->conn; 1107 conn = chan->conn;
1103 1108
1104 BT_DBG("chan %p state %s", chan, state_to_string(chan->state)); 1109 BT_DBG("chan %p state %s", chan, state_to_string(chan->state));
@@ -1134,6 +1139,9 @@ static int l2cap_sock_shutdown(struct socket *sock, int how)
1134 if (conn) 1139 if (conn)
1135 mutex_unlock(&conn->chan_lock); 1140 mutex_unlock(&conn->chan_lock);
1136 1141
1142 l2cap_chan_put(chan);
1143 sock_put(sk);
1144
1137 return err; 1145 return err;
1138} 1146}
1139 1147