From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7547C87FDD for ; Mon, 12 Jun 2023 10:50:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233914AbjFLKu0 (ORCPT ); Mon, 12 Jun 2023 06:50:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235517AbjFLKt1 (ORCPT ); Mon, 12 Jun 2023 06:49:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D3897DB9 for ; Mon, 12 Jun 2023 03:34:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B2C3C61BD9 for ; Mon, 12 Jun 2023 10:34:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8B6FC433EF; Mon, 12 Jun 2023 10:34:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1686566057; bh=5M43ELoWB7ifqYPOLh1V4YoRpfGtxbHkd46CdNKKhnc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f9U38S7uM5nFShlUQbHIqDH1WRwtODmKmfMhEjUCbFATdjYzavjFyshuq2JxybhTG ojt0tmJNEy+t3hVVIwZzhTwaT2u6OkHXfhaaGMMQ1JOBeLaQAf+J5juLjXldnwMyx9 n93aFaiU/MCcsHNhVAmhypNmW4QJHRdWhiu07tfQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Min Li , Luiz Augusto von Dentz Subject: [PATCH 5.10 46/68] Bluetooth: Fix use-after-free in hci_remove_ltk/hci_remove_irk Date: Mon, 12 Jun 2023 12:26:38 +0200 Message-ID: <20230612101700.330403989@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230612101658.437327280@linuxfoundation.org> References: <20230612101658.437327280@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Luiz Augusto von Dentz commit c5d2b6fa26b5b8386a9cc902cdece3a46bef2bd2 upstream. Similar to commit 0f7d9b31ce7a ("netfilter: nf_tables: fix use-after-free in nft_set_catchall_destroy()"). We can not access k after kfree_rcu() call. Cc: stable@vger.kernel.org Signed-off-by: Min Li Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Greg Kroah-Hartman --- net/bluetooth/hci_core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -2685,10 +2685,10 @@ int hci_remove_link_key(struct hci_dev * int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type) { - struct smp_ltk *k; + struct smp_ltk *k, *tmp; int removed = 0; - list_for_each_entry_rcu(k, &hdev->long_term_keys, list) { + list_for_each_entry_safe(k, tmp, &hdev->long_term_keys, list) { if (bacmp(bdaddr, &k->bdaddr) || k->bdaddr_type != bdaddr_type) continue; @@ -2704,9 +2704,9 @@ int hci_remove_ltk(struct hci_dev *hdev, void hci_remove_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type) { - struct smp_irk *k; + struct smp_irk *k, *tmp; - list_for_each_entry_rcu(k, &hdev->identity_resolving_keys, list) { + list_for_each_entry_safe(k, tmp, &hdev->identity_resolving_keys, list) { if (bacmp(bdaddr, &k->bdaddr) || k->addr_type != addr_type) continue;