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=1796383355; b=pFB0WXrk4pBNIn4li8hmPBwZ57JjDwMzBbl+MPwfnHEeXwUuOyJxvYReCTEDhN1UPUlT 6POOVm1bH2GGrpXkMrZyDfWsheVxseyrbWn5OqfD5Du0lAWgq3TaxxBu47hVUKxGoHyHT pIOUcmx0NeK4B1mvBfw90kyl+HlMXU7VWJ0eP8mYqRX5DnUYZwIY2WTaaeysGb0ugaE7a xDJZ8HFq73GOMwXTauDshdTowmSjdmOWD+UprTxdQNSJrOfJgVsTdYql1ARI+c+R3bocv zYXL2WlSm2h3hrbFFbVrOLks1LNTlTIdzvBPmoDW9LymtIQLmbx0F3Cx7y9XpEnKxCw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383355; 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=qqfMMeWYxBmbg8wM1xa+oh22VrbtR9HHThAhQAIDFIc=; b=XPkBM2q07yOlx9yuS38TkAXd8us2kV1HmQtAArGC1hO0tF5tygTIU1jhkCBIfZcIiuzj hQMgKY7DcAZrQFqT8dIdsu1Gl6JVHd9w/bHwvKa7TLtO8QhFDkLtdUmwYbcABAdoZyePD 9uh2rJ/LTPRhyk7UvE5senEcH5rb4nuQiJhKLoo20WVtrrohXRxLPryW4N4MoYH7er0z+ yhwIILysIRgTWmvKWvkT3DgmXTt/zx/wUxx8r5Gro7xwQwPn9ynpY3lgJK/kwpPOZ8xSG sJqjnJx/kJlDlObJztoRrDbEd7dPzye+EkaypaAnxgzx4ABZxoQlvutkdHfpdM/MO5A== 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=ySvU9JpA; 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 E5C83606A322; Fri, 4 Dec 2026 11:22:34 +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=ySvU9JpA Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6378F1F000C2; Fri, 4 Dec 2026 11:22:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383354; bh=qqfMMeWYxBmbg8wM1xa+oh22VrbtR9HHThAhQAIDFIc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ySvU9JpApKiEkaGEOSgzza2lOt5gmN04unl31E+PVQUmZ/MMO74xIra+o7JQV8vku 2EHUnNwsqIULGZ3M4BkxS25jURkJKVQr1ycYSvHNWvGnpLYPx1XgTYCZ+5zcWmnPdY K5M3GyjATTGUyNzR08qLXbZIN4TFn5G7COezoKFk= 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 192/555] Bluetooth: MSFT: Protect the event prefix with hdev->lock Date: Fri, 4 Dec 2026 19:03:55 +0900 Message-ID: <20261204100615.467418177@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 0434cd10518c1b58ca3f5366341f0b1c469afbca ] msft_vendor_evt() read msft->evt_prefix_len and compared evt_prefix before taking hdev->lock, while msft_do_open() (and the supported features reply) free and reallocate the prefix without it, so an event received while the controller is being opened could access freed memory. Take hdev->lock for the whole event processing and while updating the prefix. Reported-by: Sashiko Link: https://sashiko.dev/#/bug/linux-246df501-f32c-46fd-8779-7fa755ed7f9d Fixes: 5031ffcc79b8 ("Bluetooth: Keep MSFT ext info throughout a hci_dev's life cycle") Assisted-by: OpenCode:claude-fable-5.2 Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin --- net/bluetooth/msft.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/net/bluetooth/msft.c b/net/bluetooth/msft.c index feaabfd5399f4..5be09fce557de 100644 --- a/net/bluetooth/msft.c +++ b/net/bluetooth/msft.c @@ -170,11 +170,16 @@ static bool read_supported_features(struct hci_dev *hdev, goto failed; } + /* The event prefix is used by msft_vendor_evt() with hdev->lock held */ + hci_dev_lock(hdev); + if (rp->evt_prefix_len > 0) { msft->evt_prefix = kmemdup(rp->evt_prefix, rp->evt_prefix_len, GFP_KERNEL); - if (!msft->evt_prefix) + if (!msft->evt_prefix) { + hci_dev_unlock(hdev); goto failed; + } } msft->evt_prefix_len = rp->evt_prefix_len; @@ -183,6 +188,8 @@ static bool read_supported_features(struct hci_dev *hdev, if (msft->features & MSFT_FEATURE_MASK_CURVE_VALIDITY) hdev->msft_curve_validity = true; + hci_dev_unlock(hdev); + kfree_skb(skb); return true; @@ -648,10 +655,12 @@ void msft_do_open(struct hci_dev *hdev) bt_dev_dbg(hdev, "Initialize MSFT extension"); /* Reset existing MSFT data before re-reading */ + hci_dev_lock(hdev); kfree(msft->evt_prefix); msft->evt_prefix = NULL; msft->evt_prefix_len = 0; msft->features = 0; + hci_dev_unlock(hdev); if (!read_supported_features(hdev, msft)) { hci_dev_lock(hdev); @@ -1078,12 +1087,15 @@ static void msft_monitor_device_evt(struct hci_dev *hdev, struct sk_buff *skb) void msft_vendor_evt(struct hci_dev *hdev, void *data, struct sk_buff *skb) { - struct msft_data *msft = hdev->msft_data; + struct msft_data *msft; u8 *evt_prefix; u8 *evt; + hci_dev_lock(hdev); + + msft = hdev->msft_data; if (!msft) - return; + goto unlock; /* When the extension has defined an event prefix, check that it * matches, and otherwise just return. @@ -1091,23 +1103,21 @@ void msft_vendor_evt(struct hci_dev *hdev, void *data, struct sk_buff *skb) if (msft->evt_prefix_len > 0) { evt_prefix = msft_skb_pull(hdev, skb, 0, msft->evt_prefix_len); if (!evt_prefix) - return; + goto unlock; if (memcmp(evt_prefix, msft->evt_prefix, msft->evt_prefix_len)) - return; + goto unlock; } /* Every event starts at least with an event code and the rest of * the data is variable and depends on the event code. */ if (skb->len < 1) - return; + goto unlock; evt = msft_skb_pull(hdev, skb, 0, sizeof(*evt)); if (!evt) - return; - - hci_dev_lock(hdev); + goto unlock; switch (*evt) { case MSFT_EV_LE_MONITOR_DEVICE: @@ -1121,6 +1131,7 @@ void msft_vendor_evt(struct hci_dev *hdev, void *data, struct sk_buff *skb) break; } +unlock: hci_dev_unlock(hdev); } -- 2.53.0