From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796151814; b=1dvfLMaZcpmbmYkamXBywasDWZBFPIajDzpHoAxchQFNTjJ7kV8HPQDLX2ARRMJk014r oL7WxZBadLWA7jGOLAOJJ/Y2/AjgOIoHxbL3al3005If0vx7gXKqeHYdF6ykyqVkpNCZb 2mw+Ul9N18Va2XXDu2if6bPeRzKeyDMX7ErNfvRjh5uybbLePHwc3rY/7WEcUkMLUnDs2 q14frXHUpKpfjb5FUUhlJhAc7SRulXaHysbz1w8WaHSI9q74QXPQ0pA/CiK+VjZXXEq5k dvdQun/xfEsr1Ca36LxegRGVKGOAvrbBUVEEgRH5BM5QTKkdNiRiFpql/ees7UAQ67g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796151814; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Subject:Date: Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=O8NkacMaamZ5ZMdmUkKM65iMka9EM3WZy977KnHkUdc=; b=txwJQgOeUOR9UbgH0zjwFd3p4+pGW9MaXFBcObVWnexmNC3TMWyQVIpyygALZ6U5t/e/ 1nnkkRn9/34BXQheJ+lU5E3jMkON1Yp7xdKF1f3z0fFHOI78kPmnfYyKjEbeZ0zBwWyvX zF8k0EOR5WE/O59B7M0I7lAaNFBDmyv7zrP2GKSU3OgZ+cec1DHH3ErShPEmXixLb9MVS lEwe/LfMWfNUH6sxCKIWu4lDKHHptta7VuptoC98Jyz18q4/ORMR18v159Pc7QgmMlou5 GFIzM7a3h7EK4Y4o4/lMyQ8z2jF8Qjw4fk6+rD+LoxMP+G7WCOAicQF8ZSbtWMeT3NA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=HBlmaFMw; arc=none smtp.remote-ip=209.85.222.48 Received: from mail-ua1-f48.google.com (mail-ua1-f48.google.com [209.85.222.48]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCE5E606A320 for ; Tue, 1 Dec 2026 19:03:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BCE5E606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=HBlmaFMw Received: by mail-ua1-f48.google.com with SMTP id a1e0cc1a2514c-99e1b352df9so3475110241.1 for ; Tue, 01 Dec 2026 11:03:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796151813; x=1796756613; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=O8NkacMaamZ5ZMdmUkKM65iMka9EM3WZy977KnHkUdc=; b=HBlmaFMw0p+xYF/3yhhgeDazm7KcfuRKV0WaMzHgZcJMpvs4hcYncJYMfM/76+BTxa CaSF2+n+Wvt4DD3qYtsgg/lvaMmWDOKQrH0MRNlqPknFsEgQGPfRrhCI5R5xYO3hFCwd dyljuJdwnKbcZvEWfDdOb95+xQccPm7m6YBlXkTWFi1zKBl9bHYp93ytuX1Jd5hMxDQv P8uqlERsrA7yhn7bO1DYt6RJQ3zkYCe8pOqxvBK759heDpKDmq1n4Nxx/CqrYlS54viR R84WMWkSkqWffAU4WkyXyfZkxeYyQ3FQSBGPTM4+3XmKLxDWzmrKEaJVDI6FbgFXY/Ib JfOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796151813; x=1796756613; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=O8NkacMaamZ5ZMdmUkKM65iMka9EM3WZy977KnHkUdc=; b=m7ya47o6mgVCLL49NofhG0qtD6p9WzZ+FoCdXYX2V+y4Fu8YB2TmdP3QLO25+w/p7A rOFrtL0qALibv1cV83gEAqWVmmPOKxsDzX4z9KN9/pCVcSwvPX2u6cxiypXcikAeT7Pc 2w5xododgnbYNCbWBUisGs2sZr2mx5CNdwSg1Kr6sxu2yZe5WGz38tmhymepm2hwK+Z1 sr4qURYymagdyEw35U5ePzw5YW4gRjdoVtAVAyg0vg6V9GlL3/e0twfdFZcAP0yVBuKL 9l2dbE350AwfoJo9J/aK6hS/qxrvOzCtbC+viwT52ZE/M64NJ/qlt/zgwrRezqaqDWoD jWPA== X-Gm-Message-State: APuU4Z8k/wdhGOus/4E4UJfg73PF/m+MKMd6UXDlijDHbNwtFuXCFk56 vUquQZWzPH4aPPkvtXX5wU1QQgvMzM4BzhWecdj7R4jwVSOPZNOj5rtrztcoxAmxxwY= X-Gm-Gg: AZFdTZdrvaUZlYCcEBn8Oc87k+q5jRio5J93kdLEd+0LrOyP/bynIM4kiFNeAv9+KWq vtQyw+3gNFZ/TwfRK9jRwCzKZjUUjaHG+jto++T3x+PgI2lIYjBvdhnD9X17Oiz5yrK7XLWvO1m LxiC0mgiXcdAwdCCwyYrvhMwa/Tb8nG3GbCo0HFQzSJczMiNzJ3ss6MnB/uIlNo7uMLLrNmk0vs 03mQiG2QeHXG4FB33C1uqPgMscidiUNhUGhaUTnieBWuef1rMUHL34kBN5qUVRucOcKH/1+kPrE zjIp35EqFiv1UqeWxZ+n3B59aYs1bijdBrWAqumAZWHD+EH2VEixAG7zJX80nhAeLnVzTZBXAsF AwpNARql5W0z3YDOnvPCvZiyRT0FdmlGSCbPyZrwgCOI4tJuWLgEF1grtNvEnxGsjSkQU1kzoWa GrnV8zJBmLzkAJ6EZxjEyZDQnXW16TB8GxiQaJ8r6cdWGhNfRK7pj7hXj6RZPiYhv1fLcPCYc9n sO5oWS5Dj/A1I3F9FQCmaDm7knqSBJ3R48Gsa9ZpWgEUy/O8PBt/i7PEBjNVv6wRHS9JYX7c+kZ FgVEXu2acLeru4N7VEnoDY0V8B0dN+QD9dgC9Cjj90IRPmuB4LyzN4IqyOtNiUNnqOnN4FILYpJ QnU3vlEj6vSWc4WFK9vtMlZV8O2cN19tmLy6PtDM5H7d1L07AYLLtPCUlCI+rdABsT26pcHm0BF 7p X-Received: by 2002:a05:6102:41ab:b0:7cc:2152:4f79 with SMTP id ada2fe7eead31-7d73943e0b5mr23291421137.16.1796151812202; Tue, 01 Dec 2026 11:03:32 -0800 (PST) Received: from lvondent-mobl5 ([72.188.211.115]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-99e6dfc0b22sm38919229241.6.2026.12.01.11.03.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 11:03:31 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v12 0/6] L2CAP: Fix channels being established with insufficient security Date: Tue, 1 Dec 2026 14:03:19 -0500 Message-ID: <20261201190325.110874-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.56.1 X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Luiz Augusto von Dentz 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 patch disconnects the link when the encryption key size couldn't be read or is too small, since the upper layers were only notified of the error, leaving the channels already established open over a link that is no longer encrypted. The second patch fixes deferred LE Credit Based and Enhanced Credit Based channels being disconnected by their timer once accepted, since they were moved to BT_CONNECTED without stopping it. The third and fourth 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 fifth patch relies on them. The fifth 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 sixth 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. The tests are sent to the BlueZ mailing list as "[PATCH BlueZ v4 0/6] Add tests for security of deferred setup", which also updates L2CAP BR/EDR Client SSP - Success 2 to set an IO capability that allows the BT_SECURITY_HIGH it requests, otherwise it fails with this series since the channel is no longer connected with a lower security level. 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. v12: - Suspend a deferred Enhanced Credit Based channel when it is authorized until the response of its request is sent, so it can't send data before it, and purge the queue of a refused channel. - Lock the socket in l2cap_sock_resume_cb() with the nesting level of the channel, since the response now resumes sibling channels. - Resume a deferred channel suspended for a security level requested with BT_SECURITY once it is met. - Annotate __l2cap_le_connect_rsp_defer() with the locks it requires. v11: - Lock the socket killed from l2cap_sock_teardown_cb() with the nesting level of the channel, like the rest of it, since it can be called with a sibling channel locked, which lockdep reported. v10: - Add a patch stopping the timer of deferred LE Credit Based and Enhanced Credit Based channels once accepted, which disconnected them after being established. - Decide whether each channel of an Enhanced Credit Based request is accepted only once, when building the response, and derive the result from it, instead of counting them first, which could disagree. - Only set the security level requested with BT_SECURITY once it is accepted instead of restoring it if it fails, so a transient value is never seen by the other channels. - Disconnect the link when a security upgrade requested for a fixed channel fails, since it can't be disconnected at L2CAP. v9: - Decide per channel whether the response to an Enhanced Credit Based request accepts it, so it always has as many destination CIDs as the request even if a channel changes after the result was decided. - Don't delete a refused Enhanced Credit Based channel before the response of its request when it is closed again, e.g. by its owner or its timer, and refuse an accepted one that is closed before the response instead of disconnecting it. - Only leave alone the Enhanced Credit Based channels accepted and waiting for the response in l2cap_security_cfm(), so outgoing deferred ones in BT_CONNECT are still refused when the link doesn't meet their security level, and don't include those in the request of the others. - Check the security level when authorizing any deferred channel, not only LE and Enhanced Credit Based ones. - Disconnect an established channel whose security upgrade failed instead of leaving it suspended. v8: - Add a patch disconnecting the link when the encryption key size is not valid, which was sent separately before. - Only count the channels the response of an Enhanced Credit Based request includes when deciding its result, since idents are not unique among the channels of a connection. - Kill the socket of a channel without an owner from l2cap_sock_teardown_cb() instead of tearing the refused channel down early, which left the channel in the connection without a socket, covering the sockets never accepted as well as the ones released. - Refuse the channels in BT_CONNECT whenever the link doesn't meet their security level, not only on a downgrade, so they are also refused if the connection request was already sent. - Make all the channels wait while the link is waiting for the encryption to be enabled instead of only the pending ones. - Don't disconnect the Enhanced Credit Based channels accepted while the response of their request is pending on a downgrade, since the peer doesn't know about them yet, refuse them in the response instead if the link doesn't meet their security level by then. 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 (5): Bluetooth: hci_event: Disconnect if the encryption key size is not valid Bluetooth: L2CAP: Fix deferred LE channels being disconnected once accepted Bluetooth: L2CAP: Fix rejecting all Enhanced Credit channels if one is refused Bluetooth: L2CAP: Fix leaking sockets released before their channel is deleted 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 | 10 +- net/bluetooth/af_bluetooth.c | 6 +- net/bluetooth/hci_event.c | 8 + net/bluetooth/l2cap_core.c | 280 +++++++++++++++++++++++++++++++--- net/bluetooth/l2cap_sock.c | 89 +++++++++-- net/bluetooth/rfcomm/core.c | 1 + 6 files changed, 361 insertions(+), 33 deletions(-) -- 2.56.1