From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v7 0/4] L2CAP: Fix channels being established with insufficient security
Date: Wed, 25 Nov 2026 16:12:06 -0500 [thread overview]
Message-ID: <20261125211210.1955598-1-luiz.dentz@gmail.com> (raw)
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
l2cap_security_cfm() lowers the security level of a channel to the one
of the link when encryption completes, and accepts channels waiting for
the security to be met as long as the status is success, so a channel
can end up established, or be offered to a listener using
BT_DEFER_SETUP, over a link that doesn't meet the security level it
requires, e.g. if the peer disables encryption while the channel waits
for userspace to authorize it.
The first two patches fix the handling of Enhanced Credit Based requests
when only some of their channels are refused, e.g. when the listener
limits the number of channels: the response accepts the channels that
were authorized instead of rejecting all of them, and the socket of a
refused channel is no longer leaked. The refusal done by the third patch
relies on them.
The third patch makes l2cap_security_cfm() compare the security level
of the link with the one required by the channel, which is now kept
apart from the one of the link in min_sec_level: encryption completing
below it is a downgrade, so the channel is no longer lowered to match
it but disconnected, or refused if it was still pending, and the link is
disconnected if the channel is a fixed one since it can't be
disconnected at L2CAP. Channels waiting to be accepted or started only
proceed if the link is encrypted and meets their security level, and
deferred LE and Enhanced Credit Based channels are refused when
userspace authorizes them if it no longer does.
The fourth patch makes a BR/EDR channel visible to the listener only
once it is offered to it, after the security is met, instead of as soon
as the connection request is responded as pending, so a listener that
accepts without waiting to be notified can't authorize a connection
while authentication is still pending.
Tests for both are sent to the BlueZ mailing list as "[PATCH BlueZ v4
0/5] Add tests for security of deferred setup".
A channel requiring a security level that pairing can't provide, e.g.
BT_SECURITY_HIGH when the IO capability is NoInputNoOutput, is now
refused instead of being connected with the security level the link
ended up with.
v7:
- Add a patch fixing the response to an Enhanced Credit Based request
rejecting all of its channels, including the ones accepted, when only
some of them are refused.
- Add a patch fixing the socket of a refused Enhanced Credit Based
channel being leaked when the others of the request are still pending.
- Authentication completing before encryption is enabled is not
considered encryption being disabled: channels in BT_CONNECT and
BT_CONNECT2 wait for it, and fixed channels are not disconnected.
- Also refuse outgoing channels in BT_CONNECT on a downgrade when the
connection request was already sent.
- Restore the security level requirement of a channel if setting it
with BT_SECURITY fails.
v6:
- Evaluate the requirement of the channel in l2cap_security_cfm() after
taking chan->lock, since it can be changed by setsockopt() meanwhile.
- Treat encryption being disabled as a downgrade for fixed channels,
since l2cap_check_encryption() doesn't handle them, and don't resume
channels the link doesn't meet the security level of.
- Also refuse outgoing channels in BT_CONNECT on a downgrade.
- Close a deferred channel refused when userspace authorizes it with the
channel kept locked, so it can't be authorized by another thread
meanwhile.
v5:
- Require the link to be encrypted for channels above
BT_SECURITY_LOW, since the security level of the link is updated when
authentication completes, before encryption is enabled.
- Disconnect the link if a fixed channel is downgraded no matter its
state, so one still waiting for security doesn't bypass it.
- Keep the security level required by a channel in min_sec_level
instead of comparing with sec_level, which follows the one of the
link, so channels that only asked for BT_SECURITY_LOW, like SMP, are
not considered downgraded when the link is paired again with a lower
security level.
- Refuse deferred LE Credit Based and Enhanced Credit Based channels
when userspace authorizes them if the link doesn't meet their
security level, instead of closing them from l2cap_security_cfm(),
since rejecting an Enhanced Credit Based channel deletes the others
of the same request.
- Refuse deferred LE Credit Based channels in l2cap_security_cfm() when
the link doesn't meet their security level.
v4:
- Disconnect the link instead of the channel if a fixed channel is
downgraded, since it can't be disconnected at L2CAP.
- Call chan->ops->close() when a channel was deleted by the downgrade,
so its socket is not leaked, and also refuse deferred LE Credit
Based channels in BT_CONNECT2.
- Only start channels in BT_CONNECT if the link meets their security
level.
v3:
- Don't use l2cap_chan_check_security(), which may start
authentication or encryption, compare the security levels instead.
- Treat encryption completing below the security level of a channel as
a downgrade and disconnect it instead of lowering its security
level.
- Only let accept() return children in BT_CONNECT2, as
bt_accept_poll() does.
v2:
- Drop BT_SK_ACCEPTED and the changes to l2cap_sock_defer().
- Add the second patch for listeners accepting while the security is
still pending.
Luiz Augusto von Dentz (3):
Bluetooth: L2CAP: Fix rejecting all Enhanced Credit channels if one is
refused
Bluetooth: L2CAP: Fix leaking the socket of refused Enhanced Credit
channels
Bluetooth: L2CAP: Don't offer deferred channels before security is met
Mohammed Alquraini (1):
Bluetooth: L2CAP: Fix accepting channels with insufficient security
include/net/bluetooth/l2cap.h | 7 ++
net/bluetooth/af_bluetooth.c | 6 +-
net/bluetooth/l2cap_core.c | 204 +++++++++++++++++++++++++++++++---
net/bluetooth/l2cap_sock.c | 54 +++++++--
net/bluetooth/rfcomm/core.c | 1 +
5 files changed, 246 insertions(+), 26 deletions(-)
--
2.56.0
next reply other threads:[~2026-11-25 21:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 21:12 Luiz Augusto von Dentz [this message]
2026-11-25 21:12 ` [PATCH v7 1/4] Bluetooth: L2CAP: Fix rejecting all Enhanced Credit channels if one is refused Luiz Augusto von Dentz
2026-11-26 3:44 ` L2CAP: Fix channels being established with insufficient security bluez.test.bot
2026-11-25 21:12 ` [PATCH v7 2/4] Bluetooth: L2CAP: Fix leaking the socket of refused Enhanced Credit channels Luiz Augusto von Dentz
2026-11-25 21:12 ` [PATCH v7 3/4] Bluetooth: L2CAP: Fix accepting channels with insufficient security Luiz Augusto von Dentz
2026-11-25 21:12 ` [PATCH v7 4/4] Bluetooth: L2CAP: Don't offer deferred channels before security is met Luiz Augusto von Dentz
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=20261125211210.1955598-1-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