From mboxrd@z Thu Jan 1 00:00:00 1970 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 8C4EEEE49A3 for ; Tue, 22 Aug 2023 11:32:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234907AbjHVLcq (ORCPT ); Tue, 22 Aug 2023 07:32:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234895AbjHVLcp (ORCPT ); Tue, 22 Aug 2023 07:32:45 -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 917C2CE5; Tue, 22 Aug 2023 04:32:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8B77065255; Tue, 22 Aug 2023 11:32:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7E40C433D9; Tue, 22 Aug 2023 11:32:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692703937; bh=dDHkUqk1PKsZ4OIAUuQPDI7UTkZzYWfMrNe92ciL+4M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FR8bw4JLPIE+YZLZbE4u1mpnwdepbVJ/Fl2g+4pqSK4TkX+XtcS1llYo39eSBGpmR ToGiMX29PIB6p4wwQiY6gvl6K//4K9IBLJsJQ+64zwuRYo1cIN0I6nLfoEjSQh7QaQ 3h35vs94B724Kh172lEPKa8e6LV2eCy9fkOn860B6cc1hixDtx7khRBsxqSqQUS9Hv iondrxb0uhqEDGyIgj0vUgq8ztEgG1sG1b7mhc8vq1IV2oaJP7Wr47OZ6voUKN4hlA /uPOJ5D9LoYlW8tQwWSsZFCs1Hh9nId7LNLf1sA3HaVhaQgQ9BCZgMwbXXn+eWKcCT 5i1TeAsuRMPlg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Hans de Goede , Kees Cook , Franky Lin , Kalle Valo , Sasha Levin , aspriel@gmail.com, hante.meuleman@broadcom.com, linus.walleij@linaro.org, marcan@marcan.st, gustavoars@kernel.org, ryohei.kondo@cypress.com, linux-wireless@vger.kernel.org, brcm80211-dev-list.pdl@broadcom.com, SHA-cyfmac-dev-list@infineon.com Subject: [PATCH AUTOSEL 5.10 4/4] wifi: brcmfmac: Fix field-spanning write in brcmf_scan_params_v2_to_v1() Date: Tue, 22 Aug 2023 07:32:06 -0400 Message-Id: <20230822113207.3550238-4-sashal@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230822113207.3550238-1-sashal@kernel.org> References: <20230822113207.3550238-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.10.191 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Hans de Goede [ Upstream commit 16e455a465fca91907af0108f3d013150386df30 ] Using brcmfmac with 6.5-rc3 on a brcmfmac43241b4-sdio triggers a backtrace caused by the following field-spanning warning: memcpy: detected field-spanning write (size 120) of single field "¶ms_le->channel_list[0]" at drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c:1072 (size 2) The driver still works after this warning. The warning was introduced by the new field-spanning write checks which were enabled recently. Fix this by replacing the channel_list[1] declaration at the end of the struct with a flexible array declaration. Most users of struct brcmf_scan_params_le calculate the size to alloc using the size of the non flex-array part of the struct + needed extra space, so they do not care about sizeof(struct brcmf_scan_params_le). brcmf_notify_escan_complete() however uses the struct on the stack, expecting there to be room for at least 1 entry in the channel-list to store the special -1 abort channel-id. To make this work use an anonymous union with a padding member added + the actual channel_list flexible array. Cc: Kees Cook Signed-off-by: Hans de Goede Reviewed-by: Kees Cook Reviewed-by: Franky Lin Signed-off-by: Kalle Valo Link: https://lore.kernel.org/r/20230729140500.27892-1-hdegoede@redhat.com Signed-off-by: Sasha Levin --- .../net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h index 2e31cc10c1954..f1ad6f2cb6fbe 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h @@ -383,7 +383,12 @@ struct brcmf_scan_params_le { * fixed parameter portion is assumed, otherwise * ssid in the fixed portion is ignored */ - __le16 channel_list[1]; /* list of chanspecs */ + union { + __le16 padding; /* Reserve space for at least 1 entry for abort + * which uses an on stack brcmf_scan_params_le + */ + DECLARE_FLEX_ARRAY(__le16, channel_list); /* chanspecs */ + }; }; struct brcmf_scan_results { -- 2.40.1