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=1796381791; b=vstA6MVev0K9Xpstf03scOFY7DbiVOE24VbxFm1jSGMyYimpTQyHPxf2xnEI3uso1sfW DbmbWYGh+RyAof3VkOedfEP/M/i+nGm0F+gwk3N2fHw5r95lo8Eyyc4j6uoVlb+g5dGYl dpV6DkTNFuhzLlnOg5RkV+YXloAYKEaOmBy4pO4Mxi4V3yUiKwUKIvnAnNML5N/hfYucn KSpIuJ7OPRLSQAo5++zkiMhY1g0QoDHti+FEJ7v1U7OYACZJbUBGrx70veaMmNqKuUgUY V/wY2kYDLN0mlSnrXoqearLXmx4SJGmMj5jJv3Oz63M9qroTRpMWCpw5dkoCI+ksILw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381791; 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=87S8587Ip+tqTpwZe2RzIOi1bIp4c/WeR/wi3TAScyc=; b=suT5RyRCI3xl4439pkab5qg9TWRkEXYyijI2FqB3Bm1c0s1N2anQA0q2GHqoictYEgjx LBkaMIlElPpUdF7GUsfWFkxWxhSkCLFszeN6JX7upqGKSpqVp9XAn0IQQkuy4Cx1f6+E1 Kuf+h4PkcMfeS+Xguv7NOqRrqWpwi3pdZ9+yznV+3lVnSAu9wb/KAiQAp6KgqsekV8gnh G0iUxb/wN7lOxVwqkvXxhqBZiAZmMaIGOIXG7zMqiknCvTLlnTYubFFlxPD3WF0xukI6f 9apCNdpNZ0x408ELOJqPLSc/IYUU13QV42BJynCtRHMe4TP2pnQz18Ny02l36tzlMcg== 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=nSTd0tuF; 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 BABF9606A322; Fri, 4 Dec 2026 10:56:31 +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=nSTd0tuF Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31CF91F000CE; Fri, 4 Dec 2026 10:56:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381791; bh=87S8587Ip+tqTpwZe2RzIOi1bIp4c/WeR/wi3TAScyc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=nSTd0tuFhF3Vjs1+JFzyAgsLQlZ2yu864moXS6bLRc7/5doOFVPvac1doF7DpFgVi vaGLCvZnchCMVKM8lY0mKA4PrUfSMI01Mx60p6gJcjlEqBSZ1JJ5LmPmgi9Ilw7MqP FB/iP9XwikzcVHGk4znr1lWHMCJK4ApgvbDe2E4c= 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 174/703] Bluetooth: MSFT: Free the response of the monitor commands Date: Fri, 4 Dec 2026 19:01:13 +0900 Message-ID: <20261204100632.505945231@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 775eca0c3df2f0272f21ebc8c812ad010fd47243 ] msft_add_monitor_sync() and msft_remove_monitor_sync() send the MSFT command with __hci_cmd_sync() and pass the returned skb to the callbacks, which only parse it, so it is never freed. Free it once the callback returns. While at it initialize the RSSI fields of the handle data when it is created instead of after the command completed, so they are never exposed uninitialized, and do the lookup of the handle map in msft_remove_monitor_sync() with hdev->lock held. Found by the sashiko.dev review of the previous revision of this series. Reported-by: Sashiko Link: https://sashiko.dev/#/patchset/20261117185737.3758255-1-luiz.dentz%40gmail.com Fixes: b747a83690c8 ("Bluetooth: hci_sync: Refactor add Adv Monitor") Fixes: 7cf5c2978f23 ("Bluetooth: hci_sync: Refactor remove Adv Monitor") Assisted-by: OpenCode:claude-fable-5.2 Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin --- net/bluetooth/msft.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/net/bluetooth/msft.c b/net/bluetooth/msft.c index 14b761e944f81..da6de53d12637 100644 --- a/net/bluetooth/msft.c +++ b/net/bluetooth/msft.c @@ -297,6 +297,10 @@ static int msft_le_monitor_advertisement_cb(struct hci_dev *hdev, u16 opcode, handle_data->mgmt_handle = monitor->handle; handle_data->msft_handle = rp->handle; handle_data->cond_type = MSFT_MONITOR_ADVERTISEMENT_TYPE_PATTERN; + handle_data->rssi_high = monitor->rssi.high_threshold; + handle_data->rssi_low = monitor->rssi.low_threshold; + handle_data->rssi_low_interval = (u8)monitor->rssi.low_threshold_timeout; + handle_data->rssi_sampling_period = monitor->rssi.sampling_period; INIT_LIST_HEAD(&handle_data->list); list_add(&handle_data->list, &msft->handle_map); @@ -438,23 +442,30 @@ static int msft_remove_monitor_sync(struct hci_dev *hdev, struct msft_cp_le_cancel_monitor_advertisement cp; struct msft_monitor_advertisement_handle_data *handle_data; struct sk_buff *skb; + int err; + hci_dev_lock(hdev); handle_data = msft_find_handle_data(hdev, monitor->handle, true); + if (handle_data) + cp.handle = handle_data->msft_handle; + hci_dev_unlock(hdev); /* If no matched handle, just remove without telling controller */ if (!handle_data) return -ENOENT; cp.sub_opcode = MSFT_OP_LE_CANCEL_MONITOR_ADVERTISEMENT; - cp.handle = handle_data->msft_handle; skb = __hci_cmd_sync(hdev, hdev->msft_opcode, sizeof(cp), &cp, HCI_CMD_TIMEOUT); if (IS_ERR(skb)) return PTR_ERR(skb); - return msft_le_cancel_monitor_advertisement_cb(hdev, hdev->msft_opcode, - monitor, skb); + err = msft_le_cancel_monitor_advertisement_cb(hdev, hdev->msft_opcode, + monitor, skb); + kfree_skb(skb); + + return err; } /* This function requires the caller holds hci_req_sync_lock */ @@ -519,7 +530,6 @@ static int msft_add_monitor_sync(struct hci_dev *hdev, { struct msft_cp_le_monitor_advertisement *cp; struct msft_le_monitor_advertisement_pattern_data *pattern_data; - struct msft_monitor_advertisement_handle_data *handle_data; struct msft_le_monitor_advertisement_pattern *pattern; struct adv_pattern *entry; size_t total_size = sizeof(*cp) + sizeof(*pattern_data); @@ -571,19 +581,7 @@ static int msft_add_monitor_sync(struct hci_dev *hdev, err = msft_le_monitor_advertisement_cb(hdev, hdev->msft_opcode, monitor, skb); - if (err) - goto out_free; - - handle_data = msft_find_handle_data(hdev, monitor->handle, true); - if (!handle_data) { - err = -ENODATA; - goto out_free; - } - - handle_data->rssi_high = cp->rssi_high; - handle_data->rssi_low = cp->rssi_low; - handle_data->rssi_low_interval = cp->rssi_low_interval; - handle_data->rssi_sampling_period = cp->rssi_sampling_period; + kfree_skb(skb); out_free: kfree(cp); -- 2.53.0