From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796386979; b=B8ABnlXdwEJjwLxCxOBFe4sdT0Bc0aoYwlH0TuYC/ixGOx+c2PJLIM1g8jEGKix5abux cDTMrpoC1oI8gculmJIR+CI5+YKPKAKbJux/i2WMU3tyJPiWlbKj2kfRRiQR0xPptdZQF QdCc+az3e+C+o5aIynEp/Ht7TZUEufTyr6hJw8IGIYPUhTRHP1hdmKo5CHC7ye7fyWTBR Ief7wvo1Gi4NUgopEu3WKt6TX3EK1UrIQc+1Olmfth5pqGSswQ9ylNjEnusCk76MVgOdF 2IY0OXTVE0N4iH7DliJFrLLTVz7gnIVN/e9tXX2mEFpAU2iV6MUo6SZc7gRX3s04CZQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386979; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=+83YtmuAqC7zQzZ+q4FiO7khIvK5+tkvTJwpDdX0k8Y=; b=UiXLkpUqQ3k3JvivEqh6cMa/OPQ67pfUHl77w9QPsDM462RtKCM4LJJpu7J/sKmAaFqB /rVpN85cIhaxujuoa+hyw9u/25cEvDr+kVQCIU+dvErdNtB7Exb7AZq2/Ih3hI157FWOt psT5qstmBj9sQdLtx3K0Re9ZIEBUzAk4auB7fF/lGGNpMUULidjqMsPvXC/sSlHmuY0kg iVKapUbxCMLTn+ekOAhB3mGV/g/E2ZBoh/T8S0PTIipCVGQvYRqA5eTlNUq+ealKuOh6R JYHKZ5V/+uE4N72O3bfO5ey2N2wwoXEnvR8swo+ElU4m2ay5Wt9sAR381ocsYS8XHtA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b="co/tTSyO"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A31C606A322; Fri, 4 Dec 2026 12:22:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=co/tTSyO Received: by smtp.kernel.org (Postfix) with ESMTPSA id 013341F000C2; Fri, 4 Dec 2026 12:22:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796386979; bh=+83YtmuAqC7zQzZ+q4FiO7khIvK5+tkvTJwpDdX0k8Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=co/tTSyO41c/Cqo1aTqK+bXnQALjFn6g3Q+5YXqqA7nakFP/IbLqwFQAccbD4HIXP 7jBpsFpQVcuujQ6pQ3e3whoYSXknmCAn7sUataYN0SRJOwVC9SgdCxGmwmTyUHLh3r ILmq97H41COpa9+9cZ9DVQFhuEVQiJfIDSGe+n9A= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Binbin Deng <18983559317@163.com>, Luiz Augusto von Dentz , Sasha Levin Subject: [PATCH 6.1 0082/1059] Bluetooth: hci_core: Initialize link key before publication Date: Fri, 4 Dec 2026 18:53:33 +0900 Message-ID: <20261204100646.234636347@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@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 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Binbin Deng <18983559317@163.com> [ Upstream commit ae9c8df1ffb84560ac01cbdc26cfb19027f4d25f ] hci_add_link_key() allocates a new link key with kzalloc(), inserts it into hdev->link_keys with list_add_rcu(), and only then initializes its address, value, type, and PIN length. RCU readers such as hci_find_link_key() and the debugfs link_keys_show() do not take hci_dev_lock, so they can traverse the new entry during that initialization window and observe a zero or partially initialized key. This can be triggered by racing a link-key update with another CPU looking up or dumping keys. In particular, userspace can issue MGMT_OP_LOAD_LINK_KEYS while another process reads the corresponding debugfs file. Complete all fields of a newly allocated key before publishing it with list_add_rcu(). Existing keys remain visible and keep their current in-place update behavior. Found during a static-analysis-assisted audit: candidate sites were surfaced by a Coccinelle rule, and the reader/writer paths were confirmed by LLM-assisted (GLM-5.3) code inspection. The issue was not observed at runtime; it is identified by code inspection only. Fixes: 0378b5977013 ("Bluetooth: Convert link keys list to use RCU") Signed-off-by: Binbin Deng <18983559317@163.com> Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin --- net/bluetooth/hci_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index da6c3520de262..a8ad99664f910 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1284,7 +1284,6 @@ struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, key = kzalloc(sizeof(*key), GFP_KERNEL); if (!key) return NULL; - list_add_rcu(&key->list, &hdev->link_keys); } BT_DBG("%s key for %pMR type %u", hdev->name, bdaddr, type); @@ -1308,6 +1307,9 @@ struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, else key->type = type; + if (!old_key) + list_add_rcu(&key->list, &hdev->link_keys); + if (persistent) *persistent = hci_persistent_key(hdev, conn, type, old_key_type); -- 2.53.0