Message ID | 20230913065421.12615-1-juerg.haefliger@canonical.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp952912vqx; Wed, 13 Sep 2023 02:14:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGLFsA62An7w2iD+5XDyHWB361RBTzq6EuXK63X94kGi4Gl+KXqUeTQe2g+c3hi2qhkW3Lu X-Received: by 2002:a05:6a00:4293:b0:68f:c4a2:fb1f with SMTP id bx19-20020a056a00429300b0068fc4a2fb1fmr6256839pfb.8.1694596496688; Wed, 13 Sep 2023 02:14:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694596496; cv=none; d=google.com; s=arc-20160816; b=EnTJ2sEOqgVM9E7lJ1XuGFgsJY/gRHP4JPwcBkrr+tztYzlCgoo6epcdVxrKthaVcD WsOvkcbx9x3GoNeqwDxNuGE6bXM3n1HQc4C6J79WdfDxQCWU3J16CORhOso0vOXycWSW AcDqbSFP3buPOBQLj3KnOXxeUDQsDP6mxUqMEeE2tZrn51gkeFlqoUTEk0XpXLEJBm/M Cr9/KLrGzCKsxsTVWgMIdaUvqRFltNfhfxMpf2OP5++DNY/o7htco/4eIy+7fhO64HEU pKraztxOnoMHq2nbuizy+QbZzaFO4fF5nV5O6hJOVZ/a1ml0jz9HsXb+BXn0cZ1uvXQF Np6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=AuUP4uMpEXV7NNGmRh7ocQP9g6lCntCtTGB6qti7vSI=; fh=x2Uhma503s5N245PYHEyaDmwPfhDfN0wH/K/RGzgZWU=; b=BP7nqREqvPRojYhP+JXKX/bH6e5KLUvT4n81iNbVBQ+b0NRCXePxhRiTgBFTtuShbn 3F+yVS9ZXADOltTHzTrKxqr3kSDZs8Zq6s9bLWecpZrWLxPTxGaletXt25aAwfGVnWfG GPNCvniI84Akko5d86DyzK/Teg2Ba//2TmNnIyzl3wUC9QEaZYwVdZVqa+HzUhxiNmm9 nrRUZaiFcJ3VTunoSLflDKhma4yVCjbyOiiGdMCfcgIrbL0IoUwldAkeQRJLU5O6DFjN YzPU7zksIwFxlT2IQX5lotBCd1/oIOxrzCFINx3l6eKAGn+BW10FpzzEpRNvntx9zpKW D6jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=dbVnMbrW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id d20-20020a656214000000b0057403c26ea0si9285746pgv.391.2023.09.13.02.14.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 02:14:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=dbVnMbrW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 1D6CA82A9BA3; Tue, 12 Sep 2023 23:55:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231848AbjIMGy5 (ORCPT <rfc822;pwkd43@gmail.com> + 35 others); Wed, 13 Sep 2023 02:54:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233675AbjIMGy4 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 13 Sep 2023 02:54:56 -0400 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93DA8173E for <linux-kernel@vger.kernel.org>; Tue, 12 Sep 2023 23:54:52 -0700 (PDT) Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id C8C603F66D for <linux-kernel@vger.kernel.org>; Wed, 13 Sep 2023 06:54:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1694588088; bh=AuUP4uMpEXV7NNGmRh7ocQP9g6lCntCtTGB6qti7vSI=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=dbVnMbrWmQxKxpmeBZn21P37wx8Jwy7Q9l+qoco8L82/3oDWEdQgRo5NAdwY6ilPD GoAxWx7bJ+wFO5q1Jw+ZbdyEmGDRODVJTJIuqO9/8V2g78kLtuw9E+y1JRmps8a5rS vBRbRuBZgjo0cIpEp4UyFDx/Bmd+baQAnZNvjiZ+9Ha9jkg0POvuGwyY3oNtUIMCSI qJBZRj3A2Gdqbyhjs5Qn/C1Rkl4xa2qutFWHIHKWyeoMjR0BfLJXcJzKQNhjKu7isO 8CB998WmKFCYotnosfYnXCmMd66M7UK3V83FOpCiGb9artwIoZzM13zDQRyQb+yyj8 WmfxOc9J5PI7A== Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-401c19fc097so50559395e9.1 for <linux-kernel@vger.kernel.org>; Tue, 12 Sep 2023 23:54:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694588088; x=1695192888; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AuUP4uMpEXV7NNGmRh7ocQP9g6lCntCtTGB6qti7vSI=; b=ZMDOyjJTwSqfm7kSKKLSX2QVdRL59d1fMKKR7GZbAbqI4eG/JhPgD2WCxxVC+gZpj6 +8JFs4EkB51UwCN4339akXrfFOcAJBob+iWFkayyEH3n/C7uBtvSqJhfsifnlg21LUAn DerMgmx3tXtj1pjq9b04kpH3Vv1I2QZ0TRdq8zZqcwLC9r0BZ5lqnr8XrwxY67SUh0X0 XLmdO/5GWTpLQkH6qXuxehfU6/wSMSP3fRwAyR5Nbq3aZBGx7TKSTwZcCgPOPeCXQx2G 1q3JGN3kiwB0Z9+25m8cR0ONYPnkhCXfCLEWsh7sjpsg8QwJt+H8F2aVdFtc0S/phhu6 89bA== X-Gm-Message-State: AOJu0YyJIUk0SQPOX1wv+gSQec4/2oygkUIleb7QDNChE5WF4iYezVoG D3l8aF1wuc7YOdC+CEvhh9lbUvU8nXUhzZmeWC2ZQf8lzkG3e2j+zZzCkQkZUn6o9WCZNJl3bl0 7BHgSZ2tO04XU3FPEIdV+zKe5t9cGT/E1n0mquA93ow== X-Received: by 2002:a7b:c44b:0:b0:3f7:f2d0:b904 with SMTP id l11-20020a7bc44b000000b003f7f2d0b904mr1142857wmi.8.1694588088526; Tue, 12 Sep 2023 23:54:48 -0700 (PDT) X-Received: by 2002:a7b:c44b:0:b0:3f7:f2d0:b904 with SMTP id l11-20020a7bc44b000000b003f7f2d0b904mr1142836wmi.8.1694588088217; Tue, 12 Sep 2023 23:54:48 -0700 (PDT) Received: from localhost ([194.191.244.86]) by smtp.gmail.com with ESMTPSA id 22-20020a05600c231600b003fef6881350sm1097497wmo.25.2023.09.12.23.54.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 23:54:47 -0700 (PDT) From: Juerg Haefliger <juerg.haefliger@canonical.com> To: aspriel@gmail.com, franky.lin@broadcom.com, hante.meuleman@broadcom.com, kvalo@kernel.org, linux-wireless@vger.kernel.org, brcm80211-dev-list.pdl@broadcom.com, SHA-cyfmac-dev-list@infineon.com Cc: linux-kernel@vger.kernel.org, linus.walleij@linaro.org, marcan@marcan.st, keescook@chromium.org, gustavoars@kernel.org, hdegoede@redhat.com, juerg.haefliger@canonical.com, ryohei.kondo@cypress.com Subject: [PATCH] wifi: brcmfmac: Replace 1-element arrays with flexible arrays Date: Wed, 13 Sep 2023 08:54:21 +0200 Message-Id: <20230913065421.12615-1-juerg.haefliger@canonical.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 12 Sep 2023 23:55:18 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776912175466163351 X-GMAIL-MSGID: 1776913216238461454 |
Series |
wifi: brcmfmac: Replace 1-element arrays with flexible arrays
|
|
Commit Message
Juerg Haefliger
Sept. 13, 2023, 6:54 a.m. UTC
Since commit 2d47c6956ab3 ("ubsan: Tighten UBSAN_BOUNDS on GCC"),
UBSAN_BOUNDS no longer pretends 1-element arrays are unbounded. Walking
'element' and 'channel_list' will trigger warnings, so make them proper
flexible arrays.
False positive warnings were:
UBSAN: array-index-out-of-bounds in drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c:6984:20
index 1 is out of range for type '__le32 [1]'
UBSAN: array-index-out-of-bounds in drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c:1126:27
index 1 is out of range for type '__le16 [1]'
for these lines of code:
6884 ch.chspec = (u16)le32_to_cpu(list->element[i]);
1126 params_le->channel_list[i] = cpu_to_le16(chanspec);
Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com>
---
.../wireless/broadcom/brcm80211/brcmfmac/fwil_types.h | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
Comments
On Wed, 13 Sep 2023 11:58:07 +0300 Kalle Valo <kvalo@kernel.org> wrote: > Juerg Haefliger <juerg.haefliger@canonical.com> writes: > > > Since commit 2d47c6956ab3 ("ubsan: Tighten UBSAN_BOUNDS on GCC"), > > UBSAN_BOUNDS no longer pretends 1-element arrays are unbounded. Walking > > 'element' and 'channel_list' will trigger warnings, so make them proper > > flexible arrays. > > > > False positive warnings were: > > > > UBSAN: array-index-out-of-bounds in drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c:6984:20 > > index 1 is out of range for type '__le32 [1]' > > > > UBSAN: array-index-out-of-bounds in drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c:1126:27 > > index 1 is out of range for type '__le16 [1]' > > > > for these lines of code: > > > > 6884 ch.chspec = (u16)le32_to_cpu(list->element[i]); > > > > 1126 params_le->channel_list[i] = cpu_to_le16(chanspec); > > > > Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com> > > Should this be queued for v6.6? I would think so. It's a problem since 6.5. Which reminds me that I should have added: Cc: stable@vger.kernel.org # 6.5+ ...Juerg
On Wed, Sep 13, 2023 at 8:54 AM Juerg Haefliger <juerg.haefliger@canonical.com> wrote: > Since commit 2d47c6956ab3 ("ubsan: Tighten UBSAN_BOUNDS on GCC"), > UBSAN_BOUNDS no longer pretends 1-element arrays are unbounded. Walking > 'element' and 'channel_list' will trigger warnings, so make them proper > flexible arrays. > > False positive warnings were: > > UBSAN: array-index-out-of-bounds in drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c:6984:20 > index 1 is out of range for type '__le32 [1]' > > UBSAN: array-index-out-of-bounds in drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c:1126:27 > index 1 is out of range for type '__le16 [1]' > > for these lines of code: > > 6884 ch.chspec = (u16)le32_to_cpu(list->element[i]); > > 1126 params_le->channel_list[i] = cpu_to_le16(chanspec); > > Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com> Obviously the right solution, thanks for looking into this! Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Yours, Linus Walleij
Juerg Haefliger <juerg.haefliger@canonical.com> writes: > On Wed, 13 Sep 2023 11:58:07 +0300 > Kalle Valo <kvalo@kernel.org> wrote: > >> Juerg Haefliger <juerg.haefliger@canonical.com> writes: >> >> > Since commit 2d47c6956ab3 ("ubsan: Tighten UBSAN_BOUNDS on GCC"), >> > UBSAN_BOUNDS no longer pretends 1-element arrays are unbounded. Walking >> > 'element' and 'channel_list' will trigger warnings, so make them proper >> > flexible arrays. >> > >> > False positive warnings were: >> > >> > UBSAN: array-index-out-of-bounds in drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c:6984:20 >> > index 1 is out of range for type '__le32 [1]' >> > >> > UBSAN: array-index-out-of-bounds in drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c:1126:27 >> > index 1 is out of range for type '__le16 [1]' >> > >> > for these lines of code: >> > >> > 6884 ch.chspec = (u16)le32_to_cpu(list->element[i]); >> > >> > 1126 params_le->channel_list[i] = cpu_to_le16(chanspec); >> > >> > Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com> >> >> Should this be queued for v6.6? > > I would think so. It's a problem since 6.5. Which reminds me that I should > have added: > > Cc: stable@vger.kernel.org # 6.5+ I can add that during commit.
On 9/13/23 00:54, Juerg Haefliger wrote: > Since commit 2d47c6956ab3 ("ubsan: Tighten UBSAN_BOUNDS on GCC"), > UBSAN_BOUNDS no longer pretends 1-element arrays are unbounded. Walking > 'element' and 'channel_list' will trigger warnings, so make them proper > flexible arrays. > > False positive warnings were: > > UBSAN: array-index-out-of-bounds in drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c:6984:20 > index 1 is out of range for type '__le32 [1]' > > UBSAN: array-index-out-of-bounds in drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c:1126:27 > index 1 is out of range for type '__le16 [1]' > > for these lines of code: > > 6884 ch.chspec = (u16)le32_to_cpu(list->element[i]); > > 1126 params_le->channel_list[i] = cpu_to_le16(chanspec); > > Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com> > --- > .../wireless/broadcom/brcm80211/brcmfmac/fwil_types.h | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h > index bece26741d3a..ed723a5b5d54 100644 > --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h > +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h > @@ -442,7 +442,12 @@ struct brcmf_scan_params_v2_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_v2_le > + */ > + DECLARE_FLEX_ARRAY(__le16, channel_list); /* chanspecs */ > + }; > }; > > struct brcmf_scan_results { > @@ -702,7 +707,7 @@ struct brcmf_sta_info_le { > > struct brcmf_chanspec_list { > __le32 count; /* # of entries */ > - __le32 element[1]; /* variable length uint32 list */ > + DECLARE_FLEX_ARRAY(__le32, element); /* variable length uint32 list */ If no padding is needed, as in the other case, then DFA() is not necessary. Just remove the 1 from the array declaration: struct brcmf_chanspec_list { __le32 count; /* # of entries */ - __le32 element[1]; /* variable length uint32 list */ + __le32 element[]; /* variable length uint32 list */ }; -- Gustavo > }; > > /*
On Wed, 13 Sep 2023 10:02:12 -0600 "Gustavo A. R. Silva" <gustavo@embeddedor.com> wrote: > On 9/13/23 00:54, Juerg Haefliger wrote: > > Since commit 2d47c6956ab3 ("ubsan: Tighten UBSAN_BOUNDS on GCC"), > > UBSAN_BOUNDS no longer pretends 1-element arrays are unbounded. Walking > > 'element' and 'channel_list' will trigger warnings, so make them proper > > flexible arrays. > > > > False positive warnings were: > > > > UBSAN: array-index-out-of-bounds in drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c:6984:20 > > index 1 is out of range for type '__le32 [1]' > > > > UBSAN: array-index-out-of-bounds in drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c:1126:27 > > index 1 is out of range for type '__le16 [1]' > > > > for these lines of code: > > > > 6884 ch.chspec = (u16)le32_to_cpu(list->element[i]); > > > > 1126 params_le->channel_list[i] = cpu_to_le16(chanspec); > > > > Signed-off-by: Juerg Haefliger <juerg.haefliger@canonical.com> > > --- > > .../wireless/broadcom/brcm80211/brcmfmac/fwil_types.h | 9 +++++++-- > > 1 file changed, 7 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h > > index bece26741d3a..ed723a5b5d54 100644 > > --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h > > +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h > > @@ -442,7 +442,12 @@ struct brcmf_scan_params_v2_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_v2_le > > + */ > > + DECLARE_FLEX_ARRAY(__le16, channel_list); /* chanspecs */ > > + }; > > }; > > > > struct brcmf_scan_results { > > @@ -702,7 +707,7 @@ struct brcmf_sta_info_le { > > > > struct brcmf_chanspec_list { > > __le32 count; /* # of entries */ > > - __le32 element[1]; /* variable length uint32 list */ > > + DECLARE_FLEX_ARRAY(__le32, element); /* variable length uint32 list */ > > If no padding is needed, as in the other case, then DFA() is not necessary. > Just remove the 1 from the array declaration: > > struct brcmf_chanspec_list { > __le32 count; /* # of entries */ > - __le32 element[1]; /* variable length uint32 list */ > + __le32 element[]; /* variable length uint32 list */ > }; Ah, I wasn't sure if that is still acceptable. Will send a v2. ...Juerg > -- > Gustavo > > > }; > > > > /*
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h index bece26741d3a..ed723a5b5d54 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil_types.h @@ -442,7 +442,12 @@ struct brcmf_scan_params_v2_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_v2_le + */ + DECLARE_FLEX_ARRAY(__le16, channel_list); /* chanspecs */ + }; }; struct brcmf_scan_results { @@ -702,7 +707,7 @@ struct brcmf_sta_info_le { struct brcmf_chanspec_list { __le32 count; /* # of entries */ - __le32 element[1]; /* variable length uint32 list */ + DECLARE_FLEX_ARRAY(__le32, element); /* variable length uint32 list */ }; /*