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=1796387003; b=HfQ38PynjWOlnyEge1WWKJX2A5oSDEW9UnjipV05WXgShZgqPHF0C9r6MgXqBIZSQ1tx PKhFaAWHO7TOFiMZh1ZmwZ3sqjJTIGOBx0xY1CJtKsqmAl+rnhxYvA/MfXEP+wkX/xLuI q0f+Nydg46dCgc3tz7AhisT/irFgBaJASDWYYxSeb3aLxfDV/uOIh4p1oDKJUtsMNmeBU c7l/mWqByrc7z0enOjjZkAwwSBMkkIH6qDaHEjeNgxb+TG/pzc2cS2VrxEbCxDIaUYN9A k3pc8zt9uV6IHcQXaBuig/42U4qlDKuuxY8XyMnZAsa3hfTATjHWR569u2C4FKlWZVQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387003; 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=5Xy+XNuAGV9YHRxdjkChZ+osyTZxngN/z2cjce6YQXc=; b=ti65E8bInAMXD4iFRInAC/PujpoMhuXetz3wYKcVwRMLkq6Lv57mlYMMNsqQNtraz7Q7 /W83FrV52PJmqJfOZ7m9pbwKU1cBYhhhlPNEcFDyvjW4i1c+zO9N/WRKcyplzYIv5B/It wDbbETjOkkr3YaUbxH/41+nv5lvkvHuHxY7a6aZHNbX474OkegTvrKaa6OiNM40gitfW2 r+NeOnrRJfwppK4HzSZG2JrUme+ymj8cLIvZRqH4CllGTltKwwy153+pKA5sV2x/bKsNI e70Wwby1Wf39pc7P4k/WaeOYoiawH7nbJ9QIuLS7qRRvVqOjf1bPjZ9LMldnB1VkmrQ== 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=vyN+Kr9D; 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 46620606A322; Fri, 4 Dec 2026 12:23:23 +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=vyN+Kr9D Received: by smtp.kernel.org (Postfix) with ESMTPSA id B071D1F000C2; Fri, 4 Dec 2026 12:23:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387003; bh=5Xy+XNuAGV9YHRxdjkChZ+osyTZxngN/z2cjce6YQXc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=vyN+Kr9D94wfCjxxTjmlNsDRdLIXnLo+HBniOD59ZkhsFOxLC3Jxco5hv+9p6CR0y 0Gb9uUW0wMPVSOIdRubRNq9HucZfUV0AExhUjGogVhTMLN7xYu3jk0gluVtMP9sXO1 z+y9uyAu/wESf00X6EJ5CP/D/HKQXXUtT0pL1TpI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Cen Zhang , Luiz Augusto von Dentz , Sasha Levin Subject: [PATCH 6.1 0091/1059] Bluetooth: hci_core: Initialize advertising RPA work only once Date: Fri, 4 Dec 2026 18:53:42 +0900 Message-ID: <20261204100646.472209793@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: Cen Zhang [ Upstream commit a7c5c18b7cc30dcd2a9ae5a0fb38378d3998417e ] hci_add_adv_instance() also updates existing instances and calls INIT_DELAYED_WORK() on their rpa_expired_cb every time, even when the work is pending or running. cancel_delayed_work_sync() then no longer finds the work, so hci_remove_adv_instance() can free the instance under it: hdev->workqueue MGMT_OP_ADD_EXT_ADV_PARAMS adv_instance_rpa_expired() hci_dev_lock(hdev) hci_add_adv_instance() INIT_DELAYED_WORK() mgmt_pending_new() fails hci_remove_adv_instance() cancel_delayed_work_sync() returns without waiting kfree(adv) hci_dev_unlock(hdev) adv->rpa_expired = true The work has been initialized on every update since it was added. Initialize it only when the instance is allocated. KASAN report as below: BUG: KASAN: slab-use-after-free in adv_instance_rpa_expired+0x139/0x160 Write of size 1 at addr ffff888108d84b2e by task kworker/u17:0/504 Workqueue: hci0 adv_instance_rpa_expired Call Trace: adv_instance_rpa_expired+0x139/0x160 Allocated by task 560: hci_add_adv_instance+0x68d/0x9d0 add_ext_adv_params+0x4d4/0xb60 hci_sock_sendmsg+0x128b/0x22e0 Freed by task 594: kfree+0x307/0x580 hci_remove_adv_instance+0x230/0x540 add_ext_adv_params+0xa43/0xb60 hci_sock_sendmsg+0x128b/0x22e0 Last potentially related work creation: insert_work+0x37/0x210 __queue_work+0xaba/0x1270 call_timer_fn+0x171/0x500 The buggy address belongs to the object at ffff888108d84800 which belongs to the cache kmalloc-1k of size 1024 The buggy address is located 814 bytes inside of freed 1024-byte region [ffff888108d84800, ffff888108d84c00) Fixes: a73c046a2869 ("Bluetooth: Implement Set ADV set random address") Signed-off-by: Cen Zhang Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin --- net/bluetooth/hci_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index ef8cb26bc3994..ff31509ea4728 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1719,6 +1719,9 @@ struct adv_info *hci_add_adv_instance(struct hci_dev *hdev, u8 instance, if (!adv) return ERR_PTR(-ENOMEM); + INIT_DELAYED_WORK(&adv->rpa_expired_cb, + adv_instance_rpa_expired); + adv->pending = true; adv->instance = instance; @@ -1755,8 +1758,6 @@ struct adv_info *hci_add_adv_instance(struct hci_dev *hdev, u8 instance, else adv->duration = duration; - INIT_DELAYED_WORK(&adv->rpa_expired_cb, adv_instance_rpa_expired); - BT_DBG("%s for %dMR", hdev->name, instance); return adv; -- 2.53.0