From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.179 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796073153; b=yG63SWODxa3nvnDO8WoVsxe6IehP079K/j39Ag6x6KmHxP+wJs28bULY4jK/xmFAI8Ba O7N4gfp1bgRF+Cede97YR9BAoibPZhNJvGac6ESjOlZp0AmpN5Ui7TObSoU58HMMV5zxN /u1HBTuTvMTUk8J7/hWnE/S0u3adVI4CrpSzdFT04TP2b2NWM3aPGA1w53dLUFkMhTf8h Ghjh0ySfcOHyIVzD7n+vOfVyq18Moy2MKrC0P+x8l30uDaRyGycQnHWZwe8o2ejZHMLbk uBN/hjaN7hGQv0tiJ0SGTR3olCF//SdxEuTzAvo4Uma48jZHmUvEHJ5MaiUeMd3Ht6A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796073153; 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:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=nHtY5blApUvB9EYfLBb1NQHvODhU9oChsyrmjR1snfs=; b=tUq4AGJEzaxgDXYRYHFnk6l3gmBjnXMV7ITYQxASb6yKIrjiokTHqIMW5tVI4h4MGB6T XDoVcXYHUQOkBGkLWM3ux0D0AhGypT8iDiXqaHnP3Mlzq9PGYzKxpD91Em0Jt0YArTHPU VWl4yTC86RsyXMJifvHhO5L2KUPytCK6bYeo4mbp5itwC4Q58cfp3x7MIkZF27kN/oRfS 3XAb6MF9vYDcDiAI6gil5mx1uFOZrVxyAExkI67FKEfY9HBWwU6zcXX2YjwFZh+xT+R7F neT6qujEVa7J5bjUWHW/wyHi2Ne27y51c3ahYWJ43mKqNVfTqC5dPSIRzxlYW+kysgA== 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=xcYu5xoD; arc=none smtp.remote-ip=209.85.221.179 Received: from mail-vk1-f179.google.com (mail-vk1-f179.google.com [209.85.221.179]) (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 D0BCF606A32C for ; Mon, 30 Nov 2026 21:12:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D0BCF606A32C 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=xcYu5xoD Received: by mail-vk1-f179.google.com with SMTP id 71dfb90a1353d-5ecda93627eso3582225e0c.1 for ; Mon, 30 Nov 2026 13:12:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796073152; x=1796677952; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=nHtY5blApUvB9EYfLBb1NQHvODhU9oChsyrmjR1snfs=; b=xcYu5xoDQZl6/Z7wDi1rZcrKmSaLCnULaMJyGTG92nd6KneK0TBMb0rPdBxmVP6WOJ 8DCgxEUQpVIYOKBBnsjfvAl0HnM04Fb8HB+ewORFBLmvjA/+VOY7EFatbKoNR7qt6ywm s7LKd3LBf5iA3mRuZISxbaxOx/XnTNtcFv+G77aFhu8GkNP+Qxmnc1rrRn2g40ToWubE QamdGD/IMsCc97OLZAx0KLpJi3E5tAG94XuXpDwCdQhfoIFdVvLm2Lo1piGk8vzqbPVb lF/Rrjz2ERWCnRo7fpXsHa2BtzhEv/Rs40qLxsvFEYhpnG8t20UJ+oeYDnPtIN2QNvZl dteg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796073152; x=1796677952; h=content-transfer-encoding:mime-version:references:in-reply-to :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=nHtY5blApUvB9EYfLBb1NQHvODhU9oChsyrmjR1snfs=; b=ThCvoSEsypU6kUfC9N/3CPtg9UGwdpthHFJjeKhKgoF1LsyGmNHx/p6bRN1w7N74xg C+8wfWkum99w41haGNKthqZY/HStaNv5uem5iPGvDIzXZpX28mZW9rIVWkqX6/fhL4h9 o21acAtwvrBlqbP3O/gvFlJnfJrZWrmcJvGfHh+17CCbjUHVPus3iYv5N51mLZ41l+XR mC2+qA04ivb/nVp1ipJopLkss7uRLCYlDAKXzszFhuox8itcV7YJKtBV0PezPyLOcu4N QyIDkBRVKOpr3JS9Tv14gAeo7IR4aLb9QQxWDzqJwGlndQcAYOzC3rCN09cFGncDenTS EGzg== X-Gm-Message-State: APuU4Z/ddH/he71VABtTCiCRx+325Y9eq2cLwUqXT45AaU0/qFsPoGFI q4KsPYcdXmLW5IznwLF3zOG0zpltT0QZ+ZSFsec28iVtP71p2C3RmExnXtH1L6B1ljo= X-Gm-Gg: AZFdTZfeYhJjXG9DNOCdjtDJvHRYDx8b5tvbr9t37iHXIPJHV3uLuAWxl/bBq/nrqJO CQFC10RAL0oMgCZ/khus3dmNMMlU69F+BsSwCXkMDvessl7RIpWy+g05qOMF2FtbH5NNBMXx2Ee X8wgcl3AnHcNwNF9CdOtpvqfa0PXRQYctGyjcrDaBG19IioXrlB1ThMcxm5j59yxqww7eIoQTfC pMb7vwuED0Q6xfyq00zEABrstS33AF58YCrQyWqkRmk9nMQ1q6sLlyJTX3YA/vaEQ1lJ7pYHqKH jY8WWgc4OCMLRcwlfuuH+nH5/e3kCI96m9D2CHUJUf5Sm6YcrCc5RpBSLEFT0gVuOF5itHwoDvv QUo3DIEPsKjjaToQICOvuqKJBBJQd//olVcpZprYpBfymh5t+lA0+7vMLoIWIFum8ql9/0zhou4 NwiFjxCgjFeYQ8a7/yjTAX7OOgVHUpj/n+wTvxsDC1XUXspZyTdtlXMJhy5vA16BrcVIhLv5vtq NZJl4N71VB7/upDzseEhpUMQ9FO9gc6hFVyW+yVzdrJoUjGo7rn8HNDkTiwioYzVIVVQ2mYLooS IDbTSgMJDp5va8vzLAo5kbBx2r+nJ7Ss6AAKQ/G4HHY3WA4ba1U+db64dOlzsaUGRwUPRNgk8zP 3Nou7rz9/Mz9th67JNeP86F1tZN7FV5sLaXqa6gNAqReHiPF7Juim0k/6YY7EgGBxTDxHeTQn6r uD/mg= X-Received: by 2002:a05:6122:e149:b0:5c9:a60b:e5c0 with SMTP id 71dfb90a1353d-5ee8af1adb2mr21133258e0c.16.1796073151688; Mon, 30 Nov 2026 13:12:31 -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.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 13:12:31 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v9 1/5] Bluetooth: hci_event: Disconnect if the encryption key size is not valid Date: Mon, 30 Nov 2026 16:12:24 -0500 Message-ID: <20261130211228.621145-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261130211228.621145-1-luiz.dentz@gmail.com> References: <20261130211228.621145-1-luiz.dentz@gmail.com> 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 When the encryption key size can't be read, or is smaller than the minimum, hci_conn_enc_key_size_set() clears the encryption flags, downgrades the security level and notifies the upper layers with an error, but unlike hci_change_encrypt() when the encryption fails it doesn't disconnect the link. The channels that were already established are not closed by the upper layers for a status other than success, so they stay open over a link that is not encrypted anymore. Fix this by disconnecting the link with HCI_ERROR_AUTH_FAILURE, as hci_change_encrypt() does, after notifying the upper layers. Fixes: 04a342cc49a8 ("Bluetooth: Add more enc key size check") Assisted-by: OpenCode:claude-fable-5.2 Signed-off-by: Luiz Augusto von Dentz --- net/bluetooth/hci_event.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index a9b6a6ccaa03..7f86b71a3f80 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -782,6 +782,14 @@ static u8 hci_conn_enc_key_size_set(struct hci_dev *hdev, struct hci_conn *conn, hci_encrypt_cfm(conn, status); + /* The link was reported as encrypted but it can't be used if the key + * size couldn't be read or is too small, so disconnect it as + * hci_change_encrypt() does when the encryption fails, now that the + * upper layers have been notified so they can cleanup. + */ + if (status && conn->state == BT_CONNECTED) + hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE); + /* mgmt_security_level_changed() only reports the change for * connections already announced to userspace (it checks * HCI_CONN_MGMT_CONNECTED itself); otherwise it is a no-op here and -- 2.56.0