Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: ba316be1b6a0 ("Bluetooth: schedule SCO timeouts with delayed_work")
Signed-off-by: Desmond Cheong Zhi Xi <desmondcheongzx@gmail.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

authored by

Desmond Cheong Zhi Xi and committed by
Luiz Augusto von Dentz
49d8a560 f4712fa9

+4 -5
+4 -5
net/bluetooth/sco.c
··· 133 133 return NULL; 134 134 135 135 spin_lock_init(&conn->lock); 136 + INIT_DELAYED_WORK(&conn->timeout_work, sco_sock_timeout); 136 137 137 138 hcon->sco_data = conn; 138 139 conn->hcon = hcon; ··· 198 197 sco_chan_del(sk, err); 199 198 release_sock(sk); 200 199 sock_put(sk); 201 - 202 - /* Ensure no more work items will run before freeing conn. */ 203 - cancel_delayed_work_sync(&conn->timeout_work); 204 200 } 201 + 202 + /* Ensure no more work items will run before freeing conn. */ 203 + cancel_delayed_work_sync(&conn->timeout_work); 205 204 206 205 hcon->sco_data = NULL; 207 206 kfree(conn); ··· 214 213 215 214 sco_pi(sk)->conn = conn; 216 215 conn->sk = sk; 217 - 218 - INIT_DELAYED_WORK(&conn->timeout_work, sco_sock_timeout); 219 216 220 217 if (parent) 221 218 bt_accept_enqueue(parent, sk, true);