Skip to content

Commit 8a72710

Browse files
committed
Merge tag 'for-net-2022-02-24' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth
Luiz Augusto von Dentz says: ==================== bluetooth pull request for net: - Fix regression with RFCOMM - Fix regression with LE devices using Privacy (RPA) - Fix regression with LE devices not waiting proper timeout to establish connections - Fix race in smp * tag 'for-net-2022-02-24' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth: Bluetooth: hci_sync: Fix not using conn_timeout Bluetooth: hci_sync: Fix hci_update_accept_list_sync Bluetooth: assign len after null check Bluetooth: Fix bt_skb_sendmmsg not allocating partial chunks Bluetooth: fix data races in smp_unregister(), smp_del_chan() Bluetooth: hci_core: Fix leaking sent_cmd skb ==================== Link: https://lore.kernel.org/r/20220224210838.197787-1-luiz.dentz@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents d8152cf + a56a113 commit 8a72710

File tree

5 files changed

+33
-12
lines changed

5 files changed

+33
-12
lines changed

include/net/bluetooth/bluetooth.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,7 @@ static inline struct sk_buff *bt_skb_sendmmsg(struct sock *sk,
506506

507507
tmp = bt_skb_sendmsg(sk, msg, len, mtu, headroom, tailroom);
508508
if (IS_ERR(tmp)) {
509-
kfree_skb(skb);
510-
return tmp;
509+
return skb;
511510
}
512511

513512
len -= tmp->len;

include/net/bluetooth/hci_core.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,14 @@ void hci_conn_del_sysfs(struct hci_conn *conn);
14891489
/* Extended advertising support */
14901490
#define ext_adv_capable(dev) (((dev)->le_features[1] & HCI_LE_EXT_ADV))
14911491

1492+
/* BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 4, Part E page 1789:
1493+
*
1494+
* C24: Mandatory if the LE Controller supports Connection State and either
1495+
* LE Feature (LL Privacy) or LE Feature (Extended Advertising) is supported
1496+
*/
1497+
#define use_enhanced_conn_complete(dev) (ll_privacy_capable(dev) || \
1498+
ext_adv_capable(dev))
1499+
14921500
/* ----- HCI protocols ----- */
14931501
#define HCI_PROTO_DEFER 0x01
14941502

net/bluetooth/hci_core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,6 +2738,7 @@ void hci_release_dev(struct hci_dev *hdev)
27382738
hci_dev_unlock(hdev);
27392739

27402740
ida_simple_remove(&hci_index_ida, hdev->id);
2741+
kfree_skb(hdev->sent_cmd);
27412742
kfree(hdev);
27422743
}
27432744
EXPORT_SYMBOL(hci_release_dev);

net/bluetooth/hci_sync.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,6 +1841,7 @@ static u8 hci_update_accept_list_sync(struct hci_dev *hdev)
18411841
struct bdaddr_list *b, *t;
18421842
u8 num_entries = 0;
18431843
bool pend_conn, pend_report;
1844+
u8 filter_policy;
18441845
int err;
18451846

18461847
/* Pause advertising if resolving list can be used as controllers are
@@ -1927,6 +1928,8 @@ static u8 hci_update_accept_list_sync(struct hci_dev *hdev)
19271928
err = -EINVAL;
19281929

19291930
done:
1931+
filter_policy = err ? 0x00 : 0x01;
1932+
19301933
/* Enable address resolution when LL Privacy is enabled. */
19311934
err = hci_le_set_addr_resolution_enable_sync(hdev, 0x01);
19321935
if (err)
@@ -1937,7 +1940,7 @@ static u8 hci_update_accept_list_sync(struct hci_dev *hdev)
19371940
hci_resume_advertising_sync(hdev);
19381941

19391942
/* Select filter policy to use accept list */
1940-
return err ? 0x00 : 0x01;
1943+
return filter_policy;
19411944
}
19421945

19431946
/* Returns true if an le connection is in the scanning state */
@@ -3262,10 +3265,10 @@ static int hci_le_set_event_mask_sync(struct hci_dev *hdev)
32623265
if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT)
32633266
events[0] |= 0x40; /* LE Data Length Change */
32643267

3265-
/* If the controller supports LL Privacy feature, enable
3266-
* the corresponding event.
3268+
/* If the controller supports LL Privacy feature or LE Extended Adv,
3269+
* enable the corresponding event.
32673270
*/
3268-
if (hdev->le_features[0] & HCI_LE_LL_PRIVACY)
3271+
if (use_enhanced_conn_complete(hdev))
32693272
events[1] |= 0x02; /* LE Enhanced Connection Complete */
32703273

32713274
/* If the controller supports Extended Scanner Filter
@@ -4106,9 +4109,9 @@ int hci_dev_close_sync(struct hci_dev *hdev)
41064109
hci_inquiry_cache_flush(hdev);
41074110
hci_pend_le_actions_clear(hdev);
41084111
hci_conn_hash_flush(hdev);
4109-
hci_dev_unlock(hdev);
4110-
4112+
/* Prevent data races on hdev->smp_data or hdev->smp_bredr_data */
41114113
smp_unregister(hdev);
4114+
hci_dev_unlock(hdev);
41124115

41134116
hci_sock_dev_event(hdev, HCI_DEV_DOWN);
41144117

@@ -5185,7 +5188,7 @@ int hci_le_ext_create_conn_sync(struct hci_dev *hdev, struct hci_conn *conn,
51855188
return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_EXT_CREATE_CONN,
51865189
plen, data,
51875190
HCI_EV_LE_ENHANCED_CONN_COMPLETE,
5188-
HCI_CMD_TIMEOUT, NULL);
5191+
conn->conn_timeout, NULL);
51895192
}
51905193

51915194
int hci_le_create_conn_sync(struct hci_dev *hdev, struct hci_conn *conn)
@@ -5270,9 +5273,18 @@ int hci_le_create_conn_sync(struct hci_dev *hdev, struct hci_conn *conn)
52705273
cp.min_ce_len = cpu_to_le16(0x0000);
52715274
cp.max_ce_len = cpu_to_le16(0x0000);
52725275

5276+
/* BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 4, Part E page 2261:
5277+
*
5278+
* If this event is unmasked and the HCI_LE_Connection_Complete event
5279+
* is unmasked, only the HCI_LE_Enhanced_Connection_Complete event is
5280+
* sent when a new connection has been created.
5281+
*/
52735282
err = __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_CREATE_CONN,
5274-
sizeof(cp), &cp, HCI_EV_LE_CONN_COMPLETE,
5275-
HCI_CMD_TIMEOUT, NULL);
5283+
sizeof(cp), &cp,
5284+
use_enhanced_conn_complete(hdev) ?
5285+
HCI_EV_LE_ENHANCED_CONN_COMPLETE :
5286+
HCI_EV_LE_CONN_COMPLETE,
5287+
conn->conn_timeout, NULL);
52765288

52775289
done:
52785290
/* Re-enable advertising after the connection attempt is finished. */

net/bluetooth/mgmt_util.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,12 @@ int mgmt_send_event_skb(unsigned short channel, struct sk_buff *skb, int flag,
7777
{
7878
struct hci_dev *hdev;
7979
struct mgmt_hdr *hdr;
80-
int len = skb->len;
80+
int len;
8181

8282
if (!skb)
8383
return -EINVAL;
8484

85+
len = skb->len;
8586
hdev = bt_cb(skb)->mgmt.hdev;
8687

8788
/* Time stamp */

0 commit comments

Comments
 (0)