public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v5 3/3] Bluetooth: L2CAP: Fix allowing to change security multiple times
Date: Wed,  1 Apr 2026 12:01:53 -0400	[thread overview]
Message-ID: <20260401160153.1980387-3-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20260401160153.1980387-1-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

If FLAG_PENDING_SECURITY is already set it means SMP pairing process
is in progress and hcon->pending_sec_level shouldn't be changed since it
may require to change pairing requirements (MITM), which may not be
supported depending on stage of the pairing procedure, and
may result in a security level that don't match with the pairing keys
authentication (e.g. upgrading to BT_SECURITY_HIGH without setting
MITM requirements).

To fix tis problem the code will now return -EINPROGRESS if a process
call setsockopt(BT_SECURITY) and set FLAG_PENDING_SECURITY it needs to
await the socket to resume and clear the flag before it can update the
security level again.

Fixes: bbb69b37be15 ("Bluetooth: Add return check for L2CAP security level set")
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
v5: New patch to address comments on:
https://sashiko.dev/#/patchset/bt-smp-v4-ea63d24bfcd1416f9da279190fab15fc%401seal.org?patch=14763

 net/bluetooth/l2cap_sock.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 71e8c1b45bce..786ca7c6e272 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -929,6 +929,15 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
 
 		/* change security for LE channels */
 		if (chan->scid == L2CAP_CID_ATT) {
+			/* If security already pending, return error to avoid
+			 * changing the pending_sec_level while the pairing
+			 * procedure is still ongoing.
+			 */
+			if (test_bit(FLAG_PENDING_SECURITY, &chan->flags)) {
+				err = -EINPROGRESS;
+				break;
+			}
+
 			if (smp_conn_security(conn->hcon, sec.level)) {
 				err = -EINVAL;
 				break;
-- 
2.53.0


  parent reply	other threads:[~2026-04-01 16:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-01 16:01 [PATCH v5 1/3] Bluetooth: SMP: force responder MITM requirements before building the pairing response Luiz Augusto von Dentz
2026-04-01 16:01 ` [PATCH v5 2/3] Bluetooth: SMP: derive legacy responder STK authentication from MITM state Luiz Augusto von Dentz
2026-04-01 16:01 ` Luiz Augusto von Dentz [this message]
2026-04-01 16:25 ` [v5,1/3] Bluetooth: SMP: force responder MITM requirements before building the pairing response bluez.test.bot
2026-04-01 19:10 ` [PATCH v5 1/3] " patchwork-bot+bluetooth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260401160153.1980387-3-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox