Bluetooth: clear the temporary linkkey in hci_conn_cleanup
authorAlain Michaud <alainm@chromium.org>
Thu, 2 Jun 2022 15:30:03 +0000 (15:30 +0000)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Fri, 22 Jul 2022 00:04:53 +0000 (17:04 -0700)
If a hardware error occurs and the connections are flushed without a
disconnection_complete event being signaled, the temporary linkkeys are
not flushed.

This change ensures that any outstanding flushable linkkeys are flushed
when the connection are flushed from the hash table.

Additionally, this also makes use of test_and_clear_bit to avoid
multiple attempts to delete the link key that's already been flushed.

Signed-off-by: Alain Michaud <alainm@chromium.org>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
net/bluetooth/hci_conn.c
net/bluetooth/hci_event.c

index ac06c9724c7f30d7e0086e3827c7dd0e4f96a86f..7829433d54c158a8dd39d852b10ddbfe01e4bdaf 100644 (file)
@@ -118,6 +118,9 @@ static void hci_conn_cleanup(struct hci_conn *conn)
        if (test_bit(HCI_CONN_PARAM_REMOVAL_PEND, &conn->flags))
                hci_conn_params_del(conn->hdev, &conn->dst, conn->dst_type);
 
+       if (test_and_clear_bit(HCI_CONN_FLUSH_KEY, &conn->flags))
+               hci_remove_link_key(hdev, &conn->dst);
+
        hci_chan_list_flush(conn);
 
        hci_conn_hash_del(hdev, conn);
index af17dfb20e017da679b94591c917d1e71382ced1..63585c0bb9ceeb22b48a8e8bab7cb75e5cdca5ea 100644 (file)
@@ -2741,7 +2741,7 @@ static void hci_cs_disconnect(struct hci_dev *hdev, u8 status)
        mgmt_conn = test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags);
 
        if (conn->type == ACL_LINK) {
-               if (test_bit(HCI_CONN_FLUSH_KEY, &conn->flags))
+               if (test_and_clear_bit(HCI_CONN_FLUSH_KEY, &conn->flags))
                        hci_remove_link_key(hdev, &conn->dst);
        }
 
@@ -3368,7 +3368,7 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, void *data,
                                reason, mgmt_connected);
 
        if (conn->type == ACL_LINK) {
-               if (test_bit(HCI_CONN_FLUSH_KEY, &conn->flags))
+               if (test_and_clear_bit(HCI_CONN_FLUSH_KEY, &conn->flags))
                        hci_remove_link_key(hdev, &conn->dst);
 
                hci_req_update_scan(hdev);