Skip to content

Commit 2b10740

Browse files
committed
Merge tag 'for-net-2023-10-13' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth
Luiz Augusto von Dentz says: ==================== bluetooth pull request for net: - Fix race when opening vhci device - Avoid memcmp() out of bounds warning - Correctly bounds check and pad HCI_MON_NEW_INDEX name - Fix using memcmp when comparing keys - Ignore error return for hci_devcd_register() in btrtl - Always check if connection is alive before deleting - Fix a refcnt underflow problem for hci_conn * tag 'for-net-2023-10-13' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth: Bluetooth: hci_sock: Correctly bounds check and pad HCI_MON_NEW_INDEX name Bluetooth: avoid memcmp() out of bounds warning Bluetooth: hci_sock: fix slab oob read in create_monitor_event Bluetooth: btrtl: Ignore error return for hci_devcd_register() Bluetooth: hci_event: Fix coding style Bluetooth: hci_event: Fix using memcmp when comparing keys Bluetooth: Fix a refcnt underflow problem for hci_conn Bluetooth: hci_sync: always check if connection is alive before deleting Bluetooth: Reject connection with the device which has same BD_ADDR Bluetooth: hci_event: Ignore NULL link key Bluetooth: ISO: Fix invalid context error Bluetooth: vhci: Fix race when opening vhci device ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 7937609 + cb3871b commit 2b10740

File tree

7 files changed

+69
-32
lines changed

7 files changed

+69
-32
lines changed

drivers/bluetooth/btrtl.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -962,13 +962,10 @@ static void btrtl_dmp_hdr(struct hci_dev *hdev, struct sk_buff *skb)
962962
skb_put_data(skb, buf, strlen(buf));
963963
}
964964

965-
static int btrtl_register_devcoredump_support(struct hci_dev *hdev)
965+
static void btrtl_register_devcoredump_support(struct hci_dev *hdev)
966966
{
967-
int err;
967+
hci_devcd_register(hdev, btrtl_coredump, btrtl_dmp_hdr, NULL);
968968

969-
err = hci_devcd_register(hdev, btrtl_coredump, btrtl_dmp_hdr, NULL);
970-
971-
return err;
972969
}
973970

974971
void btrtl_set_driver_name(struct hci_dev *hdev, const char *driver_name)
@@ -1255,8 +1252,7 @@ int btrtl_download_firmware(struct hci_dev *hdev,
12551252
}
12561253

12571254
done:
1258-
if (!err)
1259-
err = btrtl_register_devcoredump_support(hdev);
1255+
btrtl_register_devcoredump_support(hdev);
12601256

12611257
return err;
12621258
}

drivers/bluetooth/hci_vhci.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ static int vhci_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
7474
struct vhci_data *data = hci_get_drvdata(hdev);
7575

7676
memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1);
77+
78+
mutex_lock(&data->open_mutex);
7779
skb_queue_tail(&data->readq, skb);
80+
mutex_unlock(&data->open_mutex);
7881

7982
wake_up_interruptible(&data->read_wait);
8083
return 0;

include/net/bluetooth/hci_mon.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct hci_mon_new_index {
5656
__u8 type;
5757
__u8 bus;
5858
bdaddr_t bdaddr;
59-
char name[8];
59+
char name[8] __nonstring;
6060
} __packed;
6161
#define HCI_MON_NEW_INDEX_SIZE 16
6262

net/bluetooth/hci_conn.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,6 +1627,15 @@ struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
16271627
return ERR_PTR(-EOPNOTSUPP);
16281628
}
16291629

1630+
/* Reject outgoing connection to device with same BD ADDR against
1631+
* CVE-2020-26555
1632+
*/
1633+
if (!bacmp(&hdev->bdaddr, dst)) {
1634+
bt_dev_dbg(hdev, "Reject connection with same BD_ADDR %pMR\n",
1635+
dst);
1636+
return ERR_PTR(-ECONNREFUSED);
1637+
}
1638+
16301639
acl = hci_conn_hash_lookup_ba(hdev, ACL_LINK, dst);
16311640
if (!acl) {
16321641
acl = hci_conn_add(hdev, ACL_LINK, dst, HCI_ROLE_MASTER);

net/bluetooth/hci_event.c

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
/* Bluetooth HCI event handling. */
2727

2828
#include <asm/unaligned.h>
29+
#include <linux/crypto.h>
30+
#include <crypto/algapi.h>
2931

3032
#include <net/bluetooth/bluetooth.h>
3133
#include <net/bluetooth/hci_core.h>
@@ -3268,6 +3270,16 @@ static void hci_conn_request_evt(struct hci_dev *hdev, void *data,
32683270

32693271
bt_dev_dbg(hdev, "bdaddr %pMR type 0x%x", &ev->bdaddr, ev->link_type);
32703272

3273+
/* Reject incoming connection from device with same BD ADDR against
3274+
* CVE-2020-26555
3275+
*/
3276+
if (hdev && !bacmp(&hdev->bdaddr, &ev->bdaddr)) {
3277+
bt_dev_dbg(hdev, "Reject connection with same BD_ADDR %pMR\n",
3278+
&ev->bdaddr);
3279+
hci_reject_conn(hdev, &ev->bdaddr);
3280+
return;
3281+
}
3282+
32713283
mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ev->link_type,
32723284
&flags);
32733285

@@ -4742,6 +4754,15 @@ static void hci_link_key_notify_evt(struct hci_dev *hdev, void *data,
47424754
if (!conn)
47434755
goto unlock;
47444756

4757+
/* Ignore NULL link key against CVE-2020-26555 */
4758+
if (!crypto_memneq(ev->link_key, ZERO_KEY, HCI_LINK_KEY_SIZE)) {
4759+
bt_dev_dbg(hdev, "Ignore NULL link key (ZERO KEY) for %pMR",
4760+
&ev->bdaddr);
4761+
hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE);
4762+
hci_conn_drop(conn);
4763+
goto unlock;
4764+
}
4765+
47454766
hci_conn_hold(conn);
47464767
conn->disc_timeout = HCI_DISCONN_TIMEOUT;
47474768
hci_conn_drop(conn);
@@ -5274,8 +5295,8 @@ static u8 bredr_oob_data_present(struct hci_conn *conn)
52745295
* available, then do not declare that OOB data is
52755296
* present.
52765297
*/
5277-
if (!memcmp(data->rand256, ZERO_KEY, 16) ||
5278-
!memcmp(data->hash256, ZERO_KEY, 16))
5298+
if (!crypto_memneq(data->rand256, ZERO_KEY, 16) ||
5299+
!crypto_memneq(data->hash256, ZERO_KEY, 16))
52795300
return 0x00;
52805301

52815302
return 0x02;
@@ -5285,8 +5306,8 @@ static u8 bredr_oob_data_present(struct hci_conn *conn)
52855306
* not supported by the hardware, then check that if
52865307
* P-192 data values are present.
52875308
*/
5288-
if (!memcmp(data->rand192, ZERO_KEY, 16) ||
5289-
!memcmp(data->hash192, ZERO_KEY, 16))
5309+
if (!crypto_memneq(data->rand192, ZERO_KEY, 16) ||
5310+
!crypto_memneq(data->hash192, ZERO_KEY, 16))
52905311
return 0x00;
52915312

52925313
return 0x01;
@@ -5303,7 +5324,7 @@ static void hci_io_capa_request_evt(struct hci_dev *hdev, void *data,
53035324
hci_dev_lock(hdev);
53045325

53055326
conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
5306-
if (!conn)
5327+
if (!conn || !hci_conn_ssp_enabled(conn))
53075328
goto unlock;
53085329

53095330
hci_conn_hold(conn);
@@ -5550,7 +5571,7 @@ static void hci_simple_pair_complete_evt(struct hci_dev *hdev, void *data,
55505571
hci_dev_lock(hdev);
55515572

55525573
conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
5553-
if (!conn)
5574+
if (!conn || !hci_conn_ssp_enabled(conn))
55545575
goto unlock;
55555576

55565577
/* Reset the authentication requirement to unknown */
@@ -7021,6 +7042,14 @@ static void hci_le_cis_req_evt(struct hci_dev *hdev, void *data,
70217042
hci_dev_unlock(hdev);
70227043
}
70237044

7045+
static int hci_iso_term_big_sync(struct hci_dev *hdev, void *data)
7046+
{
7047+
u8 handle = PTR_UINT(data);
7048+
7049+
return hci_le_terminate_big_sync(hdev, handle,
7050+
HCI_ERROR_LOCAL_HOST_TERM);
7051+
}
7052+
70247053
static void hci_le_create_big_complete_evt(struct hci_dev *hdev, void *data,
70257054
struct sk_buff *skb)
70267055
{
@@ -7065,16 +7094,17 @@ static void hci_le_create_big_complete_evt(struct hci_dev *hdev, void *data,
70657094
rcu_read_lock();
70667095
}
70677096

7097+
rcu_read_unlock();
7098+
70687099
if (!ev->status && !i)
70697100
/* If no BISes have been connected for the BIG,
70707101
* terminate. This is in case all bound connections
70717102
* have been closed before the BIG creation
70727103
* has completed.
70737104
*/
7074-
hci_le_terminate_big_sync(hdev, ev->handle,
7075-
HCI_ERROR_LOCAL_HOST_TERM);
7105+
hci_cmd_sync_queue(hdev, hci_iso_term_big_sync,
7106+
UINT_PTR(ev->handle), NULL);
70767107

7077-
rcu_read_unlock();
70787108
hci_dev_unlock(hdev);
70797109
}
70807110

net/bluetooth/hci_sock.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,8 @@ static struct sk_buff *create_monitor_event(struct hci_dev *hdev, int event)
488488
ni->type = hdev->dev_type;
489489
ni->bus = hdev->bus;
490490
bacpy(&ni->bdaddr, &hdev->bdaddr);
491-
memcpy(ni->name, hdev->name, 8);
491+
memcpy_and_pad(ni->name, sizeof(ni->name), hdev->name,
492+
strnlen(hdev->name, sizeof(ni->name)), '\0');
492493

493494
opcode = cpu_to_le16(HCI_MON_NEW_INDEX);
494495
break;

net/bluetooth/hci_sync.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5369,6 +5369,7 @@ int hci_abort_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, u8 reason)
53695369
{
53705370
int err = 0;
53715371
u16 handle = conn->handle;
5372+
bool disconnect = false;
53725373
struct hci_conn *c;
53735374

53745375
switch (conn->state) {
@@ -5399,24 +5400,15 @@ int hci_abort_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, u8 reason)
53995400
hci_dev_unlock(hdev);
54005401
return 0;
54015402
case BT_BOUND:
5402-
hci_dev_lock(hdev);
5403-
hci_conn_failed(conn, reason);
5404-
hci_dev_unlock(hdev);
5405-
return 0;
5403+
break;
54065404
default:
5407-
hci_dev_lock(hdev);
5408-
conn->state = BT_CLOSED;
5409-
hci_disconn_cfm(conn, reason);
5410-
hci_conn_del(conn);
5411-
hci_dev_unlock(hdev);
5412-
return 0;
5405+
disconnect = true;
5406+
break;
54135407
}
54145408

54155409
hci_dev_lock(hdev);
54165410

5417-
/* Check if the connection hasn't been cleanup while waiting
5418-
* commands to complete.
5419-
*/
5411+
/* Check if the connection has been cleaned up concurrently */
54205412
c = hci_conn_hash_lookup_handle(hdev, handle);
54215413
if (!c || c != conn) {
54225414
err = 0;
@@ -5428,7 +5420,13 @@ int hci_abort_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, u8 reason)
54285420
* or in case of LE it was still scanning so it can be cleanup
54295421
* safely.
54305422
*/
5431-
hci_conn_failed(conn, reason);
5423+
if (disconnect) {
5424+
conn->state = BT_CLOSED;
5425+
hci_disconn_cfm(conn, reason);
5426+
hci_conn_del(conn);
5427+
} else {
5428+
hci_conn_failed(conn, reason);
5429+
}
54325430

54335431
unlock:
54345432
hci_dev_unlock(hdev);

0 commit comments

Comments
 (0)