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=1796383359; b=cKe1lkepGpGeH2jhMLEpMJuq4wEF5KwAtYLv1epT1DFhs1gvOx0PmOcjQ+BzJzPJ7CJE Z9SOMOK0cj07tmYwaxKESZH0YGMBH6XzJ/u+zdEpysVzojG8zUt7JpYSMErpOPExiWPPZ bPw9Xzgfc8SdfPBv2jReSYi+3pSRVNZI1okSEH06r00jjsY9jJImgZmxcRrvCSmM2cSOF 3Wz8fWVAVVPw11Jw3ExWawRbI20N7XvCBc+ONHl0LiWJL6xV6eOfXeO0shHQqZdrAA6la riKbKWWEHsWJ0r3s+vQ16mSrjegTicaKYv41BkHkNkIZsJ5ii8Tpp2ORgZCSlJyY9Zg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383359; 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=E2GMxiLqDvSZsfFDC8BA59lbjpyycI1UBtiOZdVULBw=; b=ySqiu94EZlb/wqNob3eRz47+AHF7bF3j+5Z1rZPqz8cfBDekPRMH4hK3YpL4+km/uG9f nqr2vHIeNdrw5nuudvzpuTBQrmjj7ta0AgCuSabS1nX4X+ELfOwl2OIiRrh+vNdNiCKVA eRXZG/D/TLDpW1VilI0JHPEr02C4LwPu+uqg3wqhk05+EvU7oWpdMJw7mzguOL7QTKT0L I5fJs3jflTpICcZtG4lkmpwKiZUwBiZCLIxkus9Pz2kxF3UjDuNU0Dj4vzdVORogd24Hm HEBZrtDkxnRa7OrN15Bh70A1lr4RbzsAgdhFGvTMnH1nMAetMRXBZ5DWyL8tYEHlFLw== 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=usTKdRoo; 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 7A4BE606A32C; Fri, 4 Dec 2026 11:22:39 +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=usTKdRoo Received: by smtp.kernel.org (Postfix) with ESMTPSA id E61401F000CE; Fri, 4 Dec 2026 11:22:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383359; bh=E2GMxiLqDvSZsfFDC8BA59lbjpyycI1UBtiOZdVULBw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=usTKdRoo1Txwy0ApC1LFvqFCptPrkq+eFFwp/Ap9USzb14+favdCpYr1BG8qSrouC 8QQwWqwWfSgwOT5iVNberEXEs2ULGTEBJRahjkYSGGCCPZD9TeVkho29xIpotcsKqC mlGeKOp+sFOLvm/MX2ItI2LmT/A5tvk3sNTDeaKs= 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.12 194/555] Bluetooth: MSFT: Free the response of the monitor commands Date: Fri, 4 Dec 2026 19:03:57 +0900 Message-ID: <20261204100615.557198936@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@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.12-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 5be09fce557de..cd42b020c6c8d 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