From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.181 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796073152; b=lYXxlnoo03URouWFbyRmD90/H/CCLCQW+h33IMN2JiLLK9Rdsw+4ypGmEUdKr8FUnoKa xJ5HijN/3rk7egR5OqhyfTaVj8lzhKfWF0pefzIb3oLRNtN2Y9+dwyD3PAw4VHD5H6/jy TowpCm26gpXG0kXRYvVMts/QZARNFzE3I0G1lh1e/TA9oMb78aphwu9qb3JtxiRpRW2oP FGDuNxFz0dBvPre7pQamtb2SQR+GSnBsuzkV6QLquIArNFOGy7egt1rrL+AYkB0tHL/bE w14/2BqswuBU38nv+mfdIMkjxVxxk67gSeY9dFpaoTjREd0XUFkHrd1VmLFFWSFHrzw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796073152; 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=CQOJiU4kn9mVXr8mwSPAQSM1Ma+YrYd6Ir8qqA2rjco=; b=j/DfuPDXESneQpqlqQP4T2Be+mStIiYsITnkqoRlgndRwQVox5/DeN1Lt7h6xRO5210K ZXdIffOAocXJ2AgQztKVS3/s9X2hQOtL8BultmtlXduOLClZTY9CHwa6AZbMLh3HCOY4Y phCJJD5XzMopvETL/fPnuzYI1BFou3NQv1TH4kaD3gNQQmkZEOJOe1qbDFCY8XDawgOj5 ZTuuMQgjF5hfq1rycid3uUMNyXMUne1c1k4Zv9l4W8CdqVE7f4+cJWHZh1Mp1i1Suwegf JM9Yjvb1wtZnCqb7oy+IKUxnusnnfWI8w1SJveHzR/v4c9LQ4qUyL4FPPqxccMIr3Cw== 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=oEM7aEAh; arc=none smtp.remote-ip=209.85.221.181 Received: from mail-vk1-f181.google.com (mail-vk1-f181.google.com [209.85.221.181]) (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 A4774606A31A for ; Mon, 30 Nov 2026 21:12:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A4774606A31A 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=oEM7aEAh Received: by mail-vk1-f181.google.com with SMTP id 71dfb90a1353d-5ecde8e8e5bso3355502e0c.2 for ; Mon, 30 Nov 2026 13:12:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796073150; x=1796677950; 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=CQOJiU4kn9mVXr8mwSPAQSM1Ma+YrYd6Ir8qqA2rjco=; b=oEM7aEAhatYZTW/jIo+hy55ffyD1s9owtqYs097GCc6DEI8plo2SNo1bFAb5hSb+D8 cEGM91WvQ9RSELddnacRPfl7Yur/vTwC7GQmniXJPO92eU+Z1a+MQA4J8k9ZocVIdsdW h/Ha8LzEzpe6CAyBuXlM8438JV3AzfErBZ2/AQ/qPtISnRETMUhXoInRnt72MulTTq5/ rOIqn4sWYReOcAavjWKamdx1gNyu2fXrpDCuKB3xyXOom26FNx7ohUlzdaD9b5skBMxE mdB2rxUtHad04PWm/peSXGJnISmWFT8reOftDbbH8+IGldViPjQHF3YmfzzMgu5U5WEB NSuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796073150; x=1796677950; 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=CQOJiU4kn9mVXr8mwSPAQSM1Ma+YrYd6Ir8qqA2rjco=; b=hFajEqtOjc1NtWFtrG1nM89E38QllOAP96dm+IWArJ2fRvMkja9oNvcQ1krOCaAZwB +7TRCEPGFMyf7E3ae7cPDZcOBuat6s8Oi8E6GjM/Ha9U3HBmBm5bvZ+eMTRkkHYnHiaw 3pMpUwk/nU3Rz8zwMAZqzaAyBKNLN3k6wN1npV2tSS47zylwQ32yQGrWre9M8mBXGZxS c4Ht5kdyNcN7kyFyBiFY4Ju91pBFDxuQuBzbkzAG2mMx+PNSYYSC/TiSK+2r4eDaxqaA CsGCqAcR4FPp22zYrwTkXWj9Ev+EeXPaUsHh4P/DA0hV6m3SSIsSqST8Uo0/V3oaxtsO OLPw== X-Gm-Message-State: APuU4Z+2i0gVy47zgRjvP/PuBLkrh0N0gABzk+50wXhMgqDTWwzR4D21 aBux9l4rzNFPZe3WBjdegNliVlDzHYIzmF1iipV5EAkMcrun+gB8XnSLgmhicsJIaAw= X-Gm-Gg: AZFdTZdAnXwUxi+AZFZPaIP9P4PDpDp2VQCRgxGZlsVLXP0ms5w+V6Q0PYMQ3DzJ7aJ 8XOHlS25agLnZXjHmyAev/2f4ozJCmEAur9+hQxG8zsODkuxRYH8Y0WQ/rDm7pdaWyfdrnAUNC/ z4GpIys6D2T9lWiRku1j5ElJZCbT8vz1XYWc4j8zrUGjtqQEuxRvm3dEYAU2jzuJh1tO9lXMJT7 5yf2YwDkPE6yL6sEZ01iRGouR1VzSMO7+/Hi5ympT92oBJHZ4XoxsvEQEHE84OM1skrxoZ/weIL RuTZgmC+5u/lSiVG4znOGLZWqotn3kP2W5AAOfOiyx0URZ8jwNBuERTerl0gqQeojbbPbGvOhj0 N3xFucanTxErlfzzA3L+DmKck0aKxnM0+49Q0rZB0SBXMbb0qLShw7XspqWUyiPn2kaEe6puAsl hkNecInXFj+Zv1mkE89OUEoA04u49ZQDrzAdaa2veUPS3JdylsdDNKsIQYey+/bBwJTS1c351sq Au2xVVb/6QpWkwWwUeV2vOrby3RbHt23ul7BG+V5EF59RqrieVsk11m8sRRG07UZR44b4EJDatX i37Bw2xW6IzoWex8vhkews68jbtyRzQRwBmvcLZA/U1TEVo/K+UJRq3S569FssCgSgy7TAuZ6b7 f/gH4+tjRNmIjRpPMoKBaUWU7TV+Z49ZCiglwv15eUBaBu8G+SN4m0lcrHNuDaTBLr2jqfxLGk6 RvfGw= X-Received: by 2002:a05:6122:1d0f:b0:5ea:d649:d1bc with SMTP id 71dfb90a1353d-5ee8af45319mr25726708e0c.18.1796073150314; Mon, 30 Nov 2026 13:12:30 -0800 (PST) Received: from lvondent-mobl5.taila91cb8.ts.net ([72.188.211.115]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-5ee8b609bc7sm35472261e0c.12.2026.11.30.13.12.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 13:12:29 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v9 0/5] L2CAP: Fix channels being established with insufficient security Date: Mon, 30 Nov 2026 16:12:23 -0500 Message-ID: <20261130211228.621145-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 and third 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 fourth patch relies on them. The fourth 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 fifth 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". 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. 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 (4): Bluetooth: hci_event: Disconnect if the encryption key size is not valid 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 | 268 ++++++++++++++++++++++++++++++++-- net/bluetooth/l2cap_sock.c | 62 ++++++-- net/bluetooth/rfcomm/core.c | 1 + 6 files changed, 326 insertions(+), 26 deletions(-) -- 2.56.0