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=1796381782; b=ixxDKV20m5JcvRWPQPaqNeFwynKSLWuMIOjpMJXUSziNYjxEVJirEXNz7xNuPSyRQU0n IY1yEgnvcuyDmwBfpf0EEXod9z7A5I3Jtn9iBTK415Bg+wh/BdBrFMFUsTd2nPM+THE4D yWqYcqkpao2tglBzOLrKCFcoiPUM/Fnr+OSC3e48Na2VRK7GDtZLFll794mAZpQ/+ZPvW n4CgCtAf3o8Gz7x6uXneYKSgJWbyarPQDttD4HqHcaFy+gknHw+e8U7iT+8ivAVN0BCqU 1aCBOkV5mVDZLw7dMRLYxlSmv73oHaz4UQeXGV+cnAyicVQfHfT6fky2deGVvp8Ca3w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381782; 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=0TOxPSIJQNmlb48cWirWMQ+C7xHET71G+VF+4imKPAM=; b=xumhRtPqvl9qH9DEdvMBTPDreu5DnHqaeM5WDQRbVYF1xG+k7NGvN70sypOwHN8bXqRu MFuMUWmDvJksjquH6C+r1uPkPyz/FEB6iCs6AQmHhwmjbCnquTA8XKfdqiEruzYG6Vb4o K3Z5nSiCG67ks48hmgNPO6Zw7eguM68vMALItusJQkTqqvnvtVkn8Vq5nUJ2epAHH/OHc Xa4E+OnW05yVABQ4bSTPCOYEYI6kCOst+5tZp9Cu0RTM8Zdi69N2L48nZnUxaf8foxIfk kx5NRcvWL6jJebdrYkaHPEO958k3BzZ3Yvten2FRRxUoiQqnM4zs7G9ie/LOQd7gQfw== 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=ndWVwIy7; 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 A7F5B606A32C; Fri, 4 Dec 2026 10:56:22 +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=ndWVwIy7 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1EBE01F000C2; Fri, 4 Dec 2026 10:56:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381782; bh=0TOxPSIJQNmlb48cWirWMQ+C7xHET71G+VF+4imKPAM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ndWVwIy7BDGDOCA65mPkhbJhqTwVHJONuIgTwxLSmOnMnydFJ0DoDPGxxPZk+3l6s 1O4GR+KD3SfEWG6kTyyTXtElQ2ANVkbxUY3T3anbljq3+EtXRZ3Mr3dim9mjGhFHmC 2MLb/IWD9p1TJGKfm4eEwXtAdPAUfboMGvkGS3FU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sashiko , Luiz Augusto von Dentz , Sasha Levin Subject: [PATCH 6.18 170/703] Bluetooth: MGMT: Fix use-after-free in mgmt_powering_down() Date: Fri, 4 Dec 2026 19:01:09 +0900 Message-ID: <20261204100632.402420894@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Luiz Augusto von Dentz [ Upstream commit 7c8dcf322b0d978c80001632c1206d5fe1ee9ba7 ] mgmt_powering_down() looked up the Set Powered command and read its parameters after mgmt_pending_find() dropped mgmt_pending_lock, so the command could be unlinked and freed in between. Do the lookup and read the parameters while holding the lock. Reported-by: Sashiko Link: https://sashiko.dev/#/bug/linux-e45413fa-48a6-43f1-90be-638841567534 Fixes: 302a1f674c00 ("Bluetooth: MGMT: Fix possible UAFs") Assisted-by: OpenCode:claude-fable-5.2 Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin --- net/bluetooth/mgmt.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index f589ff7ce6045..4652a19cfecc1 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -10266,19 +10266,27 @@ bool mgmt_powering_down(struct hci_dev *hdev) { struct mgmt_pending_cmd *cmd; struct mgmt_mode *cp; + bool powering_down = false; if (hci_dev_test_flag(hdev, HCI_POWERING_DOWN)) return true; - cmd = pending_find(MGMT_OP_SET_POWERED, hdev); - if (!cmd) - return false; + mutex_lock(&hdev->mgmt_pending_lock); - cp = cmd->param; - if (!cp->val) - return true; + list_for_each_entry(cmd, &hdev->mgmt_pending, list) { + if (hci_sock_get_channel(cmd->sk) != HCI_CHANNEL_CONTROL || + cmd->opcode != MGMT_OP_SET_POWERED) + continue; - return false; + /* cmd can only be freed after it is unlinked under the lock */ + cp = cmd->param; + powering_down = !cp->val; + break; + } + + mutex_unlock(&hdev->mgmt_pending_lock); + + return powering_down; } void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, -- 2.53.0