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=1796384347; b=d51vy9KHSzKUfJp98CRoRllWYolROtocaLdqfKeJxcLi2I4EWLyJUTv1ZQIAc7SnBAbl Beg8Ab7YQcvzE2Hw8TH0wH+sRg8uvQUM1jLhLkrIZ0ECbZb/HmgkG9ucHu02hGgvx6Jr5 Wld/zQ2eghnEKTZJHnaSh4J8mQRd/FDMP6Ac96G4mDGo6A5aYl1rpzYHMIVB2bqkyzm/c DBfGkVmqsFbG8FHMJY85u+kgkQuyOVCwIRTN+UNig8ECVo6sidHcRe0KCNBYG/zbQ4Dml PzEbT9TSIOdvYbx19Eh/ug+GOSvebuhE1oARWR1yxz7mPmZLQEBcS95xxm0bY6hmUbg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384347; 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=W5qU9dfkMcrD8F8PI+1BZB/Va8D/rrIm56LDVHyppBQ=; b=L0c5W1WsjyRcn2yjhWQxuu8iwPVzMteEkO4FwQh0Vl0ZS6yPAS/SELRBnNqqJmH9D4yX 5YlbQOYkiz93JGPA4lfEU8SLPH7BYnvLnsH9k7wrjKWnfDNjexl6zl6hoZ9Y0NRTruMMV 2AJXMARsKt53qJKROeX5/Bp+XRuyeFZ8mGaTvHl1+mngFcop6tt9Tf6wCZk2kYg+4sxoJ 8S/s2S8W0ZPNeWqVb5TjPGr17nt907WBftGOBNdG7C+Doijh/5YR8i4RBmvpZ8aK8/v2m zAkDYwC8dGUEn8xdyoYUirb5E1r0saWysvdgZV0jpo1tkrttAps+qPtH51ju5z+g4MQ== 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=s36GohUz; 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 2EA41606A32C; Fri, 4 Dec 2026 11:39:07 +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=s36GohUz Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C3F11F0092C; Fri, 4 Dec 2026 11:39:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384347; bh=W5qU9dfkMcrD8F8PI+1BZB/Va8D/rrIm56LDVHyppBQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=s36GohUzF3U1K51KpoX33DGNVOZYwFrSYq2XtBmeHvrVnPx3Ov2MfwRh17kwhWMf8 MWLMYjpedHwZ06zC7R7H7R5fQOq1K4NOGYChUgBswPxrN9TbIFu93Uv3ArwXhRX9Ww 0kb0a94UrhsZ9k2qr6BxrhDyM44qT/QnfcDn8Vj8= 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.6 0114/1167] Bluetooth: hci_core: Initialize LTK before publication Date: Fri, 4 Dec 2026 18:52:21 +0900 Message-ID: <20261204100705.064396550@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@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.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Binbin Deng <18983559317@163.com> [ Upstream commit 4335849380aa1081ee9a1c2b934cbdda0961fa57 ] hci_add_ltk() publishes a newly allocated LTK on hdev->long_term_keys before initializing its address, type, value, authentication state, encryption size, EDIV, and random value. hci_find_ltk() and the debugfs long_term_keys_show() traverse this list under RCU and can therefore see a zero or partially initialized key before those stores complete. The race is reachable by racing an LTK addition with another CPU looking up or dumping long-term keys. For example, userspace can issue MGMT_OP_LOAD_LONG_TERM_KEYS while another process reads the corresponding debugfs file. Initialize all fields of a new LTK before list_add_rcu() makes it visible to RCU readers. Existing LTKs remain published and continue to be updated in place. 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: 970d0f1b2803 ("Bluetooth: Convert LTK list to RCU") Assisted-by: GLM-5.3 coccinelle 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 e344085aa5f7e..42b1f40c86542 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1331,7 +1331,6 @@ struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, key = kzalloc(sizeof(*key), GFP_KERNEL); if (!key) return NULL; - list_add_rcu(&key->list, &hdev->long_term_keys); } bacpy(&key->bdaddr, bdaddr); @@ -1343,6 +1342,9 @@ struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, key->enc_size = enc_size; key->type = type; + if (!old_key) + list_add_rcu(&key->list, &hdev->long_term_keys); + return key; } -- 2.53.0