diff options
author | Dean Jenkins <Dean_Jenkins@mentor.com> | 2015-06-23 12:59:39 -0400 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2015-07-23 11:10:51 -0400 |
commit | e432c72c464d2deb6c66d1e2a5f548dc1f0ef4dc (patch) | |
tree | 1206dfbdbb74bf9b5ffa8bf9999b824761cea681 /net/bluetooth/l2cap_sock.c | |
parent | cb02a25583b59ce48267472cd092485d754964f9 (diff) |
Bluetooth: __l2cap_wait_ack() add defensive timeout
Add a timeout to prevent the do while loop running in an
infinite loop. This ensures that the channel will be
instructed to close within 10 seconds so prevents
l2cap_sock_shutdown() getting stuck forever.
Returns -ENOLINK when the timeout is reached. The channel
will be subequently closed and not all data will be ACK'ed.
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.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index f0b052a75e8a..586b3d580cfc 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c | |||
@@ -1059,11 +1059,15 @@ static int __l2cap_wait_ack(struct sock *sk, struct l2cap_chan *chan) | |||
1059 | DECLARE_WAITQUEUE(wait, current); | 1059 | DECLARE_WAITQUEUE(wait, current); |
1060 | int err = 0; | 1060 | int err = 0; |
1061 | int timeo = L2CAP_WAIT_ACK_POLL_PERIOD; | 1061 | int timeo = L2CAP_WAIT_ACK_POLL_PERIOD; |
1062 | /* Timeout to prevent infinite loop */ | ||
1063 | unsigned long timeout = jiffies + L2CAP_WAIT_ACK_TIMEOUT; | ||
1062 | 1064 | ||
1063 | add_wait_queue(sk_sleep(sk), &wait); | 1065 | add_wait_queue(sk_sleep(sk), &wait); |
1064 | set_current_state(TASK_INTERRUPTIBLE); | 1066 | set_current_state(TASK_INTERRUPTIBLE); |
1065 | do { | 1067 | do { |
1066 | BT_DBG("Waiting for %d ACKs", chan->unacked_frames); | 1068 | BT_DBG("Waiting for %d ACKs, timeout %04d ms", |
1069 | chan->unacked_frames, time_after(jiffies, timeout) ? 0 : | ||
1070 | jiffies_to_msecs(timeout - jiffies)); | ||
1067 | 1071 | ||
1068 | if (!timeo) | 1072 | if (!timeo) |
1069 | timeo = L2CAP_WAIT_ACK_POLL_PERIOD; | 1073 | timeo = L2CAP_WAIT_ACK_POLL_PERIOD; |
@@ -1082,6 +1086,11 @@ static int __l2cap_wait_ack(struct sock *sk, struct l2cap_chan *chan) | |||
1082 | if (err) | 1086 | if (err) |
1083 | break; | 1087 | break; |
1084 | 1088 | ||
1089 | if (time_after(jiffies, timeout)) { | ||
1090 | err = -ENOLINK; | ||
1091 | break; | ||
1092 | } | ||
1093 | |||
1085 | } while (chan->unacked_frames > 0 && | 1094 | } while (chan->unacked_frames > 0 && |
1086 | chan->state == BT_CONNECTED); | 1095 | chan->state == BT_CONNECTED); |
1087 | 1096 | ||