Skip to content

Commit de6dfce

Browse files
diandersVudentz
authored andcommitted
Bluetooth: hci_sync: Avoid use-after-free in dbg for hci_remove_adv_monitor()
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: 7cf5c29 ("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>
1 parent 6910e2e commit de6dfce

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

net/bluetooth/hci_core.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1972,6 +1972,7 @@ static int hci_remove_adv_monitor(struct hci_dev *hdev,
19721972
struct adv_monitor *monitor)
19731973
{
19741974
int status = 0;
1975+
int handle;
19751976

19761977
switch (hci_get_adv_monitor_offload_ext(hdev)) {
19771978
case HCI_ADV_MONITOR_EXT_NONE: /* also goes here when powered off */
@@ -1980,9 +1981,10 @@ static int hci_remove_adv_monitor(struct hci_dev *hdev,
19801981
goto free_monitor;
19811982

19821983
case HCI_ADV_MONITOR_EXT_MSFT:
1984+
handle = monitor->handle;
19831985
status = msft_remove_monitor(hdev, monitor);
19841986
bt_dev_dbg(hdev, "%s remove monitor %d msft status %d",
1985-
hdev->name, monitor->handle, status);
1987+
hdev->name, handle, status);
19861988
break;
19871989
}
19881990

0 commit comments

Comments
 (0)