Commit 49d8a560 authored by Desmond Cheong Zhi Xi's avatar Desmond Cheong Zhi Xi Committed by Luiz Augusto von Dentz

Bluetooth: fix init and cleanup of sco_conn.timeout_work

Before freeing struct sco_conn, all delayed timeout work should be
cancelled. Otherwise, sco_sock_timeout could potentially use the
sco_conn after it has been freed.

Additionally, sco_conn.timeout_work should be initialized when the
connection is allocated, not when the channel is added. This is
because an sco_conn can create channels with multiple sockets over its
lifetime, which happens if sockets are released but the connection
isn't deleted.

Fixes: ba316be1 ("Bluetooth: schedule SCO timeouts with delayed_work")
Signed-off-by: default avatarDesmond Cheong Zhi Xi <desmondcheongzx@gmail.com>
Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
parent f4712fa9
...@@ -133,6 +133,7 @@ static struct sco_conn *sco_conn_add(struct hci_conn *hcon) ...@@ -133,6 +133,7 @@ static struct sco_conn *sco_conn_add(struct hci_conn *hcon)
return NULL; return NULL;
spin_lock_init(&conn->lock); spin_lock_init(&conn->lock);
INIT_DELAYED_WORK(&conn->timeout_work, sco_sock_timeout);
hcon->sco_data = conn; hcon->sco_data = conn;
conn->hcon = hcon; conn->hcon = hcon;
...@@ -197,10 +198,10 @@ static void sco_conn_del(struct hci_conn *hcon, int err) ...@@ -197,10 +198,10 @@ static void sco_conn_del(struct hci_conn *hcon, int err)
sco_chan_del(sk, err); sco_chan_del(sk, err);
release_sock(sk); release_sock(sk);
sock_put(sk); sock_put(sk);
}
/* Ensure no more work items will run before freeing conn. */ /* Ensure no more work items will run before freeing conn. */
cancel_delayed_work_sync(&conn->timeout_work); cancel_delayed_work_sync(&conn->timeout_work);
}
hcon->sco_data = NULL; hcon->sco_data = NULL;
kfree(conn); kfree(conn);
...@@ -214,8 +215,6 @@ static void __sco_chan_add(struct sco_conn *conn, struct sock *sk, ...@@ -214,8 +215,6 @@ static void __sco_chan_add(struct sco_conn *conn, struct sock *sk,
sco_pi(sk)->conn = conn; sco_pi(sk)->conn = conn;
conn->sk = sk; conn->sk = sk;
INIT_DELAYED_WORK(&conn->timeout_work, sco_sock_timeout);
if (parent) if (parent)
bt_accept_enqueue(parent, sk, true); bt_accept_enqueue(parent, sk, true);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment