public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ] shared/att: make att channel respect LE socket security level
@ 2026-02-02 15:32 Lasan Mahaliyana
  2026-02-02 16:36 ` [BlueZ] " bluez.test.bot
  2026-02-02 16:41 ` [PATCH BlueZ] " Luiz Augusto von Dentz
  0 siblings, 2 replies; 3+ messages in thread
From: Lasan Mahaliyana @ 2026-02-02 15:32 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.dentz, Lasan Mahaliyana

This prevents unwanted pairing requests instances where gatt-client tries
to read gatt characteristics that require higher security levels than
defined for the LE socket.

For example connecting to an LE L2CAP CoC socket with BT_SECURITY_LOW,
one would expect to not require pairing. But as the gatt-client starts
automatically for the initiator, if it tries to read characteristics which
require higher security levels, it fails and tries to elevate security
level. Which would prompt pairing.

Which makes it impossible to initiate a LE L2CAP CoC socket with
BT_SECURITY_LOW with some devices.
---
 src/shared/att.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/shared/att.c b/src/shared/att.c
index 77ca4aa24..ac527fccf 100644
--- a/src/shared/att.c
+++ b/src/shared/att.c
@@ -1193,6 +1193,23 @@ static uint8_t io_get_type(int fd)
 	return BT_ATT_LE;
 }
 
+static int io_get_security(int fd)
+{
+	struct bt_security sec;
+	socklen_t len;
+
+	if (!is_io_l2cap_based(fd))
+		return BT_ATT_SECURITY_LOW;
+
+	memset(&sec, 0, sizeof(sec));
+	len = sizeof(sec);
+
+	if (getsockopt(fd, SOL_BLUETOOTH, BT_SECURITY, &sec, &len) < 0)
+		return BT_ATT_SECURITY_AUTO;
+
+	return sec.level;
+}
+
 static struct bt_att_chan *bt_att_chan_new(int fd, uint8_t type)
 {
 	struct bt_att_chan *chan;
@@ -1219,6 +1236,10 @@ static struct bt_att_chan *bt_att_chan_new(int fd, uint8_t type)
 		chan->sec_level = BT_ATT_SECURITY_LOW;
 		/* fall through */
 	case BT_ATT_LE:
+		/* respect the current L2CAP socket security level */
+		if (chan->type == BT_ATT_LE)
+			chan->sec_level = io_get_security(fd);
+
 		chan->mtu = BT_ATT_DEFAULT_LE_MTU;
 		break;
 	default:
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-02-02 16:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-02 15:32 [PATCH BlueZ] shared/att: make att channel respect LE socket security level Lasan Mahaliyana
2026-02-02 16:36 ` [BlueZ] " bluez.test.bot
2026-02-02 16:41 ` [PATCH BlueZ] " Luiz Augusto von Dentz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox