Bluetooth: call sock_hold earlier in sco_conn_del
authorDesmond Cheong Zhi Xi <desmondcheongzx@gmail.com>
Fri, 3 Sep 2021 03:13:05 +0000 (23:13 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 18 Nov 2021 18:16:09 +0000 (19:16 +0100)
commita05a18cfbf9f24fa1b23014eba3c544d6a8c8dec
treeabe0bc5ea349d642825ffe6139340f5b3477f804
parent7e22e4db95b04f09adcce18c75d27cbca8f53b99
Bluetooth: call sock_hold earlier in sco_conn_del

[ Upstream commit f4712fa993f688d0a48e0c28728fcdeb88c1ea58 ]

In sco_conn_del, conn->sk is read while holding on to the
sco_conn.lock to avoid races with a socket that could be released
concurrently.

However, in between unlocking sco_conn.lock and calling sock_hold,
it's possible for the socket to be freed, which would cause a
use-after-free write when sock_hold is finally called.

To fix this, the reference count of the socket should be increased
while the sco_conn.lock is still held.

Signed-off-by: Desmond Cheong Zhi Xi <desmondcheongzx@gmail.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/bluetooth/sco.c