Skip to contentSkip to conversation

btio: Handle EOPNOTSUPP from accept() to prevent busy loop

PATCH Superseded Luiz Augusto von Dentz 2 participants 5 messages Jun 9 Bluetooth drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/4 btio: Handle EOPNOTSUPP from accept() to prevent busy loop

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

When accept() returns EOPNOTSUPP on an L2CAP SEQPACKET server socket (e.g. AVCTP browsing channel, PSM 0x1b), the error is permanent and retrying will never succeed. Previously, only EBADFD was treated as fatal, causing server_cb to return TRUE for EOPNOTSUPP. Since the fd remains readable, this creates an infinite busy loop that hangs bluetoothd.

Treat EOPNOTSUPP the same as EBADFD by returning FALSE to remove the GLib IO watch and stop the loop.

---
 btio/btio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
btio/btio.c +1 -1
index cfaa9392de12..8d71a210d505 100644
@@ -254,7 +254,7 @@ static gboolean server_cb(GIOChannel *io, GIOCondition cond,
 
 	cli_sock = accept(srv_sock, NULL, NULL);
 	if (cli_sock < 0) {
-		if (errno == EBADFD)
+		if (errno == EBADFD || errno == EOPNOTSUPP)
 			return FALSE;
 		return TRUE;
 	}
Signature · 1 line
2.54.0
author maintainer
#1 lore raw

PATCH 2/4 profile: Check if bearer is enabled on registration

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

btd_profile_register now verifies that the profile's bearer type is compatible with btd_opts.mode before registering. If the required bearer is not enabled (e.g. LE-only profile when mode is BR/EDR, or BR/EDR-only profile when mode is LE), registration is rejected with -ENOTSUP.

---
 src/profile.c | 9 +++++++++
 1 file changed, 9 insertions(+)
src/profile.c +9 -0
index 65df0f7a0969..97fffe9b4d5c 100644
@@ -36,6 +36,7 @@
 #include "dbus-common.h"
 #include "sdp-client.h"
 #include "sdp-xml.h"
+#include "btd.h"
 #include "adapter.h"
 #include "device.h"
 #include "profile.h"
@@ -802,6 +803,14 @@ struct btd_profile *btd_profile_find_remote_uuid(const char *uuid)
 
 int btd_profile_register(struct btd_profile *profile)
 {
+	if ((profile->bearer == BTD_PROFILE_BEARER_LE &&
+				btd_opts.mode == BT_MODE_BREDR) ||
+			(profile->bearer == BTD_PROFILE_BEARER_BREDR &&
+				btd_opts.mode == BT_MODE_LE)) {
+		DBG("Bearer not enabled");
+		return -ENOTSUP;
+	}
+
 	if (profile->experimental && !(g_dbus_get_flags() &
 					G_DBUS_FLAG_ENABLE_EXPERIMENTAL)) {
 		DBG("D-Bus experimental not enabled");
Signature · 1 line
2.54.0
author maintainer
#2 lore raw

PATCH 3/4 plugins: Check btd_profile_register return value

In reply to Luiz Augusto von Dentz

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

Ensure all plugin init functions check the return value of btd_profile_register. If registration fails (e.g. bearer not enabled), the plugin init propagates the error instead of continuing with an unregistered profile.

---
 profiles/audio/a2dp.c      | 14 ++++++++++++--
 profiles/audio/avrcp.c     | 13 +++++++++++--
 profiles/audio/hfp-hf.c    |  4 +---
 profiles/audio/micp.c      |  7 ++++++-
 profiles/input/manager.c   |  4 +---
 profiles/network/manager.c |  5 ++++-
 src/gatt-database.c        |  4 +++-
 7 files changed, 38 insertions(+), 13 deletions(-)
profiles/audio/a2dp.c +12 -2
index c7e0fc75c09e..a5e002784c02 100644
@@ -3798,9 +3798,19 @@ static struct btd_adapter_driver media_driver = {
 
 static int a2dp_init(void)
 {
+	int err;
+
 	btd_register_adapter_driver(&media_driver);
-	btd_profile_register(&a2dp_source_profile);
-	btd_profile_register(&a2dp_sink_profile);
+
+	err = btd_profile_register(&a2dp_source_profile);
+	if (err)
+		return err;
+
+	err = btd_profile_register(&a2dp_sink_profile);
+	if (err) {
+		btd_profile_unregister(&a2dp_source_profile);
+		return err;
+	}
 
 	return 0;
 }
profiles/audio/avrcp.c +11 -2
index b6823753fe68..f63acd47091a 100644
@@ -4987,8 +4987,17 @@ static struct btd_profile avrcp_controller_profile = {
 
 static int avrcp_init(void)
 {
-	btd_profile_register(&avrcp_controller_profile);
-	btd_profile_register(&avrcp_target_profile);
+	int err;
+
+	err = btd_profile_register(&avrcp_controller_profile);
+	if (err)
+		return err;
+
+	err = btd_profile_register(&avrcp_target_profile);
+	if (err) {
+		btd_profile_unregister(&avrcp_controller_profile);
+		return err;
+	}
 
 	populate_default_features();
 
profiles/audio/hfp-hf.c +1 -3
index c91b16426898..8de2d7a62d68 100644
@@ -507,9 +507,7 @@ static struct btd_profile hfp_hf_profile = {
 
 static int hfp_init(void)
 {
-	btd_profile_register(&hfp_hf_profile);
-
-	return 0;
+	return btd_profile_register(&hfp_hf_profile);
 }
 
 static void hfp_exit(void)
profiles/audio/micp.c +6 -1
index 475f32daf75c..3d39ef5e147f 100644
@@ -318,12 +318,17 @@ static unsigned int micp_id;
 
 static int micp_init(void)
 {
+	int err;
+
 	if (!(g_dbus_get_flags() & G_DBUS_FLAG_ENABLE_EXPERIMENTAL)) {
 		DBG("D-Bus experimental not enabled");
 		return -ENOTSUP;
 	}
 
-	btd_profile_register(&micp_profile);
+	err = btd_profile_register(&micp_profile);
+	if (err)
+		return err;
+
 	micp_id = bt_micp_register(micp_attached, micp_detached, NULL);
 
 	return 0;
profiles/input/manager.c +1 -3
index 0fcd6728c2fc..1fd82d82f500 100644
@@ -118,12 +118,10 @@ static int input_init(void)
 
 	}
 
-	btd_profile_register(&input_profile);
-
 	if (config)
 		g_key_file_free(config);
 
-	return 0;
+	return btd_profile_register(&input_profile);
 }
 
 static void input_exit(void)
profiles/network/manager.c +4 -1
index 693547d45fbc..a5f28a99ebfd 100644
@@ -180,7 +180,10 @@ static int network_init(void)
 	if (server_init(conf_security) < 0)
 		return -1;
 
-	btd_profile_register(&panu_profile);
+	err = btd_profile_register(&panu_profile);
+	if (err)
+		return err;
+
 	btd_profile_register(&gn_profile);
 	btd_profile_register(&nap_profile);
 
src/gatt-database.c +3 -1
index 680a52952b16..30e25b6f41ca 100644
@@ -3624,7 +3624,9 @@ static void add_profile(void *data, void *user_data)
 {
 	struct btd_adapter *adapter = user_data;
 
-	btd_profile_register(data);
+	if (btd_profile_register(data))
+		return;
+
 	adapter_add_profile(adapter, data);
 }
 
Signature · 1 line
2.54.0
author maintainer
#3 lore raw

PATCH 4/4 bearer: Check btd_opts.mode on btd_bearer_new

In reply to Luiz Augusto von Dentz

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

Only create the bearer interface if the corresponding transport is enabled. Return NULL if BREDR bearer is requested in LE-only mode or LE bearer in BREDR-only mode, so the D-Bus interface is never registered for unsupported bearers.

---
 src/bearer.c | 5 +++++
 1 file changed, 5 insertions(+)
src/bearer.c +5 -0
index 02267c711431..299eba6e8ab8 100644
@@ -34,6 +34,7 @@
 
 #include "log.h"
 #include "error.h"
+#include "btd.h"
 #include "adapter.h"
 #include "device.h"
 #include "profile.h"
@@ -278,6 +279,10 @@ struct btd_bearer *btd_bearer_new(struct btd_device *device, uint8_t type)
 {
 	struct btd_bearer *bearer;
 
+	if ((type == BDADDR_BREDR && btd_opts.mode == BT_MODE_LE) ||
+			(type != BDADDR_BREDR && btd_opts.mode == BT_MODE_BREDR))
+		return NULL;
+
 	bearer = new0(struct btd_bearer, 1);
 	bearer->device = device;
 	bearer->type = type;
Signature · 1 line
2.54.0
#4 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=1108736

---Test result---

Test Summary:

CheckPatch                    FAIL      1.15 seconds
GitLint                       PASS      0.80 seconds
BuildEll                      PASS      20.44 seconds
BluezMake                     PASS      680.07 seconds
MakeCheck                     PASS      18.48 seconds
MakeDistcheck                 PASS      247.78 seconds
CheckValgrind                 PASS      292.15 seconds
CheckSmatch                   PASS      353.17 seconds
bluezmakeextell               PASS      182.48 seconds
IncrementalBuild              PASS      692.42 seconds
ScanBuild                     PASS      1037.61 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[BlueZ,v1,4/4] bearer: Check btd_opts.mode on btd_bearer_new WARNING:LONG_LINE: line length of 81 exceeds 80 columns #126: FILE: src/bearer.c:283:
+ (type != BDADDR_BREDR && btd_opts.mode == BT_MODE_BREDR))

/github/workspace/src/patch/14620165.patch total: 0 errors, 1 warnings, 17 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/patch/14620165.patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

https://github.com/bluez/bluez/pull/2203

---
Regards,
Linux Bluetooth