Bluetooth: hci_sync: Avoid use-after-free in dbg for hci_remove_adv_monitor()
authorDouglas Anderson <dianders@chromium.org>
Fri, 30 Jun 2023 22:33:14 +0000 (15:33 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 27 Jul 2023 06:50:47 +0000 (08:50 +0200)
commit0d4d6b083da9b033ddccef72d77f373c819ae3ea
tree154c2d62d5dc973f9294699cdf89583e6a5ec512
parente969bfed84c1f88dc722a678ee08488e86f0ec1a
Bluetooth: hci_sync: Avoid use-after-free in dbg for hci_remove_adv_monitor()

[ Upstream commit de6dfcefd107667ce2dbedf4d9337f5ed557a4a1 ]

KASAN reports that there's a use-after-free in
hci_remove_adv_monitor(). Trawling through the disassembly, you can
see that the complaint is from the access in bt_dev_dbg() under the
HCI_ADV_MONITOR_EXT_MSFT case. The problem case happens because
msft_remove_monitor() can end up freeing the monitor
structure. Specifically:
  hci_remove_adv_monitor() ->
  msft_remove_monitor() ->
  msft_remove_monitor_sync() ->
  msft_le_cancel_monitor_advertisement_cb() ->
  hci_free_adv_monitor()

Let's fix the problem by just stashing the relevant data when it's
still valid.

Fixes: 7cf5c2978f23 ("Bluetooth: hci_sync: Refactor remove Adv Monitor")
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/bluetooth/hci_core.c