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=1796380093; b=2V9TCooUfMWbvv3+IssvxueRvzLvUhL7HSnvlZ7cYxEP1PL6WxVUrWJla2Dfmtn2uKiZ hg6igILr19GrXDDO608KhUNC1zGXrUSUPEBmfcTV/LffYzLNz3CO0KajrlPKXRNUfw8NE xw424jbsNFg3FPzyttQY+7PGsrF1nAkFddrbnasPnlra20nDp7qKf7Kyg2ojLD+z2fQOv cfQsTqs01uhVnUquRm945zEO/lT1uOUIIACXIFXvqm82rnRH615JhWgI2KHn/x7fCrGQR LHN+dEnzOuFELTRDn61WGgNP9NKh+yJRT2vqFCA7+G6kIG60U9VX0sURw2BLFj7CFog== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380093; 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=iFvuFkAvaDlY25HpXbgY7HMPKS0UtnUVsZWI2juBYFo=; b=OyWg17AqsKvzVlQMIDxiTJSxSFmaKm/NlqUVNB4Zq4V0VJzYBgRERaTCRInFfnWWfuAK NimMc3Vx6zsuRP6MjtS7tLfl4NlaCIBRmN4jAb/rGN//7K7nCcXxHV83MtHNzr+S/Oe9c Ya4WQVKTLJEPlAQK6iHR1BkWxZxQ2cOysnKjZrxYmG3awQRPNLwsDi2LpZK+SdUCePPsv 4tCmnA7S3KV4HPoot7kZTTwaje8iuoygv3Zt//o5KS+xWNZXVbpEbmivVndmaJigxx4Eh 7zypw7Bdk0Oz8NNW4scaU8tJfQv19JAuCdWTTxtl3fHqQP3jH0zQvQf6Omryuwa6gLQ== 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=B2LIgDbf; 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 BF329606A322; Fri, 4 Dec 2026 10:28:13 +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=B2LIgDbf Received: by smtp.kernel.org (Postfix) with ESMTPSA id EAA981F0093A; Fri, 4 Dec 2026 10:28:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380093; bh=iFvuFkAvaDlY25HpXbgY7HMPKS0UtnUVsZWI2juBYFo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=B2LIgDbf2VUIbIHcNxLewj4mSbZKsvcgyGB00e/M2Hniz9/kSWyPk9HvkogumW6MR 3GVJa2phWT2m1XBcbWexjtV0wS9SQWKhXrEURIMuyeoouiffwPXwZoGdWsWpuF8jI4 C6IoC8jEMNSqEp2jl0uSpFmanLXGMEQdTR2QK278= 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 7.3 122/742] Bluetooth: MSFT: Protect the event prefix with hdev->lock Date: Fri, 4 Dec 2026 18:59:46 +0900 Message-ID: <20261204100638.366101780@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@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 7.3-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 2559c5b1bef02..ab63fee3ef597 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