From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796068617; b=PLenSCkWNclU8oCVDcatZL5nYH7FQ0bOK2CTh3jst98KRNdoNQMnLhPXj0/iq/bwyI2X Zpp+WkKVdemrLbTWozv690vVe2+8DPf1kcM3GvUPAZDCFs+nJceU5pNvZI6FddAunCcMO Fh5dIG1RrszorTmC9WwS6ZDo8aONl+kKv21xYug1kRSMRPSem+w5ysexgwMS5dnl+8uEA K34yTHnlaNxqUQjISHqZP4LVqHvyRrOVWldLJGObzkKkJtujakET4ojncOVZGiYc5X7v2 3DvIL0MWELgk8i7CBGRT+dPdfD8mpYhIkVKRuXKk0udDboEV7y8kZK0cLy/leXpRj2A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796068617; 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=QOCCIH9GQg+Q6wFK3tsR2TaSsUMbzrt2dA3lPnkKNc8=; b=5kPhJ3IUB6KRiZgHIQuUa45mOtfaqG+vY4ApEQpSeBGEu7jEeHGwYJFFaPjdg/9NQiZJ lgJ6TwOreUoiiQBu2u2tb3/PGilohkixXlkKoCEpNahlbOGSf4R9HMVZAZoBwYVc99Zf9 PiRKTKJqHw5xLzcFvNNHDJQXC38DBz7rv+6P0E45EjjH6OF0VLqwxvKDufUDMqTiy444z DlK3CmPpZvWbzcu7Z1SZrv3Hzw3L9qKnc/dr8GW1H8bKEd1mcIpK+6byw8uQ1PeUWH8HQ nLL9UefoscxIYl5vlAnNL2DCvm4Uh5XHnbQ5cs6cj5Rs/fcpkAz30SiQhH0cqWnTXZA== 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=TfS7GF+I; arc=none smtp.remote-ip=209.85.222.53 Received: from mail-ua1-f53.google.com (mail-ua1-f53.google.com [209.85.222.53]) (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 5A78C606A320 for ; Mon, 30 Nov 2026 19:56:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5A78C606A320 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=TfS7GF+I Received: by mail-ua1-f53.google.com with SMTP id a1e0cc1a2514c-992f6d8cb51so2474536241.3 for ; Mon, 30 Nov 2026 11:56:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796068616; x=1796673416; 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=QOCCIH9GQg+Q6wFK3tsR2TaSsUMbzrt2dA3lPnkKNc8=; b=TfS7GF+IiYEI+LKO5KqncD5jQBhFO9bykv/oogxMc9CB78wny0FJPlfYwDHPAA9v4i KQNPbKV6S9jEb6mgAEhUjOjeQtvusukfab00ZNC9/AlxEPaAxMw2X/ikokDE3MoCOUgf cgBwXLvj2NiuBnHY3VCiNH4fb8sRXE1zvCpM6FE6Q2PXcZv2IyldDNHvcZQblvcMQD2r eixs6o0xOOw7tCO247BN2vd4/QkE+1A8Ss9Xle/vcb6W1osHtKB3paFPgMXRnr52ExTO bDoCXXFAgP1gVeMPQWoPwoIEuyYtSDrjXhhwgXwXx1n/WgEAVUqG/S3b9CEJtGetml3m wiOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796068616; x=1796673416; 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=QOCCIH9GQg+Q6wFK3tsR2TaSsUMbzrt2dA3lPnkKNc8=; b=mZSwmXpRAuh+7vi31sRLwfpQVBkHGBOc73GZYYfFmZRs/xj1dzMSCrR46qscfDaOFl D2ys60p9ddn4aNh5w2DeiGL4Xy6RtBOE60+MjLAgAvndh/tM8iAHVA+Jyag4MwgpWuGu OKHlfH6X9asvJA9Qc6RwLVUp6EbOa/O4GxMxvr/AYtwyiG2A1EK9yD4wH0BK6vgxDECc ZrXVUJwCFPgcv3hw7HbZxU+DQ7Dtx978echY/n41qFlnJapMJ/c6d9ubblJlPhD4Mud0 1+00z9XrK0ChKYUINCzsvZHX9x+pmViNxi6Q4a5h7y+wuGmqgXKLWJv1uCr+7MsWZMHy +N9Q== X-Gm-Message-State: APuU4Z++pLaRWXoCH2fiWH+kRe/pkFytZUEbSfAqcjjQC2Ohdv63s0Uo VI67cqkqy/v1WATJn9DR/o9e/psgCX4aQPNsfJT2JU2lKviHot9uDx8e0lB2Joly X-Gm-Gg: AZFdTZfCU3iUOtZAW0w8ZRt3mxYShB2v6vdR+U6a/rAUdgdN7HvG/VmLkvKg8wYORQA mOf9LG6Naw+xx6qYGaw1/v1sDw+JdFTCwdcm53IqmJ2NjIVgD6LeMDVZLKes9ZaFcCbH5bFXn3l DUMWF5Ep+mqfr/aqqxSdeVH6noV6PPEYJVFweIb6xF9Tj3+l7UAPqV+CcVxskIKAnDiyDH27heD lJUy7gVtYOBwIc2NDII4PlTtRCFKiDW5O+k1DbEi16mwwnkMslta45L51wHYedaOAFR01ymnApP GdIjHuMz2bjsiVt/S29HAlwqnPiHYEjh1fWmzt9BIHpvXd5Qtr/FLTNXmVXmRjoxpXDQ0MQfpWs c1oypy8tWZ8c0Jdfi3mXuwlacSR90cgPX/3vjbqlyC12ZFLcT8EFpPWF4AoL0qVyikIfTETtRmw Tzpp9VrhcM8tg423T8Sh2Iai/ZrOB49QSBCsHSE0Z0MC2VSFMgJGKSBeNyJELnGPVwaFGkgKEyD Oi879wtKw9dkCk6GDnKpu+VQqYnEPc5HmuR7sdwZXHMpsjiKhV9mdfB9j8SidivGXOj2Kg1tp1N 4r+u4c/Smi7vheGjSbe36kmX7IjRDY0HfH2MvO1ngtVlzsBFnMrjWgeEFEMbfjVy1BODUoIh3z1 9Y+Vqt8cagj43/Aj4EyPDpSpv48Y0eveRTnhxqkHjyXxc0mSkiE8VCBAc7xQxt9KxzDmjeMT1+Y xlM5rmS/kcBSOscRFtHTvkLXew X-Received: by 2002:a05:6102:c0e:b0:7c3:6466:3155 with SMTP id ada2fe7eead31-7d739674a7amr19751666137.33.1796068616171; Mon, 30 Nov 2026 11:56:56 -0800 (PST) Received: from lvondent-mobl5.taila91cb8.ts.net ([72.188.211.115]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-99e6dec7cb5sm36694016241.2.2026.11.30.11.56.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 11:56:55 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v8 0/5] L2CAP: Fix channels being established with insufficient security Date: Mon, 30 Nov 2026 14:56:49 -0500 Message-ID: <20261130195654.560637-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. 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 | 221 +++++++++++++++++++++++++++++++--- net/bluetooth/l2cap_sock.c | 64 ++++++++-- net/bluetooth/rfcomm/core.c | 1 + 6 files changed, 281 insertions(+), 26 deletions(-) -- 2.56.0