Skip to content

Commit 27bcc05

Browse files
committed
Merge tag 'for-net-2025-11-11' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth
Luiz Augusto von Dentz says: ==================== bluetooth pull request for net: - hci_conn: Fix not cleaning up PA_LINK connections - hci_event: Fix not handling PA Sync Lost event - MGMT: cancel mesh send timer when hdev removed - 6lowpan: reset link-local header on ipv6 recv path - 6lowpan: fix BDADDR_LE vs ADDR_LE_DEV address type confusion - L2CAP: export l2cap_chan_hold for modules - 6lowpan: Don't hold spin lock over sleeping functions - 6lowpan: add missing l2cap_chan_lock() - btusb: reorder cleanup in btusb_disconnect to avoid UAF - btrtl: Avoid loading the config file on security chips * tag 'for-net-2025-11-11' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth: Bluetooth: btrtl: Avoid loading the config file on security chips Bluetooth: hci_event: Fix not handling PA Sync Lost event Bluetooth: hci_conn: Fix not cleaning up PA_LINK connections Bluetooth: 6lowpan: add missing l2cap_chan_lock() Bluetooth: 6lowpan: Don't hold spin lock over sleeping functions Bluetooth: L2CAP: export l2cap_chan_hold for modules Bluetooth: 6lowpan: fix BDADDR_LE vs ADDR_LE_DEV address type confusion Bluetooth: 6lowpan: reset link-local header on ipv6 recv path Bluetooth: btusb: reorder cleanup in btusb_disconnect to avoid UAF Bluetooth: MGMT: cancel mesh send timer when hdev removed ==================== Link: https://patch.msgid.link/20251111141357.1983153-1-luiz.dentz@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents bb8336a + cd8dbd9 commit 27bcc05

9 files changed

Lines changed: 158 additions & 82 deletions

File tree

drivers/bluetooth/btrtl.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
#define RTL_CHIP_SUBVER (&(struct rtl_vendor_cmd) {{0x10, 0x38, 0x04, 0x28, 0x80}})
5252
#define RTL_CHIP_REV (&(struct rtl_vendor_cmd) {{0x10, 0x3A, 0x04, 0x28, 0x80}})
53-
#define RTL_SEC_PROJ (&(struct rtl_vendor_cmd) {{0x10, 0xA4, 0x0D, 0x00, 0xb0}})
53+
#define RTL_SEC_PROJ (&(struct rtl_vendor_cmd) {{0x10, 0xA4, 0xAD, 0x00, 0xb0}})
5454

5555
#define RTL_PATCH_SNIPPETS 0x01
5656
#define RTL_PATCH_DUMMY_HEADER 0x02
@@ -534,7 +534,6 @@ static int rtlbt_parse_firmware_v2(struct hci_dev *hdev,
534534
{
535535
struct rtl_epatch_header_v2 *hdr;
536536
int rc;
537-
u8 reg_val[2];
538537
u8 key_id;
539538
u32 num_sections;
540539
struct rtl_section *section;
@@ -549,14 +548,7 @@ static int rtlbt_parse_firmware_v2(struct hci_dev *hdev,
549548
.len = btrtl_dev->fw_len - 7, /* Cut the tail */
550549
};
551550

552-
rc = btrtl_vendor_read_reg16(hdev, RTL_SEC_PROJ, reg_val);
553-
if (rc < 0)
554-
return -EIO;
555-
key_id = reg_val[0];
556-
557-
rtl_dev_dbg(hdev, "%s: key id %u", __func__, key_id);
558-
559-
btrtl_dev->key_id = key_id;
551+
key_id = btrtl_dev->key_id;
560552

561553
hdr = rtl_iov_pull_data(&iov, sizeof(*hdr));
562554
if (!hdr)
@@ -1070,6 +1062,8 @@ struct btrtl_device_info *btrtl_initialize(struct hci_dev *hdev,
10701062
u16 hci_rev, lmp_subver;
10711063
u8 hci_ver, lmp_ver, chip_type = 0;
10721064
int ret;
1065+
int rc;
1066+
u8 key_id;
10731067
u8 reg_val[2];
10741068

10751069
btrtl_dev = kzalloc(sizeof(*btrtl_dev), GFP_KERNEL);
@@ -1180,6 +1174,14 @@ struct btrtl_device_info *btrtl_initialize(struct hci_dev *hdev,
11801174
goto err_free;
11811175
}
11821176

1177+
rc = btrtl_vendor_read_reg16(hdev, RTL_SEC_PROJ, reg_val);
1178+
if (rc < 0)
1179+
goto err_free;
1180+
1181+
key_id = reg_val[0];
1182+
btrtl_dev->key_id = key_id;
1183+
rtl_dev_info(hdev, "%s: key id %u", __func__, key_id);
1184+
11831185
btrtl_dev->fw_len = -EIO;
11841186
if (lmp_subver == RTL_ROM_LMP_8852A && hci_rev == 0x000c) {
11851187
snprintf(fw_name, sizeof(fw_name), "%s_v2.bin",
@@ -1202,7 +1204,7 @@ struct btrtl_device_info *btrtl_initialize(struct hci_dev *hdev,
12021204
goto err_free;
12031205
}
12041206

1205-
if (btrtl_dev->ic_info->cfg_name) {
1207+
if (btrtl_dev->ic_info->cfg_name && !btrtl_dev->key_id) {
12061208
if (postfix) {
12071209
snprintf(cfg_name, sizeof(cfg_name), "%s-%s.bin",
12081210
btrtl_dev->ic_info->cfg_name, postfix);

drivers/bluetooth/btusb.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4361,6 +4361,11 @@ static void btusb_disconnect(struct usb_interface *intf)
43614361

43624362
hci_unregister_dev(hdev);
43634363

4364+
if (data->oob_wake_irq)
4365+
device_init_wakeup(&data->udev->dev, false);
4366+
if (data->reset_gpio)
4367+
gpiod_put(data->reset_gpio);
4368+
43644369
if (intf == data->intf) {
43654370
if (data->isoc)
43664371
usb_driver_release_interface(&btusb_driver, data->isoc);
@@ -4371,17 +4376,11 @@ static void btusb_disconnect(struct usb_interface *intf)
43714376
usb_driver_release_interface(&btusb_driver, data->diag);
43724377
usb_driver_release_interface(&btusb_driver, data->intf);
43734378
} else if (intf == data->diag) {
4374-
usb_driver_release_interface(&btusb_driver, data->intf);
43754379
if (data->isoc)
43764380
usb_driver_release_interface(&btusb_driver, data->isoc);
4381+
usb_driver_release_interface(&btusb_driver, data->intf);
43774382
}
43784383

4379-
if (data->oob_wake_irq)
4380-
device_init_wakeup(&data->udev->dev, false);
4381-
4382-
if (data->reset_gpio)
4383-
gpiod_put(data->reset_gpio);
4384-
43854384
hci_free_dev(hdev);
43864385
}
43874386

include/net/bluetooth/hci.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2783,6 +2783,11 @@ struct hci_ev_le_per_adv_report {
27832783
__u8 data[];
27842784
} __packed;
27852785

2786+
#define HCI_EV_LE_PA_SYNC_LOST 0x10
2787+
struct hci_ev_le_pa_sync_lost {
2788+
__le16 handle;
2789+
} __packed;
2790+
27862791
#define LE_PA_DATA_COMPLETE 0x00
27872792
#define LE_PA_DATA_MORE_TO_COME 0x01
27882793
#define LE_PA_DATA_TRUNCATED 0x02

net/bluetooth/6lowpan.c

Lines changed: 76 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ static bool enable_6lowpan;
5353
static struct l2cap_chan *listen_chan;
5454
static DEFINE_MUTEX(set_lock);
5555

56+
enum {
57+
LOWPAN_PEER_CLOSING,
58+
LOWPAN_PEER_MAXBITS
59+
};
60+
5661
struct lowpan_peer {
5762
struct list_head list;
5863
struct rcu_head rcu;
@@ -61,6 +66,8 @@ struct lowpan_peer {
6166
/* peer addresses in various formats */
6267
unsigned char lladdr[ETH_ALEN];
6368
struct in6_addr peer_addr;
69+
70+
DECLARE_BITMAP(flags, LOWPAN_PEER_MAXBITS);
6471
};
6572

6673
struct lowpan_btle_dev {
@@ -289,6 +296,7 @@ static int recv_pkt(struct sk_buff *skb, struct net_device *dev,
289296
local_skb->pkt_type = PACKET_HOST;
290297
local_skb->dev = dev;
291298

299+
skb_reset_mac_header(local_skb);
292300
skb_set_transport_header(local_skb, sizeof(struct ipv6hdr));
293301

294302
if (give_skb_to_upper(local_skb, dev) != NET_RX_SUCCESS) {
@@ -919,7 +927,9 @@ static int bt_6lowpan_disconnect(struct l2cap_conn *conn, u8 dst_type)
919927

920928
BT_DBG("peer %p chan %p", peer, peer->chan);
921929

930+
l2cap_chan_lock(peer->chan);
922931
l2cap_chan_close(peer->chan, ENOENT);
932+
l2cap_chan_unlock(peer->chan);
923933

924934
return 0;
925935
}
@@ -956,10 +966,11 @@ static struct l2cap_chan *bt_6lowpan_listen(void)
956966
}
957967

958968
static int get_l2cap_conn(char *buf, bdaddr_t *addr, u8 *addr_type,
959-
struct l2cap_conn **conn)
969+
struct l2cap_conn **conn, bool disconnect)
960970
{
961971
struct hci_conn *hcon;
962972
struct hci_dev *hdev;
973+
int le_addr_type;
963974
int n;
964975

965976
n = sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx %hhu",
@@ -970,13 +981,32 @@ static int get_l2cap_conn(char *buf, bdaddr_t *addr, u8 *addr_type,
970981
if (n < 7)
971982
return -EINVAL;
972983

984+
if (disconnect) {
985+
/* The "disconnect" debugfs command has used different address
986+
* type constants than "connect" since 2015. Let's retain that
987+
* for now even though it's obviously buggy...
988+
*/
989+
*addr_type += 1;
990+
}
991+
992+
switch (*addr_type) {
993+
case BDADDR_LE_PUBLIC:
994+
le_addr_type = ADDR_LE_DEV_PUBLIC;
995+
break;
996+
case BDADDR_LE_RANDOM:
997+
le_addr_type = ADDR_LE_DEV_RANDOM;
998+
break;
999+
default:
1000+
return -EINVAL;
1001+
}
1002+
9731003
/* The LE_PUBLIC address type is ignored because of BDADDR_ANY */
9741004
hdev = hci_get_route(addr, BDADDR_ANY, BDADDR_LE_PUBLIC);
9751005
if (!hdev)
9761006
return -ENOENT;
9771007

9781008
hci_dev_lock(hdev);
979-
hcon = hci_conn_hash_lookup_le(hdev, addr, *addr_type);
1009+
hcon = hci_conn_hash_lookup_le(hdev, addr, le_addr_type);
9801010
hci_dev_unlock(hdev);
9811011
hci_dev_put(hdev);
9821012

@@ -993,41 +1023,52 @@ static int get_l2cap_conn(char *buf, bdaddr_t *addr, u8 *addr_type,
9931023
static void disconnect_all_peers(void)
9941024
{
9951025
struct lowpan_btle_dev *entry;
996-
struct lowpan_peer *peer, *tmp_peer, *new_peer;
997-
struct list_head peers;
998-
999-
INIT_LIST_HEAD(&peers);
1026+
struct lowpan_peer *peer;
1027+
int nchans;
10001028

1001-
/* We make a separate list of peers as the close_cb() will
1002-
* modify the device peers list so it is better not to mess
1003-
* with the same list at the same time.
1029+
/* l2cap_chan_close() cannot be called from RCU, and lock ordering
1030+
* chan->lock > devices_lock prevents taking write side lock, so copy
1031+
* then close.
10041032
*/
10051033

10061034
rcu_read_lock();
1035+
list_for_each_entry_rcu(entry, &bt_6lowpan_devices, list)
1036+
list_for_each_entry_rcu(peer, &entry->peers, list)
1037+
clear_bit(LOWPAN_PEER_CLOSING, peer->flags);
1038+
rcu_read_unlock();
10071039

1008-
list_for_each_entry_rcu(entry, &bt_6lowpan_devices, list) {
1009-
list_for_each_entry_rcu(peer, &entry->peers, list) {
1010-
new_peer = kmalloc(sizeof(*new_peer), GFP_ATOMIC);
1011-
if (!new_peer)
1012-
break;
1040+
do {
1041+
struct l2cap_chan *chans[32];
1042+
int i;
10131043

1014-
new_peer->chan = peer->chan;
1015-
INIT_LIST_HEAD(&new_peer->list);
1044+
nchans = 0;
10161045

1017-
list_add(&new_peer->list, &peers);
1018-
}
1019-
}
1046+
spin_lock(&devices_lock);
10201047

1021-
rcu_read_unlock();
1048+
list_for_each_entry_rcu(entry, &bt_6lowpan_devices, list) {
1049+
list_for_each_entry_rcu(peer, &entry->peers, list) {
1050+
if (test_and_set_bit(LOWPAN_PEER_CLOSING,
1051+
peer->flags))
1052+
continue;
10221053

1023-
spin_lock(&devices_lock);
1024-
list_for_each_entry_safe(peer, tmp_peer, &peers, list) {
1025-
l2cap_chan_close(peer->chan, ENOENT);
1054+
l2cap_chan_hold(peer->chan);
1055+
chans[nchans++] = peer->chan;
10261056

1027-
list_del_rcu(&peer->list);
1028-
kfree_rcu(peer, rcu);
1029-
}
1030-
spin_unlock(&devices_lock);
1057+
if (nchans >= ARRAY_SIZE(chans))
1058+
goto done;
1059+
}
1060+
}
1061+
1062+
done:
1063+
spin_unlock(&devices_lock);
1064+
1065+
for (i = 0; i < nchans; ++i) {
1066+
l2cap_chan_lock(chans[i]);
1067+
l2cap_chan_close(chans[i], ENOENT);
1068+
l2cap_chan_unlock(chans[i]);
1069+
l2cap_chan_put(chans[i]);
1070+
}
1071+
} while (nchans);
10311072
}
10321073

10331074
struct set_enable {
@@ -1050,7 +1091,9 @@ static void do_enable_set(struct work_struct *work)
10501091

10511092
mutex_lock(&set_lock);
10521093
if (listen_chan) {
1094+
l2cap_chan_lock(listen_chan);
10531095
l2cap_chan_close(listen_chan, 0);
1096+
l2cap_chan_unlock(listen_chan);
10541097
l2cap_chan_put(listen_chan);
10551098
}
10561099

@@ -1103,13 +1146,15 @@ static ssize_t lowpan_control_write(struct file *fp,
11031146
buf[buf_size] = '\0';
11041147

11051148
if (memcmp(buf, "connect ", 8) == 0) {
1106-
ret = get_l2cap_conn(&buf[8], &addr, &addr_type, &conn);
1149+
ret = get_l2cap_conn(&buf[8], &addr, &addr_type, &conn, false);
11071150
if (ret == -EINVAL)
11081151
return ret;
11091152

11101153
mutex_lock(&set_lock);
11111154
if (listen_chan) {
1155+
l2cap_chan_lock(listen_chan);
11121156
l2cap_chan_close(listen_chan, 0);
1157+
l2cap_chan_unlock(listen_chan);
11131158
l2cap_chan_put(listen_chan);
11141159
listen_chan = NULL;
11151160
}
@@ -1140,7 +1185,7 @@ static ssize_t lowpan_control_write(struct file *fp,
11401185
}
11411186

11421187
if (memcmp(buf, "disconnect ", 11) == 0) {
1143-
ret = get_l2cap_conn(&buf[11], &addr, &addr_type, &conn);
1188+
ret = get_l2cap_conn(&buf[11], &addr, &addr_type, &conn, true);
11441189
if (ret < 0)
11451190
return ret;
11461191

@@ -1271,7 +1316,9 @@ static void __exit bt_6lowpan_exit(void)
12711316
debugfs_remove(lowpan_control_debugfs);
12721317

12731318
if (listen_chan) {
1319+
l2cap_chan_lock(listen_chan);
12741320
l2cap_chan_close(listen_chan, 0);
1321+
l2cap_chan_unlock(listen_chan);
12751322
l2cap_chan_put(listen_chan);
12761323
}
12771324

net/bluetooth/hci_conn.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -769,21 +769,23 @@ static void find_bis(struct hci_conn *conn, void *data)
769769
d->count++;
770770
}
771771

772-
static int hci_le_big_terminate(struct hci_dev *hdev, u8 big, struct hci_conn *conn)
772+
static int hci_le_big_terminate(struct hci_dev *hdev, struct hci_conn *conn)
773773
{
774774
struct iso_list_data *d;
775775
int ret;
776776

777-
bt_dev_dbg(hdev, "big 0x%2.2x sync_handle 0x%4.4x", big, conn->sync_handle);
777+
bt_dev_dbg(hdev, "hcon %p big 0x%2.2x sync_handle 0x%4.4x", conn,
778+
conn->iso_qos.bcast.big, conn->sync_handle);
778779

779780
d = kzalloc(sizeof(*d), GFP_KERNEL);
780781
if (!d)
781782
return -ENOMEM;
782783

783-
d->big = big;
784+
d->big = conn->iso_qos.bcast.big;
784785
d->sync_handle = conn->sync_handle;
785786

786-
if (test_and_clear_bit(HCI_CONN_PA_SYNC, &conn->flags)) {
787+
if (conn->type == PA_LINK &&
788+
test_and_clear_bit(HCI_CONN_PA_SYNC, &conn->flags)) {
787789
hci_conn_hash_list_flag(hdev, find_bis, PA_LINK,
788790
HCI_CONN_PA_SYNC, d);
789791

@@ -801,6 +803,9 @@ static int hci_le_big_terminate(struct hci_dev *hdev, u8 big, struct hci_conn *c
801803
d->big_sync_term = true;
802804
}
803805

806+
if (!d->pa_sync_term && !d->big_sync_term)
807+
return 0;
808+
804809
ret = hci_cmd_sync_queue(hdev, big_terminate_sync, d,
805810
terminate_big_destroy);
806811
if (ret)
@@ -852,8 +857,7 @@ static void bis_cleanup(struct hci_conn *conn)
852857

853858
hci_le_terminate_big(hdev, conn);
854859
} else {
855-
hci_le_big_terminate(hdev, conn->iso_qos.bcast.big,
856-
conn);
860+
hci_le_big_terminate(hdev, conn);
857861
}
858862
}
859863

@@ -994,19 +998,20 @@ static struct hci_conn *__hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t
994998
conn->mtu = hdev->le_mtu ? hdev->le_mtu : hdev->acl_mtu;
995999
break;
9961000
case CIS_LINK:
997-
case BIS_LINK:
998-
case PA_LINK:
9991001
/* conn->src should reflect the local identity address */
10001002
hci_copy_identity_address(hdev, &conn->src, &conn->src_type);
10011003

1002-
/* set proper cleanup function */
1003-
if (!bacmp(dst, BDADDR_ANY))
1004-
conn->cleanup = bis_cleanup;
1005-
else if (conn->role == HCI_ROLE_MASTER)
1004+
if (conn->role == HCI_ROLE_MASTER)
10061005
conn->cleanup = cis_cleanup;
10071006

1008-
conn->mtu = hdev->iso_mtu ? hdev->iso_mtu :
1009-
hdev->le_mtu ? hdev->le_mtu : hdev->acl_mtu;
1007+
conn->mtu = hdev->iso_mtu;
1008+
break;
1009+
case PA_LINK:
1010+
case BIS_LINK:
1011+
/* conn->src should reflect the local identity address */
1012+
hci_copy_identity_address(hdev, &conn->src, &conn->src_type);
1013+
conn->cleanup = bis_cleanup;
1014+
conn->mtu = hdev->iso_mtu;
10101015
break;
10111016
case SCO_LINK:
10121017
if (lmp_esco_capable(hdev))

0 commit comments

Comments
 (0)