Skip to content

Commit 10f9f42

Browse files
swkim101Vudentz
authored andcommitted
Bluetooth: msft: fix slab-use-after-free in msft_do_close()
Tying the msft->data lifetime to hdev by freeing it in hci_release_dev() to fix the following case: [use] msft_do_close() msft = hdev->msft_data; if (!msft) ...(1) <- passed. return; mutex_lock(&msft->filter_lock); ...(4) <- used after freed. [free] msft_unregister() msft = hdev->msft_data; hdev->msft_data = NULL; ...(2) kfree(msft); ...(3) <- msft is freed. ================================================================== BUG: KASAN: slab-use-after-free in __mutex_lock_common kernel/locking/mutex.c:587 [inline] BUG: KASAN: slab-use-after-free in __mutex_lock+0x8f/0xc30 kernel/locking/mutex.c:752 Read of size 8 at addr ffff888106cbbca8 by task kworker/u5:2/309 Fixes: bf6a4e3 ("Bluetooth: disable advertisement filters during suspend") Signed-off-by: Sungwoo Kim <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 4d7b41c commit 10f9f42

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

net/bluetooth/hci_core.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2768,8 +2768,6 @@ void hci_unregister_dev(struct hci_dev *hdev)
27682768

27692769
hci_unregister_suspend_notifier(hdev);
27702770

2771-
msft_unregister(hdev);
2772-
27732771
hci_dev_do_close(hdev);
27742772

27752773
if (!test_bit(HCI_INIT, &hdev->flags) &&
@@ -2823,6 +2821,7 @@ void hci_release_dev(struct hci_dev *hdev)
28232821
hci_discovery_filter_clear(hdev);
28242822
hci_blocked_keys_clear(hdev);
28252823
hci_codec_list_clear(&hdev->local_codecs);
2824+
msft_release(hdev);
28262825
hci_dev_unlock(hdev);
28272826

28282827
ida_destroy(&hdev->unset_handle_ida);

net/bluetooth/msft.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ void msft_register(struct hci_dev *hdev)
769769
mutex_init(&msft->filter_lock);
770770
}
771771

772-
void msft_unregister(struct hci_dev *hdev)
772+
void msft_release(struct hci_dev *hdev)
773773
{
774774
struct msft_data *msft = hdev->msft_data;
775775

net/bluetooth/msft.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
bool msft_monitor_supported(struct hci_dev *hdev);
1616
void msft_register(struct hci_dev *hdev);
17-
void msft_unregister(struct hci_dev *hdev);
17+
void msft_release(struct hci_dev *hdev);
1818
void msft_do_open(struct hci_dev *hdev);
1919
void msft_do_close(struct hci_dev *hdev);
2020
void msft_vendor_evt(struct hci_dev *hdev, void *data, struct sk_buff *skb);
@@ -35,7 +35,7 @@ static inline bool msft_monitor_supported(struct hci_dev *hdev)
3535
}
3636

3737
static inline void msft_register(struct hci_dev *hdev) {}
38-
static inline void msft_unregister(struct hci_dev *hdev) {}
38+
static inline void msft_release(struct hci_dev *hdev) {}
3939
static inline void msft_do_open(struct hci_dev *hdev) {}
4040
static inline void msft_do_close(struct hci_dev *hdev) {}
4141
static inline void msft_vendor_evt(struct hci_dev *hdev, void *data,

0 commit comments

Comments
 (0)