From nobody Fri Dec 19 19:23:30 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A7ACFA3740 for ; Mon, 24 Oct 2022 13:07:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235399AbiJXNH6 (ORCPT ); Mon, 24 Oct 2022 09:07:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235360AbiJXNGJ (ORCPT ); Mon, 24 Oct 2022 09:06:09 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA91B2CE22; Mon, 24 Oct 2022 05:20:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5F27A611B0; Mon, 24 Oct 2022 12:20:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 750B2C433C1; Mon, 24 Oct 2022 12:20:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614034; bh=nL/pAzm+dIZFsdEKGBzZs3U4ggfZzyn+WAnDW5EQt4w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mOeot6D9ih3nzfvvNX5WN3spDLUyPR9tvuJ5Y/agP0H+HHpxSuB8Nk+25hNMQ7DW1 bN3SZLa7ZAzWEapUD0fWMguRvJXAAt4vvftNI1AwqiSst6VvE4ojisMTaWumXt/hC2 UWJ3xC1zoDQ1if5bD+D7cwRerB+/qyvmqEwhOcmM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arnd Bergmann , Marcel Holtmann , Sasha Levin Subject: [PATCH 5.10 107/390] Bluetooth: btusb: fix excessive stack usage Date: Mon, 24 Oct 2022 13:28:24 +0200 Message-Id: <20221024113027.248824888@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Arnd Bergmann [ Upstream commit 10888140f09c3472146dc206accd0cfa051d0ed4 ] Enlarging the size of 'struct btmtk_hci_wmt_cmd' makes it no longer fit on the kernel stack, as seen from this compiler warning: drivers/bluetooth/btusb.c:3365:12: error: stack frame size of 1036 bytes in= function 'btusb_mtk_hci_wmt_sync' [-Werror,-Wframe-larger-than=3D] Change the function to dynamically allocate the buffer instead. As there are other sleeping functions called from the same location, using GFP_KERNEL should be fine here, and the runtime overhead should not matter as this is rarely called. Unfortunately, I could not figure out why the message size is increased in the previous patch. Using dynamic allocation means any size is possible now, but there is still a range check that limits the total size (including the five-byte header) to 255 bytes, so whatever was intended there is now undone. Fixes: 48c13301e6ba ("Bluetooth: btusb: Fine-tune mt7663 mechanism.") Signed-off-by: Arnd Bergmann Signed-off-by: Marcel Holtmann Stable-dep-of: fd3f106677ba ("Bluetooth: btusb: mediatek: fix WMT failure d= uring runtime suspend") Signed-off-by: Sasha Levin --- drivers/bluetooth/btusb.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index eb6e33d168d8..80a3d5019950 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -2832,7 +2832,7 @@ struct btmtk_wmt_hdr { =20 struct btmtk_hci_wmt_cmd { struct btmtk_wmt_hdr hdr; - u8 data[1000]; + u8 data[]; } __packed; =20 struct btmtk_hci_wmt_evt { @@ -3011,7 +3011,7 @@ static int btusb_mtk_hci_wmt_sync(struct hci_dev *hde= v, struct btmtk_hci_wmt_evt_funcc *wmt_evt_funcc; u32 hlen, status =3D BTMTK_WMT_INVALID; struct btmtk_hci_wmt_evt *wmt_evt; - struct btmtk_hci_wmt_cmd wc; + struct btmtk_hci_wmt_cmd *wc; struct btmtk_wmt_hdr *hdr; int err; =20 @@ -3020,20 +3020,24 @@ static int btusb_mtk_hci_wmt_sync(struct hci_dev *h= dev, if (hlen > 255) return -EINVAL; =20 - hdr =3D (struct btmtk_wmt_hdr *)&wc; + wc =3D kzalloc(hlen, GFP_KERNEL); + if (!wc) + return -ENOMEM; + + hdr =3D &wc->hdr; hdr->dir =3D 1; hdr->op =3D wmt_params->op; hdr->dlen =3D cpu_to_le16(wmt_params->dlen + 1); hdr->flag =3D wmt_params->flag; - memcpy(wc.data, wmt_params->data, wmt_params->dlen); + memcpy(wc->data, wmt_params->data, wmt_params->dlen); =20 set_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags); =20 - err =3D __hci_cmd_send(hdev, 0xfc6f, hlen, &wc); + err =3D __hci_cmd_send(hdev, 0xfc6f, hlen, wc); =20 if (err < 0) { clear_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags); - return err; + goto err_free_wc; } =20 /* Submit control IN URB on demand to process the WMT event */ @@ -3055,13 +3059,14 @@ static int btusb_mtk_hci_wmt_sync(struct hci_dev *h= dev, if (err =3D=3D -EINTR) { bt_dev_err(hdev, "Execution of wmt command interrupted"); clear_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags); - return err; + goto err_free_wc; } =20 if (err) { bt_dev_err(hdev, "Execution of wmt command timed out"); clear_bit(BTUSB_TX_WAIT_VND_EVT, &data->flags); - return -ETIMEDOUT; + err =3D -ETIMEDOUT; + goto err_free_wc; } =20 /* Parse and handle the return WMT event */ @@ -3097,7 +3102,8 @@ static int btusb_mtk_hci_wmt_sync(struct hci_dev *hde= v, err_free_skb: kfree_skb(data->evt_skb); data->evt_skb =3D NULL; - +err_free_wc: + kfree(wc); return err; } =20 --=20 2.35.1