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=1796388937; b=zDeZ7I52/M9LXEYEPpx72zGGKzL0mroUFyOHHBSxV2BF8CO3BJ/KAIxaBmOnapg5sYC7 jbBR2b7Ke24APBP551CQjaQPDRdovFXJOG4dwI0RkVA6zR8AXSeKeu1ICCHQSD+/1Vhju BBnsECo3M+M3+gGYANOo69rXBURHh35ah5991wcniTvqUs+F7/6UcIA7Akz7nfCauAHAZ +AtWaAravuVTFfeZUfBjFsdzIVpyVzhrN9O9AhO3LmtFkHLAxNfwGcWnIQd+kBLygbYUm AZK+F9QnwL9r1lKWaMVlyYEviTx4ZCMo5DWTkIpm113Z7v2ppCstCcp0D9io5wRfLbQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388937; 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=GFr4pCxPGefxTxHJ+7O0dz99D6fEK0yrx99m0+4brxg=; b=R/+kB3G5ODPJSuDdOlL/osPlUxe5m2AWYZQX58AoMOteu16GSOTihcHCeMczCwZzaNIp 8QkdxcvxR/nwGJdF0slEXfyeAqaIaJZ+CX1Ofrk2xnLrwEFBjiHloYzY6NVy4ryoCwVdT gosk65nj2iej77Yiv6rIoWvVHeaYBrbESC5s3Ky+08D8biICMkyV7cxtGcNvr+4BC/L1E 9xb8MrIj3fNjmqhqutYy69gHN622mEvDEo6YXRESTX1NjD337PHKaYcz2YwekyQswQXlQ +dfvwcixTWna/d/hdoY+pZ+tp9aruI39xNBqm2ATZfXUUUnSUltDW8P1wKbHnXwPQxA== 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=bCpivDcp; 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 9D910606A32C; Fri, 4 Dec 2026 12:55:37 +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=bCpivDcp Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB7B21F000C2; Fri, 4 Dec 2026 12:55:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796388937; bh=GFr4pCxPGefxTxHJ+7O0dz99D6fEK0yrx99m0+4brxg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bCpivDcpN2aOFMZcjOdL8Llv931dSFGPl+LWdI9jlzZUpzLUnsn+DS+ZZuYTM7XTi zdnTYXDZor6LZH+igwPuW0ZkLZuQa+HiXkZzbLVHSMZfP6VWu5v8RMb3L2W+Jeu5YO e80gVXozNbXjiwcIm3LV+ngoXiEcPdFL870naPiw= 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.1 0800/1059] Bluetooth: MSFT: Free the response of the monitor commands Date: Fri, 4 Dec 2026 19:05:31 +0900 Message-ID: <20261204100704.751131986@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-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 18c3d3a741369..a89d77845ddde 100644 --- a/net/bluetooth/msft.c +++ b/net/bluetooth/msft.c @@ -301,6 +301,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); @@ -442,15 +446,19 @@ 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); @@ -460,8 +468,11 @@ static int msft_remove_monitor_sync(struct hci_dev *hdev, 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 */ @@ -526,7 +537,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); @@ -578,19 +588,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