Skip to contentSkip to conversation

bluetooth 2026-11-02

GIT PULL In review Luiz Augusto von Dentz 2 participants 10 messages Nov 3 – Nov 4

Subsystems (2)
lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

The following changes since commit c3e67bd82b9b9b1a5118f09a429ccefe2aab0741:

ipv6: reject wrapped temporary address preferred lifetimes (2026-11-02 22:31:32 +0100)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth.git tags/for-net-2026-11-02

for you to fetch changes up to 60b10121db602a43ada3dbc39792bbf93d25991b:

Bluetooth: MGMT: Fix discovery stuck after a failed Stop Discovery (2026-11-02 17:09:03 -0500)

----------------------------------------------------------------
bluetooth pull request for net:

Core:

- hci_core: Initialize IRK before publication
- hci_core: Initialize link key before publication
- hci_core: Initialize LTK before publication
- hci_core: Fix queuing rx_work while workqueue is drained
- hci_core: Keep link-key filtering inside RCU
- hci_core: Initialize advertising RPA work only once
- hci_sync: Fix invalid Supervision_Timeout in LE Set Default Rate
- hci_sync: re-enable legacy advertising on resume
- hci_sync: pause advertising for the scan address update
- hci_sync: Update the CIS host feature when enabling LE
- hci_sync: Copy the LE accept list under hdev->lock
- hci_sync: Protect resolving-list lookups
- hci_sync: Copy the resolving-list IRK under RCU
- hci_event: Clear explicit connect state on LE connection
- L2CAP: Hold incoming data until encryption key size is known
- L2CAP: Ignore connection responses with wrong ident
- SMP: Protect link keys during LTK derivation
- SMP: Protect LTK encryption with RCU
- MGMT: Return RFKILLED for Set Powered on a blocked controller
- MGMT: Clear disabled connection parameters when loading none
- MGMT: Fix discovery stuck after a failed Stop Discovery
- validate retained LE Create CIS command length
- validate retained LE Set CIG Parameters command length

Drivers:

- btintel: fix buffer over-read in fw payload
- btmtk: drop zero-length ISO packets from endpoint padding
- btmtk: bound the ISO payload length by the controller's MTU
- btmtk: derive the firmware ISO setting from MTK_ISO_THRESHOLD
- btmtk: fix error handling in btmtk_usb_isointf_init()
- qca: Fix the WCN3950 NVM baud rate offset

----------------------------------------------------------------
Akhil Arul (1):
Bluetooth: hci_core: Fix queuing rx_work while workqueue is drained

Binbin Deng (3):
Bluetooth: hci_core: Initialize IRK before publication
Bluetooth: hci_core: Initialize link key before publication
Bluetooth: hci_core: Initialize LTK before publication

Catherine L (1):
Bluetooth: btintel: fix buffer over-read in fw payload

Cen Zhang (7):
Bluetooth: hci_sync: Copy the LE accept list under hdev->lock
Bluetooth: hci_sync: Protect resolving-list lookups
Bluetooth: hci_core: Keep link-key filtering inside RCU
Bluetooth: SMP: Protect link keys during LTK derivation
Bluetooth: SMP: Protect LTK encryption with RCU
Bluetooth: hci_sync: Copy the resolving-list IRK under RCU
Bluetooth: hci_core: Initialize advertising RPA work only once

Chris Lu (3):
Bluetooth: btmtk: drop zero-length ISO packets from endpoint padding
Bluetooth: btmtk: bound the ISO payload length by the controller's MTU
Bluetooth: btmtk: derive the firmware ISO setting from MTK_ISO_THRESHOLD

Ismail Tarim (1):
Bluetooth: btmtk: fix error handling in btmtk_usb_isointf_init()

Jinwang Li (1):
Bluetooth: L2CAP: Ignore connection responses with wrong ident

Kevin Dewald (3):
Bluetooth: hci_event: Clear explicit connect state on LE connection
Bluetooth: MGMT: Clear disabled connection parameters when loading none
Bluetooth: MGMT: Fix discovery stuck after a failed Stop Discovery

Luiz Augusto von Dentz (4):
Bluetooth: hci_sync: Fix invalid Supervision_Timeout in LE Set Default Rate
Bluetooth: hci_core: Convert hci_conn flags to a bitmap
Bluetooth: L2CAP: Hold incoming data until encryption key size is known
Bluetooth: hci_sync: Update the CIS host feature when enabling LE

Michael McAllister (1):
Bluetooth: qca: Fix the WCN3950 NVM baud rate offset

Tobias Wilken (1):
Bluetooth: MGMT: Return RFKILLED for Set Powered on a blocked controller

Valentin Kindschi (2):
Bluetooth: hci_sync: re-enable legacy advertising on resume
Bluetooth: hci_sync: pause advertising for the scan address update

Yifan Zhang (2):
Bluetooth: validate retained LE Create CIS command length
Bluetooth: validate retained LE Set CIG Parameters command length

 drivers/bluetooth/btintel.c      |  24 ++++-
 drivers/bluetooth/btmtk.c        |  49 +++++++--
 drivers/bluetooth/btqca.c        |   3 +-
 include/net/bluetooth/hci_core.h | 104 +++++++++---------
 net/bluetooth/hci_conn.c         |  92 ++++++++--------
 net/bluetooth/hci_core.c         |  54 +++++++---
 net/bluetooth/hci_event.c        | 212 +++++++++++++++++++++++--------------
 net/bluetooth/hci_sync.c         | 223 ++++++++++++++++++++++++++++++---------
 net/bluetooth/iso.c              |  20 ++--
 net/bluetooth/l2cap_core.c       |  26 +++--
 net/bluetooth/mgmt.c             |  51 ++++++---
 net/bluetooth/smp.c              |  53 ++++++----
 12 files changed, 609 insertions(+), 302 deletions(-)
author maintainer
#1 lore raw

cover Bluetooth: Add support for HDT and EKS

From: Luiz Augusto von Dentz <[email protected]>

This adds support for High Data Throughput (HDT) and Encryption Key Schedule (EKS), introduced in Bluetooth Core 7.0:

- The LE HDT PHY and its rates, selectable with BT_PHY on ACL and with BT_ISO_QOS on CIS and BIS, using the v2 versions of the data length, CIG parameters and BIG creation commands and events.
- struct bt_iso_qos_v2, which adds the rates to the ISO QoS.
- LE Enable Encryption v2, Encryption Change v3 and Encryption Key Refresh Complete v2, which carry the MIC length and whether the key schedule is in use.
- MIC length requirements for L2CAP, set with BT_SECURITY, rejecting LE Credit Based and Enhanced Credit Based connections with MIC Length Too Short when the link uses a shorter MIC.
- LE Set HDT Default Parameters, with the MIC length, packet format and rates configurable through the MGMT system configuration TLVs.
- EKS opportunistic encryption, which encrypts a link without pairing when both devices support it, configurable through MGMT as well.

The userspace changes are posted to linux-bluetooth as:

[PATCH BlueZ v1 0/9] Add support for HDT and EKS

which add the btmon decoding, the emulator support (btdev implements a 7.0 controller with HDT and EKS, now the default for btvirt) and the tests covering this series.

Test coverage, using the BlueZ series above with test-runner:

- l2cap-tester: 141/141, including 30 HDT tests covering each HDT rate, MIC Length Too Short and MIC length downgrade on re-encryption.
- iso-tester: 209/209, including 68 HDT tests covering CIS and BIS on each HDT rate and the default MIC length.
- mgmt-tester: 522/522, including the HDT setting, the HDT default parameters and EKS opportunistic encryption system configuration.
- smp-tester: 8/8.
- BlueZ make check-functional: 53 passed, 1 skipped, with btvirt emulating 7.0 controllers, which covers pairing alongside EKS opportunistic encryption.

Luiz Augusto von Dentz (6):
Bluetooth: Add initial support for HDT PHY
Bluetooth: ISO: Add new QoS v2 adding rate field
Bluetooth: Add initial support for EKS
Bluetooth: L2CAP: Add MIC length validation for HDT PHY
Bluetooth: Add HCI_OP_LE_SET_HDT_DEFAULT_PARAMS support
Bluetooth: Add EKS Opportunistic Encryption support

 include/net/bluetooth/bluetooth.h |  65 +++-
 include/net/bluetooth/hci.h       | 217 +++++++++++-
 include/net/bluetooth/hci_core.h  |  60 +++-
 include/net/bluetooth/hci_sync.h  |   9 +-
 include/net/bluetooth/l2cap.h     |   2 +
 include/net/bluetooth/mgmt.h      |   1 +
 net/bluetooth/hci_conn.c          | 241 +++++++------
 net/bluetooth/hci_core.c          |   4 +
 net/bluetooth/hci_event.c         | 535 ++++++++++++++++++++++++----
 net/bluetooth/hci_sync.c          | 569 +++++++++++++++++++++++++++++-
 net/bluetooth/iso.c               | 136 ++++++-
 net/bluetooth/l2cap_core.c        |  54 ++-
 net/bluetooth/l2cap_sock.c        |   6 +-
 net/bluetooth/mgmt.c              |   6 +
 net/bluetooth/mgmt_config.c       |  49 +++
 net/bluetooth/smp.c               |  30 +-
 net/bluetooth/smp.h               |   2 +
 17 files changed, 1762 insertions(+), 224 deletions(-)
Signature · 1 line
2.56.0
author maintainer
#2 lore raw

PATCH 1/6 Bluetooth: Add initial support for HDT PHY

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Add support for the LE HDT PHY introduced by High Data Throughput (HDT) in Bluetooth 7.0:

- The HDT feature bits (Link Layer feature bits 76-83) and the le_feature() helper to access the FeatureSet pages above page 0, along with hdt_capable() and the per-rate capability checks.
- BT_PHY_HDT_* bits for the HDT2, HDT3, HDT4, HDT6 and HDT7.5 rates in each direction, so userspace can select them with BT_PHY, which map to the LE HDT PHY and the rate bits of PHY_Options in LE Set PHY.
- LE Read Maximum Data Length v2, LE Set Data Length v2, LE Read/Write Suggested Default Data Length v2 and LE Data Length Change v2, used instead of their v1 counterparts on HDT capable controllers so the data length is set for each PHY. The values given to LE Write Suggested Default Data Length are clamped to the maximum the specification allows.
- LE Set CIG Parameters v2, LE CIS Established v3, LE Create BIG v2 and LE Create BIG Complete v2, which carry the HDT rates, MIC length and packet format of a CIS or BIS.
- MGMT_SETTING_HDT to report HDT support to userspace.

---
 include/net/bluetooth/bluetooth.h |  20 +-
 include/net/bluetooth/hci.h       | 179 +++++++++++++++-
 include/net/bluetooth/hci_core.h  |  32 +++
 include/net/bluetooth/hci_sync.h  |   5 +-
 include/net/bluetooth/mgmt.h      |   1 +
 net/bluetooth/hci_conn.c          | 195 ++++++++++-------
 net/bluetooth/hci_event.c         | 326 ++++++++++++++++++++++++++++
 net/bluetooth/hci_sync.c          | 342 +++++++++++++++++++++++++++++-
 net/bluetooth/mgmt.c              |   6 +
 9 files changed, 1019 insertions(+), 87 deletions(-)
include/net/bluetooth/bluetooth.h +19 -1
index cd9189244566..aab6a1ac9a3e 100644
@@ -142,6 +142,16 @@ struct bt_voice {
 #define BT_PHY_LE_2M_RX		BIT(12)
 #define BT_PHY_LE_CODED_TX	BIT(13)
 #define BT_PHY_LE_CODED_RX	BIT(14)
+#define BT_PHY_HDT_2M_TX	BIT(15)
+#define BT_PHY_HDT_2M_RX	BIT(16)
+#define BT_PHY_HDT_3M_TX	BIT(17)
+#define BT_PHY_HDT_3M_RX	BIT(18)
+#define BT_PHY_HDT_4M_TX	BIT(19)
+#define BT_PHY_HDT_4M_RX	BIT(20)
+#define BT_PHY_HDT_6M_TX	BIT(21)
+#define BT_PHY_HDT_6M_RX	BIT(22)
+#define BT_PHY_HDT_7_5M_TX	BIT(23)
+#define BT_PHY_HDT_7_5M_RX	BIT(24)
 
 #define BT_PHY_BREDR_MASK	(BT_PHY_BR_1M_1SLOT | BT_PHY_BR_1M_3SLOT | \
 				 BT_PHY_BR_1M_5SLOT | BT_PHY_EDR_2M_1SLOT | \
@@ -151,6 +161,13 @@ struct bt_voice {
 #define BT_PHY_LE_MASK		(BT_PHY_LE_1M_TX | BT_PHY_LE_1M_RX | \
 				 BT_PHY_LE_2M_TX | BT_PHY_LE_2M_RX | \
 				 BT_PHY_LE_CODED_TX | BT_PHY_LE_CODED_RX)
+#define BT_PHY_HDT_TX_MASK	(BT_PHY_HDT_2M_TX | BT_PHY_HDT_3M_TX | \
+				 BT_PHY_HDT_4M_TX | BT_PHY_HDT_6M_TX | \
+				 BT_PHY_HDT_7_5M_TX)
+#define BT_PHY_HDT_RX_MASK	(BT_PHY_HDT_2M_RX | BT_PHY_HDT_3M_RX | \
+				 BT_PHY_HDT_4M_RX | BT_PHY_HDT_6M_RX | \
+				 BT_PHY_HDT_7_5M_RX)
+#define BT_PHY_HDT_MASK		(BT_PHY_HDT_TX_MASK | BT_PHY_HDT_RX_MASK)
 
 #define BT_MODE			15
 
@@ -221,8 +238,9 @@ struct bt_iso_qos {
 #define BT_ISO_PHY_1M		BIT(0)
 #define BT_ISO_PHY_2M		BIT(1)
 #define BT_ISO_PHY_CODED	BIT(2)
+#define BT_ISO_PHY_HDT		BIT(4)
 #define BT_ISO_PHY_ANY		(BT_ISO_PHY_1M | BT_ISO_PHY_2M | \
-				 BT_ISO_PHY_CODED)
+				 BT_ISO_PHY_CODED | BT_ISO_PHY_HDT)
 
 #define BT_CODEC	19
 
include/net/bluetooth/hci.h +175 -4

209 lines not on this page · raw message

include/net/bluetooth/hci_core.h +32 -0
index e33b158086fd..6a16bc1e775c 100644
@@ -424,6 +424,15 @@ struct hci_dev {
 	__u16		le_max_tx_time;
 	__u16		le_max_rx_len;
 	__u16		le_max_rx_time;
+	__u16		hdt_def_tx_len;
+	__u16		hdt_def_tx_time;
+	__u16		hdt_max_tx_len;
+	__u16		hdt_max_tx_time;
+	__u16		hdt_max_rx_len;
+	__u16		hdt_max_rx_time;
+	__u8		hdt_max_tx_win;
+	__u8		hdt_max_rx_win;
+	__u8		hdt_max_rx_packet;
 	__u8		le_max_key_size;
 	__u8		le_min_key_size;
 	__u16		discov_interleaved_timeout;
@@ -784,6 +793,7 @@ struct hci_conn {
 	__u8		le_rx_def_phys;
 	__u8		le_tx_phy;
 	__u8		le_rx_phy;
+	__u16		le_phy_opts;
 	__s8		rssi;
 	__s8		tx_power;
 	__s8		max_tx_power;
@@ -2148,6 +2158,28 @@ void hci_conn_del_sysfs(struct hci_conn *conn);
 	(past_sender_enabled(dev) || past_receiver_enabled(dev))
 #define ll_ext_feature_capable(dev) \
 	((dev)->le_features[7] & HCI_LE_LL_EXT_FEATURE)
+#define le_feature(dev, page, byte) \
+	(page ? ((dev)->le_features[(page - 1) * 24 + 8 + byte]) : \
+	((dev)->le_features[byte]))
+#define hdt_capable(dev) \
+	(((dev)->le_features[7] & BIT(3)) || \
+	(le_feature(dev, 1, 1) & HCI_LE_HDT_FEATURE))
+#define hdt_enabled(dev) \
+	(le_enabled(dev) && hdt_capable(dev))
+#define hdt_6_rx_capable(dev) \
+	(le_feature(dev, 1, 1) & HCI_LE_HDT_6_RX_FEATURE)
+#define hdt_6_tx_capable(dev) \
+	(le_feature(dev, 1, 1) & HCI_LE_HDT_6_TX_FEATURE)
+#define hdt_7_5_rx_capable(dev) \
+	(le_feature(dev, 1, 2) & HCI_LE_HDT_7_5_RX_FEATURE)
+#define hdt_7_5_tx_capable(dev) \
+	(le_feature(dev, 1, 2) & HCI_LE_HDT_7_5_TX_FEATURE)
+#define hdt_pf1_capable(dev) \
+	(le_feature(dev, 1, 2) & HCI_LE_HDT_PF_1)
+#define hdt_tx_capable(conn) \
+	((conn)->le_tx_def_phys & HCI_LE_SET_PHY_HDT)
+#define hdt_rx_capable(conn) \
+	((conn)->le_rx_def_phys & HCI_LE_SET_PHY_HDT)
 
 /* Channel sounding support */
 #define le_cs_capable(dev) \
include/net/bluetooth/hci_sync.h +4 -1
index 59cb918d1405..a24f6a84a447 100644
@@ -193,4 +193,7 @@ int hci_past_sync(struct hci_conn *conn, struct hci_conn *le);
 int hci_le_read_remote_features(struct hci_conn *conn);
 
 int hci_acl_change_pkt_type(struct hci_conn *conn, u16 pkt_type);
-int hci_le_set_phy(struct hci_conn *conn, u8 tx_phys, u8 rx_phys);
+int hci_le_set_phy(struct hci_conn *conn, u8 tx_phys, u8 rx_phys, u16 phy_opts);
+int hci_le_set_cig_params_sync(struct hci_dev *hdev, u8 cig_id);
+int hci_le_create_big_sync(struct hci_conn *conn, struct bt_iso_qos *qos,
+			   u8 num_bis);
include/net/bluetooth/mgmt.h +1 -0
index b02e915bb44c..17bdd6345d19 100644
@@ -119,6 +119,7 @@ struct mgmt_rp_read_index_list {
 #define MGMT_SETTING_PAST_SENDER	BIT(23)
 #define MGMT_SETTING_PAST_RECEIVER	BIT(24)
 #define MGMT_SETTING_SCI		BIT(25)
+#define MGMT_SETTING_HDT		BIT(26)
 
 #define MGMT_OP_READ_INFO		0x0004
 #define MGMT_READ_INFO_SIZE		0
net/bluetooth/hci_conn.c +115 -80

248 lines not on this page · raw message

net/bluetooth/hci_event.c +326 -0

382 lines not on this page · raw message

net/bluetooth/hci_sync.c +341 -1

404 lines not on this page · raw message

net/bluetooth/mgmt.c +6 -0
index 260ef2a45719..6ed3bf6f1738 100644
@@ -865,6 +865,9 @@ static u32 get_supported_settings(struct hci_dev *hdev)
 	if (le_sci_capable(hdev))
 		settings |= MGMT_SETTING_SCI;
 
+	if (hdt_capable(hdev))
+		settings |= MGMT_SETTING_HDT;
+
 	settings |= MGMT_SETTING_PHY_CONFIGURATION;
 
 	return settings;
@@ -959,6 +962,9 @@ static u32 get_current_settings(struct hci_dev *hdev)
 	if (le_sci_enabled(hdev))
 		settings |= MGMT_SETTING_SCI;
 
+	if (hdt_enabled(hdev))
+		settings |= MGMT_SETTING_HDT;
+
 	return settings;
 }
 
Signature · 1 line
2.56.0
#3 lore raw

RE: [v1,1/6] Bluetooth: Add initial support for HDT PHY

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1200957/

---Test result---

Test Summary:

CheckPatch                    PASS      3.53 seconds
VerifyFixes                   PASS      0.07 seconds
VerifySignedoff               PASS      0.07 seconds
GitLint                       PASS      0.27 seconds
SubjectPrefix                 PASS      0.07 seconds
BuildKernel                   PASS      32.35 seconds
CheckAllWarning               PASS      38.39 seconds
CheckSparse                   WARNING   40.71 seconds
BuildKernel32                 PASS      32.46 seconds
CheckKernelLLVM               PASS      34.66 seconds
TestRunnerSetup               PASS      765.96 seconds
TestRunner_l2cap-tester       FAIL      10.79 seconds
TestRunner_iso-tester         PASS      11.13 seconds
TestRunner_bnep-tester        PASS      3.17 seconds
TestRunner_mgmt-tester        PASS      89.20 seconds
TestRunner_rfcomm-tester      PASS      4.58 seconds
TestRunner_sco-tester         PASS      5.75 seconds
TestRunner_ioctl-tester       PASS      7.83 seconds
TestRunner_mesh-tester        PASS      5.57 seconds
TestRunner_smp-tester         PASS      4.48 seconds
TestRunner_userchan-tester    PASS      3.29 seconds
TestRunner_6lowpan-tester     PASS      5.09 seconds
IncrementalBuild              PASS      30.61 seconds

Details
##############################
Test: CheckSparse - WARNING
Desc: Run sparse tool with linux kernel
Output:
net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):net/bluetooth/hci_sync.c:8425:42: warning: invalid assignment: |=net/bluetooth/hci_sync.c:8425:42: left side has type restricted __le16net/bluetooth/hci_sync.c:8425:42: right side has type unsigned longnet/bluetooth/hci_sync.c:8426:42: warning: invalid assignment: |=net/bluetooth/hci_sync.c:8426:42: left side has type restricted __le16net/bluetooth/hci_sync.c:8426:42: right side has type unsigned longnet/bluetooth/hci_sync.c:8427:42: warning: invalid assignment: |=net/bluetooth/hci_sync.c:8427:42: left side has type restricted __le16net/bluetooth/hci_sync.c:8427:42: right side has type unsigned longnet/bluetooth/hci_sync.c:8430:50: warning: invalid assignment: |=net/bluetooth/hci_sync.c:8430:50: left side has type restricted __le16net/bluetooth/hci_sync.c:8430:50: right side has type unsigned longnet/bluetooth/hci_sync.c:8433:50: warning: invalid assignment: |=net/bluetooth/hci_sync.c:8433:50: left side has type restricted __le16net/bluetooth/hci_sync.c:8433:50: right side has type unsigned longnet/bluetooth/hci_sync.c:8437:42: warning: invalid assignment: |=net/bluetooth/hci_sync.c:8437:42: left side has type restricted __le16net/bluetooth/hci_sync.c:8437:42: right side has type unsigned longnet/bluetooth/hci_sync.c:8438:42: warning: invalid assignment: |=net/bluetooth/hci_sync.c:8438:42: left side has type restricted __le16net/bluetooth/hci_sync.c:8438:42: right side has type unsigned longnet/bluetooth/hci_sync.c:8439:42: warning: invalid assignment: |=net/bluetooth/hci_sync.c:8439:42: left side has type restricted __le16net/bluetooth/hci_sync.c:8439:42: right side has type unsigned longnet/bluetooth/hci_sync.c:8442:50: warning: invalid assignment: |=net/bluetooth/hci_sync.c:8442:50: left side has type restricted __le16net/bluetooth/hci_sync.c:8442:50: right side has type unsigned longnet/bluetooth/hci_sync.c:8445:50: warning: invalid assignment: |=net/bluetooth/hci_sync.c:8445:50: left side has type restricted __le16net/bluetooth/hci_sync.c:8445:50: right side has type unsigned longnet/bluetooth/hci_sync.c:8538:20: warning: incorrect type in assignment (different base types)net/bluetooth/hci_sync.c:8538:20: expected unsigned short [addressable] [assigned] [usertype] sdunet/bluetooth/hci_sync.c:8538:20: got restricted __le16 [usertype]net/bluetooth/hci_sync.c:8539:24: warning: incorrect type in assignment (different base types)net/bluetooth/hci_sync.c:8539:24: expected unsigned short [addressable] [assigned] [usertype] latencynet/bluetooth/hci_sync.c:8539:24: got restricted __le16 [usertype]
##############################
Test: TestRunner_l2cap-tester - FAIL
Desc: Run l2cap-tester with test-runner
Output:
Sanitizer errors:
==35==ERROR: AddressSanitizer: heap-use-after-free on address 0x7b60767e33d0 at pc 0x55c1c3d0de8e bp 0x7ffe51b1f950 sp 0x7ffe51b1f940 READ of size 4 at 0x7b60767e33d0 thread T0

    #0 0x55c1c3d0de8d in timeout_callback src/shared/timeout-mainloop.c:33
    #1 0x55c1c3d0eb75 in timeout_callback src/shared/mainloop.c:270
    #2 0x55c1c3d0faa6 in mainloop_run src/shared/mainloop.c:124
    #3 0x55c1c3d123fa in mainloop_run_with_signal src/shared/mainloop-notify.c:196
    #4 0x55c1c3d1764b in tester_run src/shared/tester.c:1223
    #5 0x55c1c3c4117d in main tools/l2cap-tester.c:3918
    #6 0x7f207777f600 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:59
    #7 0x7f207777f717 in __libc_start_main_impl ../csu/libc-start.c:360
    #8 0x55c1c3c47c84 in _start (/home/runner/work/bluetooth-next/bluetooth-next/src/bluez/tools/l2cap-tester+0x16cc84) (BuildId: 91c9d49e9766c394468e27ffa29b05e7d348169f)

0x7b60767e33d0 is located 0 bytes inside of 40-byte region [0x7b60767e33d0,0x7b60767e33f8) freed by thread T0 here:

    #0 0x7f20780bd3ff in free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:51
    #1 0x55c1c3d0e36a in timeout_destroy src/shared/mainloop.c:251

previously allocated by thread T0 here:

    #0 0x7f20780be60f in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:67
    #1 0x55c1c3cf82d5 in util_malloc src/shared/util.c:46

SUMMARY: AddressSanitizer: heap-use-after-free src/shared/timeout-mainloop.c:33 in timeout_callback No test result found

https://github.com/bluez/bluetooth-next/pull/1055

---
Regards,
Linux Bluetooth

author maintainer
#4 lore raw

PATCH 2/6 Bluetooth: ISO: Add new QoS v2 adding rate field

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Add struct bt_iso_qos_v2, which extends the I/O QoS of BT_ISO_QOS with a rates field so userspace can select the HDT rates of a CIS or BIS along with BT_ISO_PHY_HDT. BT_ISO_QOS accepts either version, telling them apart by the length of the option, and the ISO sockets keep the v2 form internally so the rates are passed to LE Set CIG Parameters v2 and LE Create BIG v2 and reported back from the CIS Established and Create BIG Complete events.

---
 include/net/bluetooth/bluetooth.h |  44 ++++++++++
 include/net/bluetooth/hci_core.h  |  15 ++--
 include/net/bluetooth/hci_sync.h  |   2 +-
 net/bluetooth/hci_conn.c          |  26 +++---
 net/bluetooth/hci_event.c         |   8 +-
 net/bluetooth/hci_sync.c          |  44 ++++++----
 net/bluetooth/iso.c               | 138 ++++++++++++++++++++++++++----
 7 files changed, 218 insertions(+), 59 deletions(-)
include/net/bluetooth/bluetooth.h +44 -0
index aab6a1ac9a3e..945c0bc58a95 100644
@@ -235,6 +235,50 @@ struct bt_iso_qos {
 	};
 };
 
+struct bt_iso_io_qos_v2 {
+	__u32 interval;
+	__u16 latency;
+	__u16 sdu;
+	__u8  phys;
+	__u8  rtn;
+	__u16 rates;
+};
+
+struct bt_iso_ucast_qos_v2 {
+	__u8  cig;
+	__u8  cis;
+	__u8  sca;
+	__u8  packing;
+	__u8  framing;
+	struct bt_iso_io_qos_v2 in;
+	struct bt_iso_io_qos_v2 out;
+};
+
+struct bt_iso_bcast_qos_v2 {
+	__u8  big;
+	__u8  bis;
+	__u8  sync_factor;
+	__u8  packing;
+	__u8  framing;
+	struct bt_iso_io_qos_v2 in;
+	struct bt_iso_io_qos_v2 out;
+	__u8  encryption;
+	__u8  bcode[16];
+	__u8  options;
+	__u16 skip;
+	__u16 sync_timeout;
+	__u8  sync_cte_type;
+	__u8  mse;
+	__u16 timeout;
+};
+
+struct bt_iso_qos_v2 {
+	union {
+		struct bt_iso_ucast_qos_v2 ucast;
+		struct bt_iso_bcast_qos_v2 bcast;
+	};
+};
+
 #define BT_ISO_PHY_1M		BIT(0)
 #define BT_ISO_PHY_2M		BIT(1)
 #define BT_ISO_PHY_CODED	BIT(2)
include/net/bluetooth/hci_core.h +8 -7
index 6a16bc1e775c..f6e2a414bf2a 100644
@@ -797,7 +797,7 @@ struct hci_conn {
 	__s8		rssi;
 	__s8		tx_power;
 	__s8		max_tx_power;
-	struct bt_iso_qos iso_qos;
+	struct bt_iso_qos_v2 iso_qos;
 	__u8		num_bis;
 	__u8		bis[HCI_MAX_ISO_BIS];
 
@@ -1678,23 +1678,24 @@ struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
 				 __u16 setting, struct bt_codec *codec,
 				 u16 timeout);
 struct hci_conn *hci_bind_cis(struct hci_dev *hdev, bdaddr_t *dst,
-			      __u8 dst_type, struct bt_iso_qos *qos,
+			      __u8 dst_type, struct bt_iso_qos_v2 *qos,
 			      u16 timeout);
 struct hci_conn *hci_bind_bis(struct hci_dev *hdev, bdaddr_t *dst, __u8 sid,
-			      struct bt_iso_qos *qos,
+			      struct bt_iso_qos_v2 *qos,
 			      __u8 base_len, __u8 *base, u16 timeout);
 int hci_past_bis(struct hci_conn *conn, bdaddr_t *dst, __u8 dst_type);
 struct hci_conn *hci_connect_cis(struct hci_dev *hdev, bdaddr_t *dst,
-				 __u8 dst_type, struct bt_iso_qos *qos,
+				 __u8 dst_type, struct bt_iso_qos_v2 *qos,
 				 u16 timeout);
 struct hci_conn *hci_connect_bis(struct hci_dev *hdev, bdaddr_t *dst,
 				 __u8 dst_type, __u8 sid,
-				 struct bt_iso_qos *qos,
+				 struct bt_iso_qos_v2 *qos,
 				 __u8 data_len, __u8 *data, u16 timeout);
 struct hci_conn *hci_pa_create_sync(struct hci_dev *hdev, bdaddr_t *dst,
-		       __u8 dst_type, __u8 sid, struct bt_iso_qos *qos);
+				    __u8 dst_type, __u8 sid,
+				    struct bt_iso_qos_v2 *qos);
 int hci_conn_big_create_sync(struct hci_dev *hdev, struct hci_conn *hcon,
-			     struct bt_iso_qos *qos, __u16 sync_handle,
+			     struct bt_iso_qos_v2 *qos, __u16 sync_handle,
 			     __u8 num_bis, __u8 bis[]);
 int hci_conn_check_link_mode(struct hci_conn *conn);
 int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level);
include/net/bluetooth/hci_sync.h +1 -1
index a24f6a84a447..ca21fe81a06e 100644
@@ -195,5 +195,5 @@ int hci_le_read_remote_features(struct hci_conn *conn);
 int hci_acl_change_pkt_type(struct hci_conn *conn, u16 pkt_type);
 int hci_le_set_phy(struct hci_conn *conn, u8 tx_phys, u8 rx_phys, u16 phy_opts);
 int hci_le_set_cig_params_sync(struct hci_dev *hdev, u8 cig_id);
-int hci_le_create_big_sync(struct hci_conn *conn, struct bt_iso_qos *qos,
+int hci_le_create_big_sync(struct hci_conn *conn, struct bt_iso_qos_v2 *qos,
 			   u8 num_bis);
net/bluetooth/hci_conn.c +13 -13
index edf7be18a0cc..8524fca9f273 100644
@@ -1637,7 +1637,7 @@ static int hci_explicit_conn_params_set(struct hci_dev *hdev,
 	return 0;
 }
 
-static int qos_set_big(struct hci_dev *hdev, struct bt_iso_qos *qos)
+static int qos_set_big(struct hci_dev *hdev, struct bt_iso_qos_v2 *qos)
 {
 	struct hci_conn *conn;
 	u8  big;
@@ -1661,7 +1661,7 @@ static int qos_set_big(struct hci_dev *hdev, struct bt_iso_qos *qos)
 	return 0;
 }
 
-static int qos_set_bis(struct hci_dev *hdev, struct bt_iso_qos *qos)
+static int qos_set_bis(struct hci_dev *hdev, struct bt_iso_qos_v2 *qos)
 {
 	struct hci_conn *conn;
 	u8  bis;
@@ -1703,7 +1703,7 @@ static int qos_set_bis(struct hci_dev *hdev, struct bt_iso_qos *qos)
 
 /* This function requires the caller holds hdev->lock */
 static struct hci_conn *hci_add_bis(struct hci_dev *hdev, bdaddr_t *dst,
-				    __u8 sid, struct bt_iso_qos *qos,
+				    __u8 sid, struct bt_iso_qos_v2 *qos,
 				    __u8 base_len, __u8 *base, u16 timeout)
 {
 	struct hci_conn *conn;
@@ -1938,7 +1938,7 @@ struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
 	return sco;
 }
 
-static int hci_le_create_big(struct hci_conn *conn, struct bt_iso_qos *qos)
+static int hci_le_create_big(struct hci_conn *conn, struct bt_iso_qos_v2 *qos)
 {
 	struct hci_dev *hdev = conn->hdev;
 	struct iso_list_data data;
@@ -1961,7 +1961,7 @@ static int set_cig_params_sync(struct hci_dev *hdev, void *data)
 	return hci_le_set_cig_params_sync(hdev, cig_id);
 }
 
-static bool hci_le_set_cig_params(struct hci_conn *conn, struct bt_iso_qos *qos)
+static bool hci_le_set_cig_params(struct hci_conn *conn, struct bt_iso_qos_v2 *qos)
 {
 	struct hci_dev *hdev = conn->hdev;
 	struct iso_list_data data;
@@ -2023,7 +2023,7 @@ static bool hci_le_set_cig_params(struct hci_conn *conn, struct bt_iso_qos *qos)
 }
 
 struct hci_conn *hci_bind_cis(struct hci_dev *hdev, bdaddr_t *dst,
-			      __u8 dst_type, struct bt_iso_qos *qos,
+			      __u8 dst_type, struct bt_iso_qos_v2 *qos,
 			      u16 timeout)
 {
 	struct hci_conn *cis;
@@ -2166,7 +2166,7 @@ int hci_le_create_cis_pending(struct hci_dev *hdev)
 }
 
 static void hci_iso_qos_setup(struct hci_dev *hdev, struct hci_conn *conn,
-			      struct bt_iso_io_qos *qos, __u8 phys)
+			      struct bt_iso_io_qos_v2 *qos, __u8 phys)
 {
 	/* Only set MTU if PHY is enabled */
 	if (!qos->sdu && qos->phys)
@@ -2189,7 +2189,7 @@ static void hci_iso_qos_setup(struct hci_dev *hdev, struct hci_conn *conn,
 static int create_big_sync(struct hci_dev *hdev, void *data)
 {
 	struct hci_conn *conn = data;
-	struct bt_iso_qos *qos = &conn->iso_qos;
+	struct bt_iso_qos_v2 *qos = &conn->iso_qos;
 	u16 interval, sync_interval = 0;
 	u32 flags = 0;
 	int err;
@@ -2218,7 +2218,7 @@ static int create_big_sync(struct hci_dev *hdev, void *data)
 
 struct hci_conn *hci_pa_create_sync(struct hci_dev *hdev, bdaddr_t *dst,
 				    __u8 dst_type, __u8 sid,
-				    struct bt_iso_qos *qos)
+				    struct bt_iso_qos_v2 *qos)
 {
 	struct hci_conn *conn;
 
@@ -2241,7 +2241,7 @@ struct hci_conn *hci_pa_create_sync(struct hci_dev *hdev, bdaddr_t *dst,
 }
 
 int hci_conn_big_create_sync(struct hci_dev *hdev, struct hci_conn *hcon,
-			     struct bt_iso_qos *qos, __u16 sync_handle,
+			     struct bt_iso_qos_v2 *qos, __u16 sync_handle,
 			     __u8 num_bis, __u8 bis[])
 {
 	int err;
@@ -2292,7 +2292,7 @@ static void create_big_complete(struct hci_dev *hdev, void *data, int err)
 }
 
 struct hci_conn *hci_bind_bis(struct hci_dev *hdev, bdaddr_t *dst, __u8 sid,
-			      struct bt_iso_qos *qos,
+			      struct bt_iso_qos_v2 *qos,
 			      __u8 base_len, __u8 *base, u16 timeout)
 {
 	struct hci_conn *conn;
@@ -2380,7 +2380,7 @@ static void bis_mark_per_adv(struct hci_conn *conn, void *data)
 
 struct hci_conn *hci_connect_bis(struct hci_dev *hdev, bdaddr_t *dst,
 				 __u8 dst_type, __u8 sid,
-				 struct bt_iso_qos *qos,
+				 struct bt_iso_qos_v2 *qos,
 				 __u8 base_len, __u8 *base, u16 timeout)
 {
 	struct hci_conn *conn;
@@ -2431,7 +2431,7 @@ struct hci_conn *hci_connect_bis(struct hci_dev *hdev, bdaddr_t *dst,
 }
 
 struct hci_conn *hci_connect_cis(struct hci_dev *hdev, bdaddr_t *dst,
-				 __u8 dst_type, struct bt_iso_qos *qos,
+				 __u8 dst_type, struct bt_iso_qos_v2 *qos,
 				 u16 timeout)
 {
 	struct hci_conn *le;
net/bluetooth/hci_event.c +6 -2
index 466f09124fcd..7b1c2ce58d73 100644
@@ -7372,7 +7372,7 @@ static void hci_le_cis_established_evt(struct hci_dev *hdev, void *data,
 {
 	struct hci_evt_le_cis_established *ev = data;
 	struct hci_conn *conn;
-	struct bt_iso_qos *qos;
+	struct bt_iso_qos_v2 *qos;
 	bool pending = false;
 	u16 handle = __le16_to_cpu(ev->handle);
 	u32 c_sdu_interval, p_sdu_interval;
@@ -7869,7 +7869,7 @@ static void hci_le_cis_established_evt_v3(struct hci_dev *hdev, void *data,
 {
 	struct hci_evt_le_cis_established_v3 *ev = data;
 	struct hci_conn *conn;
-	struct bt_iso_qos *qos;
+	struct bt_iso_qos_v2 *qos;
 	bool pending = false;
 	u16 handle = __le16_to_cpu(ev->handle);
 	u32 c_sdu_interval, p_sdu_interval;
@@ -7915,6 +7915,8 @@ static void hci_le_cis_established_evt_v3(struct hci_dev *hdev, void *data,
 		qos->ucast.out.sdu = ev->p_bn ? le16_to_cpu(ev->p_mtu) : 0;
 		qos->ucast.in.phys = le_phy_qos(ev->c_phy);
 		qos->ucast.out.phys = le_phy_qos(ev->p_phy);
+		qos->ucast.in.rates = le16_to_cpu(ev->c_rates);
+		qos->ucast.out.rates = le16_to_cpu(ev->p_rates);
 		break;
 	case HCI_ROLE_MASTER:
 		qos->ucast.in.interval = p_sdu_interval;
@@ -7930,6 +7932,8 @@ static void hci_le_cis_established_evt_v3(struct hci_dev *hdev, void *data,
 		qos->ucast.in.sdu = ev->p_bn ? le16_to_cpu(ev->p_mtu) : 0;
 		qos->ucast.out.phys = le_phy_qos(ev->c_phy);
 		qos->ucast.in.phys = le_phy_qos(ev->p_phy);
+		qos->ucast.out.rates = le16_to_cpu(ev->c_rates);
+		qos->ucast.in.rates = le16_to_cpu(ev->p_rates);
 		break;
 	}
 
net/bluetooth/hci_sync.c +27 -17

116 lines not on this page · raw message

net/bluetooth/iso.c +119 -19

221 lines not on this page · raw message

Signature · 1 line
2.56.0
author maintainer
#5 lore raw

PATCH 3/6 Bluetooth: Add initial support for EKS

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Add support for Encryption Key Schedule (EKS) introduced in Bluetooth 7.0:

- LE Enable Encryption v2, which replaces LE Start Encryption on EKS capable controllers and carries the MIC length to use on the LE HDT PHY. SMP now starts encryption through hci_le_enable_encrypt(), which picks the version the controller supports.
- Encryption Change v3 and Encryption Key Refresh Complete v2, enabled through Event Mask Page 2, which report the MIC length and whether the key schedule is in use. The encryption change and key refresh handling is moved to helpers shared by every version of the events.
- eks_capable() for the Encryption Key Schedule feature bit.

---
 include/net/bluetooth/hci.h      |  30 +++++++
 include/net/bluetooth/hci_core.h |   4 +-
 include/net/bluetooth/hci_sync.h |   3 +
 net/bluetooth/hci_conn.c         |  18 ----
 net/bluetooth/hci_event.c        | 149 +++++++++++++++++++++----------
 net/bluetooth/hci_sync.c         |  85 ++++++++++++++++++
 net/bluetooth/smp.c              |   7 +-
 7 files changed, 228 insertions(+), 68 deletions(-)
include/net/bluetooth/hci.h +30 -0
index 525344702c87..e9bbd687b12e 100644
@@ -2564,6 +2564,16 @@ struct hci_rp_le_read_def_data_len_v2 {
 	__le16	tx_time;
 } __packed;
 
+#define HCI_OP_LE_ENABLE_ENCRYPT_V2		0x20af
+struct hci_cp_le_enable_encrypt_v2 {
+	__le16  handle;
+	__le64  rand;
+	__le16  ediv;
+	__u8    ltk[16];
+	__u8    mic_len;
+	__u8    encryption;
+} __packed;
+
 #define HCI_OP_LE_READ_MAX_DATA_LEN_V2		0x20b0
 struct hci_cp_le_read_max_data_len_v2 {
 	__u8    phy;
@@ -3040,6 +3050,26 @@ struct hci_ev_sync_train_complete {
 
 #define HCI_EV_PERIPHERAL_PAGE_RESP_TIMEOUT	0x54
 
+#define HCI_EVT_KEY_REFRESH_COMPLETE_V2		0x5b
+struct hci_evt_key_refresh_complete_v2 {
+	__u8    status;
+	__le16  handle;
+	__u8    mic_len;
+	__u8    eks_mode;
+	__u8    eks_debug;
+} __packed;
+
+#define HCI_EVT_ENCRYPT_CHANGE_V3		0x5a
+struct hci_evt_encrypt_change_v3 {
+	__u8    status;
+	__le16  handle;
+	__u8    mode;
+	__u8    key_size;
+	__u8    mic_len;
+	__u8    eks_mode;
+	__u8    eks_debug;
+} __packed;
+
 #define HCI_EV_LE_CONN_COMPLETE		0x01
 struct hci_ev_le_conn_complete {
 	__u8     status;
include/net/bluetooth/hci_core.h +2 -2
index f6e2a414bf2a..60318740ec99 100644
@@ -2181,6 +2181,8 @@ void hci_conn_del_sysfs(struct hci_conn *conn);
 	((conn)->le_tx_def_phys & HCI_LE_SET_PHY_HDT)
 #define hdt_rx_capable(conn) \
 	((conn)->le_rx_def_phys & HCI_LE_SET_PHY_HDT)
+#define eks_capable(dev) \
+	(le_feature(dev, 1, 1) & HCI_LE_EKS_FEATURE)
 
 /* Channel sounding support */
 #define le_cs_capable(dev) \
@@ -2628,8 +2630,6 @@ void mgmt_conn_subrate_notify(struct hci_dev *hdev, struct hci_conn *conn,
 int hci_abort_conn(struct hci_conn *conn, u8 reason);
 void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max, u16 latency,
 		      u16 to_multiplier);
-void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __le64 rand,
-		      __u8 ltk[16], __u8 key_size);
 
 void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr,
 			       u8 *bdaddr_type);
include/net/bluetooth/hci_sync.h +3 -0
index ca21fe81a06e..4b5baee9ce11 100644
@@ -197,3 +197,6 @@ int hci_le_set_phy(struct hci_conn *conn, u8 tx_phys, u8 rx_phys, u16 phy_opts);
 int hci_le_set_cig_params_sync(struct hci_dev *hdev, u8 cig_id);
 int hci_le_create_big_sync(struct hci_conn *conn, struct bt_iso_qos_v2 *qos,
 			   u8 num_bis);
+
+int hci_le_enable_encrypt(struct hci_conn *conn, __le16 ediv, __le64 rand,
+			  __u8 ltk[16], __u8 key_size);
net/bluetooth/hci_conn.c +0 -18
index 8524fca9f273..90aed3b75634 100644
@@ -598,24 +598,6 @@ void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max, u16 latency,
 	}
 }
 
-void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __le64 rand,
-		      __u8 ltk[16], __u8 key_size)
-{
-	struct hci_dev *hdev = conn->hdev;
-	struct hci_cp_le_start_enc cp;
-
-	BT_DBG("hcon %p", conn);
-
-	memset(&cp, 0, sizeof(cp));
-
-	cp.handle = cpu_to_le16(conn->handle);
-	cp.rand = rand;
-	cp.ediv = ediv;
-	memcpy(cp.ltk, ltk, key_size);
-
-	hci_send_cmd(hdev, HCI_OP_LE_START_ENC, sizeof(cp), &cp);
-}
-
 /* Device _must_ be locked */
 void hci_sco_setup(struct hci_conn *conn, __u8 status)
 {
net/bluetooth/hci_event.c +104 -45

236 lines not on this page · raw message

net/bluetooth/hci_sync.c +85 -0

100 lines not on this page · raw message

net/bluetooth/smp.c +4 -3
index b7015e37e1f1..0dc236cd4d1c 100644
@@ -987,7 +987,7 @@ static u8 smp_random(struct smp_chan *smp)
 		if (test_and_set_bit(HCI_CONN_ENCRYPT_PEND, hcon->flags))
 			return SMP_UNSPECIFIED;
 
-		hci_le_start_enc(hcon, ediv, rand, stk, smp->enc_key_size);
+		hci_le_enable_encrypt(hcon, ediv, rand, stk, smp->enc_key_size);
 		hcon->enc_key_size = smp->enc_key_size;
 		set_bit(HCI_CONN_STK_ENCRYPT, hcon->flags);
 	} else {
@@ -2224,7 +2224,8 @@ static bool smp_ltk_encrypt(struct l2cap_conn *conn, u8 sec_level)
 	if (test_and_set_bit(HCI_CONN_ENCRYPT_PEND, hcon->flags))
 		goto unlock;
 
-	hci_le_start_enc(hcon, key->ediv, key->rand, key->val, key->enc_size);
+	hci_le_enable_encrypt(hcon, key->ediv, key->rand, key->val,
+			      key->enc_size);
 	hcon->enc_key_size = key->enc_size;
 
 	/* We never store STKs for initiator role, so clear this flag */
@@ -2927,7 +2928,7 @@ static int smp_cmd_dhkey_check(struct l2cap_conn *conn, struct sk_buff *skb)
 	sc_add_ltk(smp);
 
 	if (test_bit(SMP_FLAG_INITIATOR, &smp->flags)) {
-		hci_le_start_enc(hcon, 0, 0, smp->tk, smp->enc_key_size);
+		hci_le_enable_encrypt(hcon, 0, 0, smp->tk, smp->enc_key_size);
 		hcon->enc_key_size = smp->enc_key_size;
 	}
 
Signature · 1 line
2.56.0
author maintainer
#6 lore raw

PATCH 4/6 Bluetooth: L2CAP: Add MIC length validation for HDT PHY

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Add a mic_len field to struct bt_security so userspace can require a minimum MIC length on an L2CAP channel with BT_SECURITY, and read the MIC length in use on the link back. The field is added at the end of the struct, so the shorter struct is still accepted, leaving mic_len unset.

The requirement is propagated to the connection so LE Enable Encryption v2 asks for it, and the MIC length reported by Encryption Change v3 is stored on the connection. When a connection is encrypted on the LE HDT PHY with a MIC shorter than the channel requires, the LE Credit Based and Enhanced Credit Based connection requests are rejected with MIC Length Too Short.

The negotiated MIC length only applies on the LE HDT PHY, the MIC is always 32 bits on the GFSK PHYs, so hci_conn_mic_len() reports it as such both for the check and for BT_SECURITY.

---
 include/net/bluetooth/bluetooth.h |  1 +
 include/net/bluetooth/hci_core.h  |  9 +++++++++
 include/net/bluetooth/l2cap.h     |  2 ++
 net/bluetooth/hci_event.c         | 29 +++++++++++++++++----------
 net/bluetooth/hci_sync.c          |  3 ++-
 net/bluetooth/l2cap_core.c        | 33 ++++++++++++++++++++++++++++++-
 net/bluetooth/l2cap_sock.c        | 16 ++++++++++++---
 7 files changed, 78 insertions(+), 15 deletions(-)
include/net/bluetooth/bluetooth.h +1 -0
index 945c0bc58a95..9e462c58c4ce 100644
@@ -66,6 +66,7 @@
 struct bt_security {
 	__u8 level;
 	__u8 key_size;
+	__u8 mic_len;
 };
 #define BT_SECURITY_SDP		0
 #define BT_SECURITY_LOW		1
include/net/bluetooth/hci_core.h +9 -0
index 60318740ec99..d1c6ae23714d 100644
@@ -765,6 +765,7 @@ struct hci_conn {
 	__u8		pending_sec_level;
 	__u8		pin_length;
 	__u8		enc_key_size;
+	__u8		mic_len;
 	__u8		io_capability;
 	__u32		passkey_notify;
 	__u8		passkey_entered;
@@ -2181,6 +2182,14 @@ void hci_conn_del_sysfs(struct hci_conn *conn);
 	((conn)->le_tx_def_phys & HCI_LE_SET_PHY_HDT)
 #define hdt_rx_capable(conn) \
 	((conn)->le_rx_def_phys & HCI_LE_SET_PHY_HDT)
+
+/* The MIC length negotiated with LE Enable Encryption v2 only applies on the
+ * LE HDT PHY, the MIC is always 32 bits (0x00) on the GFSK PHYs.
+ */
+static inline __u8 hci_conn_mic_len(struct hci_conn *conn)
+{
+	return conn->le_rx_phy == 0x05 ? conn->mic_len : 0x00;
+}
 #define eks_capable(dev) \
 	(le_feature(dev, 1, 1) & HCI_LE_EKS_FEATURE)
 
include/net/bluetooth/l2cap.h +2 -0
index 54eddcdd341f..182df5c5731e 100644
@@ -285,6 +285,7 @@ struct l2cap_conn_rsp {
 #define L2CAP_CR_LE_SCID_IN_USE		0x000A
 #define L2CAP_CR_LE_UNACCEPT_PARAMS	0x000B
 #define L2CAP_CR_LE_INVALID_PARAMS	0x000C
+#define L2CAP_CR_LE_MIC_LEN_TOO_SHORT	0x00FE
 
 /* connect/create channel status */
 #define L2CAP_CS_NO_INFO	0x0000
@@ -533,6 +534,7 @@ struct l2cap_chan {
 	__u8		chan_policy;
 
 	__u8		sec_level;
+	__u8		mic_len;
 
 	__u8		ident;
 
net/bluetooth/hci_event.c +19 -10
index 896a2ebd806d..be8b480e6ab7 100644
@@ -3725,7 +3725,8 @@ static void hci_remote_name_evt(struct hci_dev *hdev, void *data,
 	hci_dev_unlock(hdev);
 }
 
-static void hci_change_encrypt(struct hci_conn *conn, u8 status, u8 encrypt)
+static void hci_change_encrypt(struct hci_conn *conn, u8 status, u8 encrypt,
+			       u8 key_size, u8 mic_len)
 {
 	struct hci_dev *hdev = conn->hdev;
 
@@ -3744,14 +3745,21 @@ static void hci_change_encrypt(struct hci_conn *conn, u8 status, u8 encrypt)
 			    conn->type == LE_LINK)
 				set_bit(HCI_CONN_AES_CCM, conn->flags);
 
+			if (key_size)
+				conn->enc_key_size = key_size;
+
+			if (mic_len)
+				conn->mic_len = mic_len;
+
 			/* For ACL links the encryption key size is still
-			 * validated below via hci_read_enc_key_size(). Its
-			 * completion handler, hci_cc_read_enc_key_size(),
-			 * reports the final security level so userspace does
-			 * not see a transient "encrypted" state that a
-			 * key-size downgrade would immediately invalidate.
+			 * validated below via hci_read_enc_key_size(), unless
+			 * the event already carried it. Its completion
+			 * handler, hci_cc_read_enc_key_size(), reports the
+			 * final security level so userspace does not see a
+			 * transient "encrypted" state that a key-size
+			 * downgrade would immediately invalidate.
 			 */
-			if (conn->type != ACL_LINK)
+			if (conn->type != ACL_LINK || key_size)
 				mgmt_security_level_changed(conn);
 		} else {
 			clear_bit(HCI_CONN_ENCRYPT, conn->flags);
@@ -3796,7 +3804,7 @@ static void hci_change_encrypt(struct hci_conn *conn, u8 status, u8 encrypt)
 	}
 
 	/* Try reading the encryption key size for encrypted ACL links */
-	if (!status && encrypt && conn->type == ACL_LINK) {
+	if (!status && encrypt && conn->type == ACL_LINK && !key_size) {
 		if (hci_read_enc_key_size(hdev, conn)) {
 			/* Could not even issue the key-size read: report the
 			 * security level now since hci_cc_read_enc_key_size()
@@ -3853,7 +3861,7 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, void *data,
 	if (!conn)
 		goto unlock;
 
-	hci_change_encrypt(conn, ev->status, ev->encrypt);
+	hci_change_encrypt(conn, ev->status, ev->encrypt, 0, 0);
 
 unlock:
 	hci_dev_unlock(hdev);
@@ -3873,7 +3881,8 @@ static void hci_encrypt_change_v3_evt(struct hci_dev *hdev, void *data,
 	if (!conn)
 		goto unlock;
 
-	hci_change_encrypt(conn, ev->status, ev->mode);
+	hci_change_encrypt(conn, ev->status, ev->mode, ev->key_size,
+			   ev->mic_len);
 
 unlock:
 	hci_dev_unlock(hdev);
net/bluetooth/hci_sync.c +2 -1
index 1c52b914c236..5f743cf362e5 100644
@@ -8636,7 +8636,8 @@ static int hci_le_enable_encrypt_v2(struct hci_conn *conn, __le16 ediv,
 	cp->handle = cpu_to_le16(conn->handle);
 	cp->rand = rand;
 	cp->ediv = ediv;
-	cp->mic_len = 0x02; /* Always prefer 128 bits? */
+	/* Use requested mic_len from hcon, default to 128 bits if unset */
+	cp->mic_len = conn->mic_len ? conn->mic_len : 0x02;
 
 	if (ltk) {
 		memcpy(cp->ltk, ltk, sizeof(cp->ltk));
net/bluetooth/l2cap_core.c +32 -1
index 70ad30b091e4..4abb4b28ddec 100644
@@ -579,6 +579,7 @@ void l2cap_chan_set_defaults(struct l2cap_chan *chan, struct l2cap_chan *pchan)
 		chan->tx_win = pchan->tx_win;
 		chan->tx_win_max = pchan->tx_win_max;
 		chan->sec_level = pchan->sec_level;
+		chan->mic_len = pchan->mic_len;
 		chan->conf_state = pchan->conf_state;
 		chan->flags = pchan->flags;
 		chan->tx_credits = pchan->tx_credits;
@@ -1031,8 +1032,13 @@ int l2cap_chan_check_security(struct l2cap_chan *chan, bool initiator)
 	struct l2cap_conn *conn = chan->conn;
 	__u8 auth_type;
 
-	if (conn->hcon->type == LE_LINK)
+	if (conn->hcon->type == LE_LINK) {
+		/* Propagate mic_len requirement to hcon for encrypt_v2 */
+		if (chan->mic_len > conn->hcon->mic_len)
+			conn->hcon->mic_len = chan->mic_len;
+
 		return smp_conn_security(conn->hcon, chan->sec_level);
+	}
 
 	auth_type = l2cap_get_auth_type(chan);
 
@@ -1579,6 +1585,18 @@ static bool l2cap_check_enc_key_size(struct hci_conn *hcon,
 		hcon->enc_key_size >= min_key_size);
 }
 
+static bool l2cap_check_mic_len(struct hci_conn *hcon, struct l2cap_chan *chan)
+{
+	/* If the channel has no MIC length requirement, skip check */
+	if (!chan->mic_len)
+		return true;
+
+	if (!test_bit(HCI_CONN_ENCRYPT, hcon->flags))
+		return true;
+
+	return hci_conn_mic_len(hcon) >= chan->mic_len;
+}
+
 static void l2cap_do_start(struct l2cap_chan *chan)
 	__must_hold(&chan->lock)
 	__must_hold(&chan->conn->lock)
@@ -5283,6 +5301,13 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn,
 		goto response_unlock;
 	}
 
+	/* Check if MIC length is sufficient for HDT PHY */
+	if (!l2cap_check_mic_len(conn->hcon, pchan)) {
+		result = L2CAP_CR_LE_MIC_LEN_TOO_SHORT;
+		chan = NULL;
+		goto response_unlock;
+	}
+
 	/* Check for valid dynamic CID range */
 	if (scid < L2CAP_CID_DYN_START || scid > L2CAP_CID_LE_DYN_END) {
 		result = L2CAP_CR_LE_INVALID_SCID;
@@ -5501,6 +5526,12 @@ static inline int l2cap_ecred_conn_req(struct l2cap_conn *conn,
 		goto unlock;
 	}
 
+	/* Check if MIC length is sufficient */
+	if (!l2cap_check_mic_len(conn->hcon, pchan)) {
+		result = L2CAP_CR_LE_MIC_LEN_TOO_SHORT;
+		goto unlock;
+	}
+
 	/* Check if the listening channel has set an output MTU then the
 	 * requested MTU shall be less than or equal to that value.
 	 */
net/bluetooth/l2cap_sock.c +13 -3
index 7a2551ef7f50..9b7798961266 100644
@@ -623,8 +623,10 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname,
 		if (conn) {
 			sec.level = conn->hcon->sec_level;
 
-			if (sk->sk_state == BT_CONNECTED)
+			if (sk->sk_state == BT_CONNECTED) {
 				sec.key_size = conn->hcon->enc_key_size;
+				sec.mic_len = hci_conn_mic_len(conn->hcon);
+			}
 		} else {
 			sec.level = chan->sec_level;
 		}
@@ -960,9 +962,16 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
 			break;
 		}
 
-		sec.level = BT_SECURITY_LOW;
+		/* mic_len was added at the end of struct bt_security, so
+		 * accept the shorter struct as well, leaving mic_len unset.
+		 */
+		if (optlen < offsetofend(struct bt_security, key_size)) {
+			err = -EINVAL;
+			break;
+		}
 
-		err = copy_safe_from_sockptr(&sec, sizeof(sec), optval, optlen);
+		err = copy_struct_from_sockptr(&sec, sizeof(sec), optval,
+					       optlen);
 		if (err)
 			break;
 
@@ -973,6 +982,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
 		}
 
 		chan->sec_level = sec.level;
+		chan->mic_len = sec.mic_len;
 
 		conn = l2cap_chan_conn(chan);
 		if (!conn)
Signature · 1 line
2.56.0
author maintainer
#7 lore raw

PATCH 5/6 Bluetooth: Add HCI_OP_LE_SET_HDT_DEFAULT_PARAMS support

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Add support for LE Set HDT Default Parameters, which sets the MIC length, packet format and ACL rates the controller prefers on the LE HDT PHY. The command is sent during controller initialization when the controller supports HDT and the command, with the rates limited to the ones the controller supports.

The defaults are stored in hci_dev, 128-bit MIC, no packet format preference and all HDT rates, and exposed through the MGMT system configuration TLVs 0x0021-0x0023 so userspace can change them; changing them while the controller is up sends the command again.

The default MIC length also applies when a connection did not request
one: to LE Enable Encryption v2, LE Set CIG Parameters v2 and LE Create BIG v2, and to the L2CAP channels, so ACL, CIS and BIS are set up with the MIC length the host was told to use.

---
 include/net/bluetooth/hci.h      |  7 +++++
 include/net/bluetooth/hci_core.h |  3 +++
 net/bluetooth/hci_core.c         |  3 +++
 net/bluetooth/hci_sync.c         | 37 ++++++++++++++++++++++++---
 net/bluetooth/l2cap_core.c       | 19 +++++++++-----
 net/bluetooth/mgmt_config.c      | 44 ++++++++++++++++++++++++++++++++
 6 files changed, 104 insertions(+), 9 deletions(-)
include/net/bluetooth/hci.h +7 -0
index e9bbd687b12e..af8a20682e31 100644
@@ -2664,6 +2664,13 @@ struct hci_cp_le_create_big_v2 {
 	struct hci_bis_v2 bis;
 } __packed;
 
+#define HCI_OP_LE_SET_HDT_DEFAULT_PARAMS	0x20bc
+struct hci_cp_le_set_hdt_default_params {
+	__u8    mic_len;
+	__u8    format;
+	__le16  rates;
+} __packed;
+
 /* ---- HCI Events ---- */
 struct hci_ev_status {
 	__u8    status;
include/net/bluetooth/hci_core.h +3 -0
index d1c6ae23714d..def547e1b7f1 100644
@@ -433,6 +433,9 @@ struct hci_dev {
 	__u8		hdt_max_tx_win;
 	__u8		hdt_max_rx_win;
 	__u8		hdt_max_rx_packet;
+	__u8		hdt_def_mic_len;
+	__u8		hdt_def_format;
+	__u16		hdt_def_rates;
 	__u8		le_max_key_size;
 	__u8		le_min_key_size;
 	__u16		discov_interleaved_timeout;
net/bluetooth/hci_core.c +3 -0
index bfc5bdebc71a..a4014bbcdfc2 100644
@@ -2575,6 +2575,9 @@ struct hci_dev *hci_alloc_dev_priv(int sizeof_priv)
 	hdev->le_min_key_size = SMP_MIN_ENC_KEY_SIZE;
 	hdev->le_tx_def_phys = HCI_LE_SET_PHY_1M;
 	hdev->le_rx_def_phys = HCI_LE_SET_PHY_1M;
+	hdev->hdt_def_mic_len = 0x02;	/* 128-bit */
+	hdev->hdt_def_format = 0x00;	/* No preference */
+	hdev->hdt_def_rates = 0x001f;	/* All defined HDT rates */
 	hdev->le_num_of_adv_sets = HCI_MAX_ADV_INSTANCES;
 	hdev->def_multi_adv_rotation_duration = HCI_DEFAULT_ADV_DURATION;
 	hdev->def_le_autoconnect_timeout = HCI_LE_CONN_TIMEOUT;
net/bluetooth/hci_sync.c +34 -3
index 5f743cf362e5..b2b1a553e7c2 100644
@@ -5412,11 +5412,40 @@ static int hci_le_set_default_phy_sync(struct hci_dev *hdev)
 				     sizeof(cp), &cp, HCI_CMD_TIMEOUT);
 }
 
+static int hci_le_set_hdt_params_sync(struct hci_dev *hdev)
+{
+	struct hci_cp_le_set_hdt_default_params cp;
+	u16 rates;
+
+	/* Only send if controller supports HDT and the command */
+	if (!hdt_capable(hdev) || !(hdev->commands[52] & BIT(1)))
+		return 0;
+
+	/* Compute supported rates based on controller capabilities */
+	rates = hdev->hdt_def_rates;
+
+	/* Mask out rates not supported by the controller */
+	if (!hdt_6_tx_capable(hdev))
+		rates &= ~BIT(3);
+	if (!hdt_7_5_tx_capable(hdev))
+		rates &= ~BIT(4);
+
+	memset(&cp, 0, sizeof(cp));
+	cp.mic_len = hdev->hdt_def_mic_len;
+	cp.format = hdev->hdt_def_format;
+	cp.rates = cpu_to_le16(rates);
+
+	return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_HDT_DEFAULT_PARAMS,
+				     sizeof(cp), &cp, HCI_CMD_TIMEOUT);
+}
+
 static const struct hci_init_stage le_init4[] = {
 	/* HCI_OP_LE_WRITE_DEF_DATA_LEN */
 	HCI_INIT(hci_le_set_write_def_data_len_sync),
 	/* HCI_OP_LE_SET_DEFAULT_PHY */
 	HCI_INIT(hci_le_set_default_phy_sync),
+	/* HCI_OP_LE_SET_HDT_DEFAULT_PARAMS */
+	HCI_INIT(hci_le_set_hdt_params_sync),
 	{}
 };
 
@@ -8431,7 +8460,8 @@ static int hci_le_set_cig_params_v2_sync(struct hci_dev *hdev, u8 cig_id)
 				   qos->ucast.in.rates;
 		cis->p_hdt_rates = qos->ucast.in.rates ? qos->ucast.in.rates :
 				   qos->ucast.out.rates;
-		cis->mic_len = 0x02; /* Always prefer 128 bits? */
+		cis->mic_len = conn->mic_len ? conn->mic_len :
+			       hdev->hdt_def_mic_len;
 
 		/* If HDT PHY is set but rates are not set then enable all HDT
 		 * supported rates.
@@ -8559,6 +8589,7 @@ static int hci_le_create_big_v2_sync(struct hci_conn *conn,
 	cp.bis.encryption = qos->bcast.encryption;
 	memcpy(cp.bis.bcode, qos->bcast.bcode, sizeof(cp.bis.bcode));
 	cp.bis.hdt_rates = qos->bcast.out.rates ? qos->bcast.out.rates : 0x00;
+	cp.bis.mic_len = conn->mic_len ? conn->mic_len : hdev->hdt_def_mic_len;
 
 	/* If HDT PHY is set but rates are not set then enable all HDT
 	 * supported rates.
@@ -8636,8 +8667,8 @@ static int hci_le_enable_encrypt_v2(struct hci_conn *conn, __le16 ediv,
 	cp->handle = cpu_to_le16(conn->handle);
 	cp->rand = rand;
 	cp->ediv = ediv;
-	/* Use requested mic_len from hcon, default to 128 bits if unset */
-	cp->mic_len = conn->mic_len ? conn->mic_len : 0x02;
+	/* Use requested mic_len from hcon if set; otherwise use hdev default */
+	cp->mic_len = conn->mic_len ? conn->mic_len : hdev->hdt_def_mic_len;
 
 	if (ltk) {
 		memcpy(cp->ltk, ltk, sizeof(cp->ltk));
net/bluetooth/l2cap_core.c +13 -6
index 4abb4b28ddec..73712db05e14 100644
@@ -1030,19 +1030,26 @@ static inline u8 l2cap_get_auth_type(struct l2cap_chan *chan)
 int l2cap_chan_check_security(struct l2cap_chan *chan, bool initiator)
 {
 	struct l2cap_conn *conn = chan->conn;
+	struct hci_conn *hcon = conn->hcon;
 	__u8 auth_type;
 
-	if (conn->hcon->type == LE_LINK) {
-		/* Propagate mic_len requirement to hcon for encrypt_v2 */
-		if (chan->mic_len > conn->hcon->mic_len)
-			conn->hcon->mic_len = chan->mic_len;
+	if (hcon->type == LE_LINK) {
+		/* Propagate mic_len requirement to hcon for encrypt_v2.
+		 * Use chan->mic_len if set, otherwise fall back to the
+		 * device default HDT MIC length.
+		 */
+		u8 mic_len = chan->mic_len ? chan->mic_len :
+					     hcon->hdev->hdt_def_mic_len;
+
+		if (mic_len > hcon->mic_len)
+			hcon->mic_len = mic_len;
 
-		return smp_conn_security(conn->hcon, chan->sec_level);
+		return smp_conn_security(hcon, chan->sec_level);
 	}
 
 	auth_type = l2cap_get_auth_type(chan);
 
-	return hci_conn_security(conn->hcon, chan->sec_level, auth_type,
+	return hci_conn_security(hcon, chan->sec_level, auth_type,
 				 initiator);
 }
 
net/bluetooth/mgmt_config.c +44 -0

88 lines not on this page · raw message

Signature · 1 line
2.56.0
author maintainer
#8 lore raw

PATCH 6/6 Bluetooth: Add EKS Opportunistic Encryption support

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Add support for opportunistic encryption with Encryption Key Schedule, which encrypts a link without pairing when both devices support it:

- The Opportunistic Encryption (Host Support) feature bit (Link Layer feature bit 90) is set with LE Set Host Feature during initialization, and eks_oppt_capable() checks the remote supports it.
- When the remote features are read as Central and there is no LTK for the peer, LE Enable Encryption v2 is sent with Encryption set to opportunistic. The checks are repeated right before the command is sent, so it is skipped if the link is gone, already encrypted or SMP pairing has started in the meantime, since encrypting the link under SMP would break the pairing.
- An opportunistically encrypted link does not raise the security level, as it is not authenticated.
- The feature can be turned off with the MGMT system configuration TLV 0x0024; it is on by default.

---
 include/net/bluetooth/hci.h      |  1 +
 include/net/bluetooth/hci_core.h |  5 ++
 include/net/bluetooth/hci_sync.h |  1 +
 net/bluetooth/hci_core.c         |  1 +
 net/bluetooth/hci_event.c        |  7 ++-
 net/bluetooth/hci_sync.c         | 92 +++++++++++++++++++++++++++++++-
 net/bluetooth/mgmt_config.c      |  5 ++
 net/bluetooth/smp.c              | 23 ++++++++
 net/bluetooth/smp.h              |  2 +
 9 files changed, 135 insertions(+), 2 deletions(-)
include/net/bluetooth/hci.h +1 -0
index af8a20682e31..bcd2f5aa1987 100644
@@ -668,6 +668,7 @@ enum {
 #define HCI_LE_HDT_7_5_TX_FEATURE	BIT(1)
 #define HCI_LE_HDT_PF_1			BIT(2)
 #define HCI_LE_HDT_LQF_FEATURE		BIT(3)
+#define HCI_LE_OPPORTUNISTIC_ENC	BIT(2)	/* Byte 3 */
 
 /* Connection modes */
 #define HCI_CM_ACTIVE	0x0000
include/net/bluetooth/hci_core.h +5 -0
index def547e1b7f1..fe43a968eabe 100644
@@ -436,6 +436,7 @@ struct hci_dev {
 	__u8		hdt_def_mic_len;
 	__u8		hdt_def_format;
 	__u16		hdt_def_rates;
+	bool		eks_oppt;
 	__u8		le_max_key_size;
 	__u8		le_min_key_size;
 	__u16		discov_interleaved_timeout;
@@ -2196,6 +2197,10 @@ static inline __u8 hci_conn_mic_len(struct hci_conn *conn)
 #define eks_capable(dev) \
 	(le_feature(dev, 1, 1) & HCI_LE_EKS_FEATURE)
 
+#define eks_oppt_capable(dev) \
+	(eks_capable(dev) && \
+	 (le_feature(dev, 1, 3) & HCI_LE_OPPORTUNISTIC_ENC))
+
 /* Channel sounding support */
 #define le_cs_capable(dev) \
 	((dev)->le_features[5] & HCI_LE_CS)
include/net/bluetooth/hci_sync.h +1 -0
index 4b5baee9ce11..5f74af68730b 100644
@@ -200,3 +200,4 @@ int hci_le_create_big_sync(struct hci_conn *conn, struct bt_iso_qos_v2 *qos,
 
 int hci_le_enable_encrypt(struct hci_conn *conn, __le16 ediv, __le64 rand,
 			  __u8 ltk[16], __u8 key_size);
+int hci_le_eks_oppt_encrypt(struct hci_conn *conn);
net/bluetooth/hci_core.c +1 -0
index a4014bbcdfc2..06e676eed468 100644
@@ -2578,6 +2578,7 @@ struct hci_dev *hci_alloc_dev_priv(int sizeof_priv)
 	hdev->hdt_def_mic_len = 0x02;	/* 128-bit */
 	hdev->hdt_def_format = 0x00;	/* No preference */
 	hdev->hdt_def_rates = 0x001f;	/* All defined HDT rates */
+	hdev->eks_oppt = true;		/* Opportunistic encryption enabled */
 	hdev->le_num_of_adv_sets = HCI_MAX_ADV_INSTANCES;
 	hdev->def_multi_adv_rotation_duration = HCI_DEFAULT_ADV_DURATION;
 	hdev->def_le_autoconnect_timeout = HCI_LE_CONN_TIMEOUT;
net/bluetooth/hci_event.c +6 -1
index be8b480e6ab7..4037ee6cf885 100644
@@ -3732,7 +3732,6 @@ static void hci_change_encrypt(struct hci_conn *conn, u8 status, u8 encrypt,
 
 	if (!status) {
 		if (encrypt) {
-			/* Encryption implies authentication */
 			set_bit(HCI_CONN_AUTH, conn->flags);
 			set_bit(HCI_CONN_ENCRYPT, conn->flags);
 			conn->sec_level = conn->pending_sec_level;
@@ -3881,6 +3880,10 @@ static void hci_encrypt_change_v3_evt(struct hci_dev *hdev, void *data,
 	if (!conn)
 		goto unlock;
 
+	/* EKS Opportunistic (eks_mode 0x02) provides no security change */
+	if (ev->eks_mode == 0x02)
+		goto unlock;
+
 	hci_change_encrypt(conn, ev->status, ev->mode, ev->key_size,
 			   ev->mic_len);
 
@@ -7867,6 +7870,8 @@ static void hci_le_read_all_remote_features_evt(struct hci_dev *hdev,
 			conn->le_tx_def_phys &= ~HCI_LE_SET_PHY_HDT;
 			conn->le_rx_def_phys &= ~HCI_LE_SET_PHY_HDT;
 		}
+
+		hci_le_eks_oppt_encrypt(conn);
 	}
 
 	if (conn->state == BT_CONFIG) {
net/bluetooth/hci_sync.c +91 -1

103 lines not on this page · raw message

net/bluetooth/mgmt_config.c +5 -0
index f5b37b0cd975..1b9b823355b4 100644
@@ -94,6 +94,7 @@ int read_def_system_config(struct sock *sk, struct hci_dev *hdev, void *data,
 		HDEV_PARAM_U8(hdt_def_mic_len);
 		HDEV_PARAM_U8(hdt_def_format);
 		HDEV_PARAM_U16(hdt_def_rates);
+		HDEV_PARAM_U8(eks_oppt);
 	} __packed rp = {
 		TLV_SET_U16(0x0000, def_page_scan_type),
 		TLV_SET_U16(0x0001, def_page_scan_int),
@@ -131,6 +132,7 @@ int read_def_system_config(struct sock *sk, struct hci_dev *hdev, void *data,
 		TLV_SET_U8(0x0021, hdt_def_mic_len),
 		TLV_SET_U8(0x0022, hdt_def_format),
 		TLV_SET_U16(0x0023, hdt_def_rates),
+		TLV_SET_U8(0x0024, eks_oppt),
 	};
 
 	bt_dev_dbg(hdev, "sock %p", sk);
@@ -372,6 +374,9 @@ int set_def_system_config(struct sock *sk, struct hci_dev *hdev, void *data,
 		case 0x0023:
 			hdev->hdt_def_rates = TLV_GET_LE16(buffer);
 			break;
+		case 0x0024:
+			hdev->eks_oppt = !!TLV_GET_U8(buffer);
+			break;
 		default:
 			bt_dev_warn(hdev, "unsupported parameter %u", type);
 			break;
net/bluetooth/smp.c +23 -0
index 0dc236cd4d1c..112100e790cd 100644
@@ -2444,6 +2444,29 @@ int smp_conn_security(struct hci_conn *hcon, __u8 sec_level)
 	return ret;
 }
 
+bool smp_pairing_in_progress(struct hci_conn *hcon)
+{
+	struct l2cap_conn *conn;
+	struct l2cap_chan *chan;
+	bool pending;
+
+	lockdep_assert_held(&hcon->hdev->lock);
+
+	conn = hcon->l2cap_data;
+	if (!conn)
+		return false;
+
+	chan = conn->smp;
+	if (!chan)
+		return false;
+
+	l2cap_chan_lock(chan);
+	pending = !!chan->data;
+	l2cap_chan_unlock(chan);
+
+	return pending;
+}
+
 int smp_cancel_and_remove_pairing(struct hci_dev *hdev, bdaddr_t *bdaddr,
 				  u8 addr_type)
 {
net/bluetooth/smp.h +2 -0
index c86c46389007..0537762e2775 100644
@@ -185,6 +185,8 @@ int smp_cancel_and_remove_pairing(struct hci_dev *hdev, bdaddr_t *bdaddr,
 bool smp_sufficient_security(struct hci_conn *hcon, u8 sec_level,
 			     enum smp_key_pref key_pref);
 int smp_conn_security(struct hci_conn *hcon, __u8 sec_level);
+bool smp_pairing_in_progress(struct hci_conn *hcon)
+	__must_hold(&hcon->hdev->lock);
 int smp_user_confirm_reply(struct hci_conn *conn, u16 mgmt_op, __le32 passkey)
 	__must_hold(&conn->hdev->lock);
 
Signature · 1 line
2.56.0
#9 lore raw
In reply to Luiz Augusto von Dentz

This is an automated email and please do not reply to this email.

Dear Submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
While preparing the CI tests, the patches you submitted couldn't be applied to the current HEAD of the repository.

----- Output -----

hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To record the empty patch as an empty commit, run "git am --allow-empty".
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"

Please resolve the issue and submit the patches again.

---
Regards,
Linux Bluetooth