Skip to contentSkip to conversation

device: Attempt to elevate security on Pair while connected

PATCH Applied Luiz Augusto von Dentz 3 participants 7 messages Mar 26, 2025 – Mar 27, 2025 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH v2 1/5 device: Attempt to elevate security on Pair while connected

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

This would make Pair act behave the same as when the device reconnect and bonding already exists.

---
 src/device.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
src/device.c +4 -1
index 9774b5bf1b96..f76c1ec3eabf 100644
@@ -3194,10 +3194,13 @@ static DBusMessage *pair_device(DBusConnection *conn, DBusMessage *msg,
 
 		if (!state->connected && btd_le_connect_before_pairing())
 			err = device_connect_le(device);
-		else
+		else if (!state->connected || !bt_att_set_security(device->att,
+						BT_ATT_SECURITY_MEDIUM))
 			err = adapter_create_bonding(adapter, &device->bdaddr,
 							device->bdaddr_type,
 							io_cap);
+		else
+			err = 0;
 	} else {
 		err = adapter_create_bonding(adapter, &device->bdaddr,
 							BDADDR_BREDR, io_cap);
Signature · 1 line
2.48.1
author maintainer
#1 lore raw

PATCH v2 2/5 device: Make Connect and Pair mutually exclusive

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

This makes Device.Connect and Device.Pair methods mutually exclusive so they cannot happen in parallel, so just as Connect:Connect and Pair:Pair combinations the Connect:Pair and Pair:Connect will now return org.bluez.Error.InProgress.

---
 src/device.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
src/device.c +7 -1
index f76c1ec3eabf..6a6c379fcbbf 100644
@@ -2629,6 +2629,9 @@ static DBusMessage *dev_connect(DBusConnection *conn, DBusMessage *msg,
 	struct btd_device *dev = user_data;
 	uint8_t bdaddr_type;
 
+	if (dev->bonding)
+		return btd_error_in_progress(msg);
+
 	if (dev->bredr_state.connected) {
 		/*
 		 * Check if services have been resolved and there is at least
@@ -2648,6 +2651,9 @@ static DBusMessage *dev_connect(DBusConnection *conn, DBusMessage *msg,
 	if (bdaddr_type != BDADDR_BREDR) {
 		int err;
 
+		if (dev->connect)
+			return btd_error_in_progress(msg);
+
 		if (dev->le_state.connected)
 			return dbus_message_new_method_return(msg);
 
@@ -3133,7 +3139,7 @@ static DBusMessage *pair_device(DBusConnection *conn, DBusMessage *msg,
 	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_INVALID))
 		return btd_error_invalid_args(msg);
 
-	if (device->bonding)
+	if (device->bonding || device->connect)
 		return btd_error_in_progress(msg);
 
 	/* Only use this selection algorithms when device is combo
Signature · 1 line
2.48.1
author maintainer
#2 lore raw

PATCH v2 3/5 device: Use btd_device_is_initiator instead of Connect message

In reply to Luiz Augusto von Dentz

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

Device.Connect message is not the only way to initiate a connection as there is also the likes of Device.Pair which will initiate bonding, so this incorporate the bonding check into btd_device_is_initiator and replaces the checks of were Connect message was used to determine if initiator to use btd_device_is_initiator.

---
 src/device.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
src/device.c +6 -3
index 6a6c379fcbbf..034491b59d30 100644
@@ -320,6 +320,8 @@ bool btd_device_is_initiator(struct btd_device *dev)
 		return dev->le_state.initiator;
 	else if (dev->bredr_state.connected)
 		return dev->bredr_state.initiator;
+	else if (dev->bonding)
+		return true;
 
 	return dev->att_io ? true : false;
 }
@@ -5780,11 +5782,12 @@ static void gatt_client_init(struct btd_device *device)
 
 	gatt_client_cleanup(device);
 
-	if (!device->connect && !btd_opts.reverse_discovery) {
+	if (!btd_device_is_initiator(device) && !btd_opts.reverse_discovery) {
 		DBG("Reverse service discovery disabled: skipping GATT client");
 		return;
 	}
-	if (!device->connect && !btd_opts.gatt_client) {
+
+	if (!btd_device_is_initiator(device) && !btd_opts.gatt_client) {
 		DBG("GATT client disabled: skipping GATT client");
 		return;
 	}
@@ -5834,7 +5837,7 @@ static void gatt_client_init(struct btd_device *device)
 	 * it shall be triggered only when ready to avoid possible clashes where
 	 * both sides attempt to connection at same time.
 	 */
-	if (device->connect)
+	if (btd_device_is_initiator(device))
 		btd_gatt_client_eatt_connect(device->client_dbus);
 }
 
Signature · 1 line
2.48.1
author maintainer
#3 lore raw

PATCH v2 4/5 shared/att: Make bt_att_set_security never downgrade security level

In reply to Luiz Augusto von Dentz

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

Requesting a lower security level than existing one shall result in no operation since higher security satisfy a lower one and it is never a good practice to allow downgrading security to begin with.

---
 src/shared/att.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
src/shared/att.c +5 -1
index dabbdb4315eb..8657cb6423fb 100644
@@ -727,7 +727,11 @@ static bool bt_att_chan_set_security(struct bt_att_chan *chan, int level)
 {
 	struct bt_security sec;
 
-	if (level == bt_att_chan_get_security(chan))
+	/* Check if security level has already been set, if the security level
+	 * is higher it shall satisfy the request since we never want to
+	 * downgrade security.
+	 */
+	if (level <= bt_att_chan_get_security(chan))
 		return true;
 
 	if (chan->type == BT_ATT_LOCAL) {
Signature · 1 line
2.48.1
author maintainer
#4 lore raw

PATCH v2 5/5 device: Elevate bt_att security if bonding is in progress

In reply to Luiz Augusto von Dentz

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

When bonding is in progress it means Device.Pair has been called thus the user indicated the intend to pair/bond from the start so the security of bt_att shall be set in order for it to wait until pairing process complete before attempting to proceed with GATT discovery and any other traffic.

---
 src/device.c | 5 +++++
 1 file changed, 5 insertions(+)
src/device.c +5 -0
index 034491b59d30..057d116be6fc 100644
@@ -5797,6 +5797,11 @@ static void gatt_client_init(struct btd_device *device)
 	if (btd_opts.gatt_channels > 1)
 		features |= BT_GATT_CHRC_CLI_FEAT_EATT;
 
+	if (device->bonding) {
+		DBG("Elevating security level since bonding is in progress");
+		bt_att_set_security(device->att, BT_ATT_SECURITY_MEDIUM);
+	}
+
 	device->client = bt_gatt_client_new(device->db, device->att,
 						device->att_mtu, features);
 	if (!device->client) {
Signature · 1 line
2.48.1
#5 lore raw
In reply to Luiz Augusto von Dentz

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/project/bluetooth/list/?series=947562

---Test result---

Test Summary:

CheckPatch                    PENDING   0.24 seconds
GitLint                       PENDING   0.26 seconds
BuildEll                      PASS      20.67 seconds
BluezMake                     PASS      1547.48 seconds
MakeCheck                     FAIL      13.31 seconds
MakeDistcheck                 FAIL      144.10 seconds
CheckValgrind                 FAIL      215.07 seconds
CheckSmatch                   PASS      288.33 seconds
bluezmakeextell               PASS      100.38 seconds
IncrementalBuild              PENDING   0.31 seconds
ScanBuild                     PASS      879.29 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: MakeCheck - FAIL
Desc: Run Bluez Make Check
Output:

./test-driver: line 107: 32282 Aborted (core dumped) "$@" > $log_file 2>&1
make[3]: *** [Makefile:11780: test-suite.log] Error 1 make[2]: *** [Makefile:11888: check-TESTS] Error 2 make[1]: *** [Makefile:12317: check-am] Error 2
make: *** [Makefile:12319: check] Error 2
##############################
Test: MakeDistcheck - FAIL
Desc: Run Bluez Make Distcheck
Output:

Package cups was not found in the pkg-config search path. Perhaps you should add the directory containing `cups.pc' to the PKG_CONFIG_PATH environment variable
No package 'cups' found
../../test-driver: line 107: 55085 Aborted (core dumped) "$@" > $log_file 2>&1
make[4]: *** [Makefile:11780: test-suite.log] Error 1 make[3]: *** [Makefile:11888: check-TESTS] Error 2 make[2]: *** [Makefile:12317: check-am] Error 2 make[1]: *** [Makefile:12319: check] Error 2
make: *** [Makefile:12240: distcheck] Error 1
##############################
Test: CheckValgrind - FAIL
Desc: Run Bluez Make Check with Valgrind
Output:

tools/mgmt-tester.c: In function ‘main’:
tools/mgmt-tester.c:12907:5: note: variable tracking size limit exceeded with ‘-fvar-tracking-assignments’, retrying without 12907 | int main(int argc, char *argv[])

      |     ^~~~

./test-driver: line 107: 75123 Aborted (core dumped) "$@" > $log_file 2>&1
make[3]: *** [Makefile:11780: test-suite.log] Error 1 make[2]: *** [Makefile:11888: check-TESTS] Error 2 make[1]: *** [Makefile:12317: check-am] Error 2
make: *** [Makefile:12319: check] Error 2
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:

---
Regards,
Linux Bluetooth

#6 lore raw
In reply to Luiz Augusto von Dentz
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 7 lines · On Wed, 26 Mar 2025 15:31:29 -0400 you wrote:

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

This would make Pair act behave the same as when the device reconnect and bonding already exists.

---
 src/device.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Here is the summary with links:
- [BlueZ,v2,1/5] device: Attempt to elevate security on Pair while connected

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=8e2cece67dbe
  - [BlueZ,v2,2/5] device: Make Connect and Pair mutually exclusive
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=1c2ec29900e4
  - [BlueZ,v2,3/5] device: Use btd_device_is_initiator instead of Connect message
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=45b61a10bd0a
  - [BlueZ,v2,4/5] shared/att: Make bt_att_set_security never downgrade security level
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=ac1f8dd88a46
  - [BlueZ,v2,5/5] device: Elevate bt_att security if bonding is in progress
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=5df9521ce4d5

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html