From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4FB6A3E1680; Wed, 30 Sep 2026 19:25:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790796350; cv=none; b=c5mdRwPyr6gnx9SdgvcsFoLmBwYrQs+Gfvw1BQoJNx1KIkww1hkDvkQcHEx7gWuxdiuPNqqI4oQg3HMI9oND3uIEZwNttzlYKd8caki3Khyco+V37qHlcZoGqmahGdXjVWg/rNwpK4SmJiKYKAlK1G4cimqWtxFbhRUdsvVagUI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790796350; c=relaxed/simple; bh=PkkNRtMqh1sgBVn7m8wVnKH1bmf41FqUW9xJM3l9uFU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PiEq3TFA6SnyK/p+fSzt84/tv0pa3nCtc7ydBYFiiCuiJcwUz4sKDcLTxt3TnrPzlhtt9GHm5TojB3khGZicMEVuD9ctHNkYcc3VxGXROo5532fvQlAGjFd8QffJZpCMp/DDqMXITwJNpgEdI6N7Ia0xBd5p4tLJHnwzsbOxSI4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=jk8o7cDk; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="jk8o7cDk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9DD91F000FF; Wed, 30 Sep 2026 19:25:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1790796349; bh=6yrVbnJmHvLrWG3Mxga1iLffdPUX7qoG9t7NcTx+sC8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jk8o7cDkOsE8UupNIeVFwzh8DYgi9zSUbs3AJtMi92gsMye5AQ8kzvfQWf7ZwFhhb O/uE5fCg/FUSpoh1cgiSGH5bG2exxk6XpTbH+2If+XDoAOLwyJs6kXfRx7OOgy0t2l EdKLaZbYjMSzSpcIeVMw5rP8MbKFA7PCu9RHkakA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chengfeng Ye , Luiz Augusto von Dentz Subject: [PATCH 6.6 0855/1193] Bluetooth: hci_sync: Serialize local codec list cleanup Date: Wed, 30 Sep 2026 17:25:39 +0200 Message-ID: <20260930152453.229640269@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930152434.301151190@linuxfoundation.org> References: <20260930152434.301151190@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chengfeng Ye commit 9a10987a2f160a44a638c9a35994ca6e3089696e upstream. hci_dev_close_sync() clears hdev->local_codecs after releasing hdev->lock. Codec list additions and both traversals in sco_sock_getsockopt() use that lock, but the close path does not. A close and BT_CODEC query can therefore interleave as follows: hci_dev_close_sync() sco_sock_getsockopt() hci_dev_lock() fetch codec entry hci_codec_list_clear() kfree(entry) read entry->id The reader then accesses an entry which the close path has freed. KASAN reported: BUG: KASAN: slab-use-after-free in sco_sock_getsockopt+0xfa0/0xfe0 Read of size 1 at addr ffff8881001c3450 Call Trace: sco_sock_getsockopt+0xfa0/0xfe0 do_sock_getsockopt+0x537/0x7b0 __sys_getsockopt+0xf2/0x170 Allocated by task 92: hci_codec_list_add.isra.0+0x2c/0x440 hci_read_codec_capabilities+0x224/0x590 hci_read_supported_codecs+0x2c2/0x640 Freed by task 92: kfree+0x131/0x3c0 hci_codec_list_clear+0xd8/0x160 hci_dev_close_sync+0x92a/0xfa0 Take hdev->lock around the clear operation at its existing point in the close path. This makes the clear wait for active readers and prevents a new traversal until the list is empty without changing teardown ordering. Fixes: b938790e7054 ("Bluetooth: hci_codec: Fix leaking content of local_codecs") Cc: stable@vger.kernel.org Signed-off-by: Chengfeng Ye Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Greg Kroah-Hartman --- net/bluetooth/hci_sync.c | 2 ++ 1 file changed, 2 insertions(+) --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -5465,7 +5465,9 @@ int hci_dev_close_sync(struct hci_dev *h memset(hdev->eir, 0, sizeof(hdev->eir)); memset(hdev->dev_class, 0, sizeof(hdev->dev_class)); bacpy(&hdev->random_addr, BDADDR_ANY); + hci_dev_lock(hdev); hci_codec_list_clear(&hdev->local_codecs); + hci_dev_unlock(hdev); hci_dev_put(hdev); return err;