From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.177 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796138937; b=ap4VPF5Mr0WuE4yo5PhmCn81ZaXGemHtSqfPyAsAQ/ihE9FRDZl5j6275lSkw2+ePvbF UwLS6MnIIF8HtXsaPpKF6lSfZcByygmVMmN3Jx0X31oY/uP7W4Yy+kMxuRA1kw9K8vh7k +eSL5Zn1QijYpSwNhYuxWyzRyWKEpjvvCbFqfNF6x98MU3vYhgvcckiuZ2xh6mxgj6y/A NrWndL1NLcvDRQ9r3Q2vaSSa5ikyXzoSOivtfSialM4mBdJg+bLZ6OeHH8s9aqsH3F8YO XT4H0pUm6CgpNTi+5WmmWT9BksEIjntDarLbCkb7lRXlulSSS3jBjmqdxQz4qqjGmuA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796138937; 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=YHCSOUSpZpZZkp8aHWq682h/ZVWXgYaqR8WH/mdXaEg=; b=nMvldJ8v5hVhZj7a99ENjNRqoRPEaWzzn8lv2yoie5Jnjw0DyLNZf/TTOn6HJ0nFP18s hdGC2oH04ozGO/lgdyaBnFdUHRK6DOjD3nvmNs4FxVEVVXj1S1qOhFy5emXa3Ufmt43Lo Z2HYI09sSJRwyrNR8DlKSShwYwmHXOdZJyGB2YjnJjs+Lc0vWiB2+OL05FHXWBS8EzV1k CW3VQ1fgrY8Vt1J7PRA50PofiN1fuzbkhLaGcuoIR4/eysYMBudGWpocpggzvWCL1gUnh C9yQRcay36v/A+hFNqJK7YEdgGUoxmDGZ7KnQmRaNbbzMBJlvLSQaevwdyyqW1l/ndg== 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=EbzXSKYv; arc=none smtp.remote-ip=209.85.221.177 Received: from mail-vk1-f177.google.com (mail-vk1-f177.google.com [209.85.221.177]) (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 269FF606A327 for ; Tue, 1 Dec 2026 15:28:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 269FF606A327 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=EbzXSKYv Received: by mail-vk1-f177.google.com with SMTP id 71dfb90a1353d-5ee1e4e3abcso4272748e0c.1 for ; Tue, 01 Dec 2026 07:28:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796138936; x=1796743736; 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=YHCSOUSpZpZZkp8aHWq682h/ZVWXgYaqR8WH/mdXaEg=; b=EbzXSKYv2QXsaW5eZzwtKGxFM/IkhDt7fhihJXAjnsWbS6hxoDAm/93j2Jv/4fMwsE +iMM4X9j8o/n07rBNu1e93sBdrUN9YLQwAZLIdLyBMawDP04NJStFi63eGOxaxG4rR4U C2BQ5seGlqTfK0cxS0dODp27cB7w1cAMdStG6Jt38PzKNYe1inQXBEa1fCr8ewXtwbI9 Ylu9bazw+J02n+XpIKV/zHJwsCxEVIjBdZak2yJLgf9KndZKhQhzBZCtkh7/Ajl1wuIm 6i34vxS5fcRnbNIw/YuOMw4dSj2nDNYxctwTWhndK5uyX0l6H0MjIegHVaTmHYIEQCgc PWNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796138936; x=1796743736; 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=YHCSOUSpZpZZkp8aHWq682h/ZVWXgYaqR8WH/mdXaEg=; b=ola5OTJU4mWza0sKilKwxjm4TxPHqeAB/02e1SVo40llZQgFwgR7a2BS+6/NBWtoZW MZAa6h27oBNjpyyWI+7/Ck7YcAzhEX/ZZL4IviZsfblb+8dWH94bGn61kY/pwL8ljfmy tULe2sRQ8Hc69Rn1xqjMSibl/BWU9x6MeuOdAEVOj8h5Y2CKeB5k6vyRsENL72Qohajk 7U5MZk/AkNaQ/GgrnHMRkBm9SlWC8fLU3VwG7mEvYBU9RQVA63JZLKRVU4pvamxjIVQV dQaG1KbFWRdnLroMY7KkScdVJiyBwkMIxnNm+Noxk2VBXrB2uG7d08VvzQUuTzF1WDAC NHcw== X-Gm-Message-State: APuU4Z+VnPyiEbJAaGqTKpstUqIeyLIIwe/bFPPNKOOjDplH/lj9IZsp DKSJtdqfdNskUjcRag3p+zCmDhbDOUjZidD/wMclZND2N1SWn5R9tuF8A4SJzTXjifo= X-Gm-Gg: AZFdTZe6iLtWy5F9lhxiwem8/h1qy0ATyEW3HBxdjp94aSZ8ZZB5f6DTefHiWqQ6v+m p5wyXC/RXxaDc6bhLokjY1h8j7qhuGtjKeGyujP60My6Up0A96F60N1/ClLKqnEhbk9w1c9QHM6 0vkeo9RjZ+VrLOyzqBJR1fPqqLJu95MFiOJmbMJs8+hGJOMOsCYE6cLw7rt7WO4WpzqXqZTbrAS Vn6koQ1HfKzXt1sz4BpKHEKKHqaAgDG4uB+4rVl2A8RBA9OiYW2PH5/UG8X3FV3/UPqmM9wt0x8 JGWUOQhmc7gxl8wEYO99PDo32VCouaQIfM4xG5QRSXD0P6hEQ0lCKtnbTO9JimtTSqR6856SMkk YckkulCNihlwo7mV6fKEc9vJ7T0vJkZF/nH7aQsnADQ2hKVsVLAUf1zPRjicZdHjDEFR9zdFSTj jk28ylwolQXrC7n9lyrx+6Y6h5xCHN1Mb9zOnPp3nAJd5ilNfUZF5jZvJhlLYO4VUc5Z96oFNse zSCRcGrwlKUssuC9HnN+bTFJTkqEnb+lFHwoAz1kw/yTKPu9YqrOAZPge2vnQoV3aJd/1UeNRXW trGUwRR+5v6fymN1kzZbu6cLNU2oAH3QI/kzXspwC7NAEcFhtD+Tqa7MpjquJwu58b66yiJb/61 hth6q+2G1Nmlx/N8eVxEVQsfsqAdwzXGu8au5xC9FRrF9OyrKv9sPr1wLYbNNzl+r3/dp6eWxrX zQ/xY= X-Received: by 2002:a05:6122:1307:b0:5ea:94cd:c5d7 with SMTP id 71dfb90a1353d-5ee8af38b50mr26167633e0c.16.1796138935745; Tue, 01 Dec 2026 07:28:55 -0800 (PST) Received: from lvondent-mobl5.taila91cb8.ts.net ([72.188.211.115]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-99e6df8a29csm37603297241.5.2026.12.01.07.28.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 07:28:55 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v11 0/6] L2CAP: Fix channels being established with insufficient security Date: Tue, 1 Dec 2026 10:28:47 -0500 Message-ID: <20261201152853.1118148-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.56.0 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. 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 | 7 + net/bluetooth/af_bluetooth.c | 6 +- net/bluetooth/hci_event.c | 8 ++ net/bluetooth/l2cap_core.c | 262 +++++++++++++++++++++++++++++++--- net/bluetooth/l2cap_sock.c | 79 ++++++++-- net/bluetooth/rfcomm/core.c | 1 + 6 files changed, 332 insertions(+), 31 deletions(-) -- 2.56.0