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=1796386258; b=tsbmHixmhcxUSU9CXlpl4yG9RqfEvExFifGaswR7cNuiscTWQOpmhoubgEnp5etxBU2x Mo5kn5uYK+IO4m1YzVTe/adYa2tSIM3ZgUvQrGANkSGNtmalaR5U9hqtkM5Hch9yuFnc2 pGF0MTfWQJngkWXGR+Zb4cGUvXCJvV4cKDwlgJg6tOy07fskIJd6s1CtdAyinqjYgoWZS az/dD5ovY+DGTGUdUM9GRswxvveTKDSbLrQghSzD0zfU9QgH0oX8XQjIpvNDQeUFBIpe1 L/h06pbUEbF6HYQU2K179406Keuuoe6LtiPd1j/6NklMKunLzed8lr8TJseB/ipPi3w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386258; 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=wwOWFUPww2Ak2gazwJUEXgzMNDkV67rWDsm7iBO5RCI=; b=vX6tVmSZD+SGwvDt1A4sCIKFslxyFD1Lb3UdB9QxQ5cfgUpJ7VQElbk3DNLomyOnHnP7 vYC7JDUXosL+De24lbnxTbTway4QSPkkPiq45c6yJGg9MAIbuvG3UCOqGqSaTeBp5iyYU A+7JA1wVqGjl5ycHTLgdgCnFrnHvKV3rIdarOPOT4AQqdfu8qlQ97tDuBHu2ROk8o0696 6cmQedXGjcwx7a5UctyZLhG2opn0OBHyWt7o34U0/sKYaQUH2ije0pbcludBU1fzvPumq XVed/O3wHq7ToSNJXMZ+k4dWU9eVKMeA4sYwE+kxDs74oCw8iPda1KbKqJWvqDnKiSQ== 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=gci43thT; 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 2A988606A322; Fri, 4 Dec 2026 12:10:57 +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=gci43thT Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5332D1F0093B; Fri, 4 Dec 2026 12:10:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796386257; bh=wwOWFUPww2Ak2gazwJUEXgzMNDkV67rWDsm7iBO5RCI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gci43thT3LkUrs4iFPhaiAkmxHZ1HSOD6dz7/IEl2457eFOd1RxI0X51jaw4arrjP sIupdiryyV5C036VKtFhBas2C8SH0fG/rhCxgk7hNBxcUO8aZHe9lNHW0V+VCbV1cN 5XazlN8UTAjF5mVzQkogRCfyBIUngje+5iq1aNZs= 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.6 0888/1167] Bluetooth: MSFT: Free the response of the monitor commands Date: Fri, 4 Dec 2026 19:05:15 +0900 Message-ID: <20261204100725.315159176@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@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.6-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 975821b3d5274..9d960eddd9e11 100644 --- a/net/bluetooth/msft.c +++ b/net/bluetooth/msft.c @@ -298,6 +298,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); @@ -439,23 +443,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 */ @@ -520,7 +531,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); @@ -572,19 +582,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