Message ID | ZC7X7KCb+JEkPe5D@work |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1079859vqo; Thu, 6 Apr 2023 07:44:07 -0700 (PDT) X-Google-Smtp-Source: AKy350bF5dNFDd8QIwkL2SOQlZJDeUC+AXGKcMoV32Ow16IF3p3g2A+MX8W1ECE7/B00NjoNfO1b X-Received: by 2002:aa7:d59a:0:b0:504:7171:4545 with SMTP id r26-20020aa7d59a000000b0050471714545mr657839edq.9.1680792247043; Thu, 06 Apr 2023 07:44:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680792247; cv=none; d=google.com; s=arc-20160816; b=sGeuwIpQby6vmLQQrmwF7dZY/BatMhsICLFA6IkKyH4tkYD3RIeOLk3cGs2tCwcufG 8ntILQdUSZ/ZW9CccRlVsZw52QkS2aYKg2VZ0rFLMwJPWNJVNh0d+OyuTiaXjBVntbhL A5Ppaxk66NR6S0AKyza7YzfZo1qEC3M7aZByV7FqfWKq1Rbuv0VvKE4UxsvA3FB0yqMr OGiWmqfXkeINdSpubaSv8yaQ2osDKGxRFAXhauyAgbHZNfzjrgG21VTqwpxNuiZAiUfy hZTcMyxfqcBMUUo1jTH2Ds35BfrgCqW2wkdSDBKzCgNqm98elE8n+JHgbakew7mL/jFg MOFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=83DCRrtSJq8aIhSri57P8Nkhk9kMsmJ33d/Kt/QPqOM=; b=c8a8aJljkLWu5+UlKYFVXv413773JNmAlfnpNEr/Rc2oF0+XNPzP/1GH1wYKM+/wJ4 5WsF80Q6b6wRKALVHchaAx7zDcuSuos7wdUWxIWs6tCrMy5GKvXpQzzVLMIqMXpapyIn r1PUZOR/V2nDCPbj9ho/M3V2IGzqf+SwtshxA+9e9z00E4iDgYaZiH69aFqrRRMz29FU 9UR1HO3jUVfW3p7z/3iCwOd7+q+/zU52Re3GlF1ZMo6EJf4B/2edi4Ska98qnjOvXncP VcYXaOMYvcApo01xijV9h9RA5yPTF8KZxo/yWChiMd6LwRZphLmdotHdhMMpJxcZEm6D 62WQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SjiLsj18; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y21-20020a50e615000000b00504564d26d4si923681edm.556.2023.04.06.07.43.43; Thu, 06 Apr 2023 07:44:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SjiLsj18; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238814AbjDFOiz (ORCPT <rfc822;lkml4gm@gmail.com> + 99 others); Thu, 6 Apr 2023 10:38:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238352AbjDFOid (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 6 Apr 2023 10:38:33 -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 87284CC10; Thu, 6 Apr 2023 07:36:36 -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 CCCE06478C; Thu, 6 Apr 2023 14:31:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48A63C4339C; Thu, 6 Apr 2023 14:31:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680791494; bh=fS1epBKc6/LIuAlKccrK1+yZRgDIBGUB741ssPvpdOQ=; h=Date:From:To:Cc:Subject:From; b=SjiLsj18bWuofLs6hhWeLC/lLw/a3iNtZ9wlEueFZEmCpkNlYBNfrW2g/JfGJHGTi vet9hVGN3GV90yUx+3gAa/XNftBN0j39XOMRCSz2X9AIryTOjRKZkau8WazkdAVbKe 7jo/OiVuhS8JxGUofx57NN8frKBM2tj4fn33MN5OokPIYjhPFpYfjxIVlje0uFnNYq o+keawWHSe/sdTrcyzxIyVKkwcke3vee+fUSrJSER8RnbtzoGn6X9DOk/pfIaR/jlM ZoF5CIu1w4YilJ9YwXKoTj0fnpznmfu4LCYmI1CVH3mBWnGcBheecAhLYWYKRmVcUM 1CooyEc8vqBvg== Date: Thu, 6 Apr 2023 08:32:12 -0600 From: "Gustavo A. R. Silva" <gustavoars@kernel.org> To: Felix Fietkau <nbd@nbd.name>, Lorenzo Bianconi <lorenzo@kernel.org>, Ryder Lee <ryder.lee@mediatek.com>, Shayne Chen <shayne.chen@mediatek.com>, Sean Wang <sean.wang@mediatek.com>, Kalle Valo <kvalo@kernel.org>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Matthias Brugger <matthias.bgg@gmail.com>, AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, "Gustavo A. R. Silva" <gustavoars@kernel.org>, linux-hardening@vger.kernel.org Subject: [PATCH][next] wifi: mt76: Replace zero-length array with flexible-array member Message-ID: <ZC7X7KCb+JEkPe5D@work> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762438411223194321?= X-GMAIL-MSGID: =?utf-8?q?1762438411223194321?= |
Series |
[next] wifi: mt76: Replace zero-length array with flexible-array member
|
|
Commit Message
Gustavo A. R. Silva
April 6, 2023, 2:32 p.m. UTC
Zero-length arrays are deprecated [1] and have to be replaced by C99
flexible-array members.
This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines
on memcpy() and help to make progress towards globally enabling
-fstrict-flex-arrays=3 [2]
Link: https://github.com/KSPP/linux/issues/78 [1]
Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [2]
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Thu, Apr 06, 2023 at 08:32:12AM -0600, Gustavo A. R. Silva wrote: > Zero-length arrays are deprecated [1] and have to be replaced by C99 > flexible-array members. > > This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines > on memcpy() and help to make progress towards globally enabling > -fstrict-flex-arrays=3 [2] > > Link: https://github.com/KSPP/linux/issues/78 [1] > Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [2] > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Reviewed-by: Simon Horman <simon.horman@corigine.com> > --- > drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h > index a5e6ee4daf92..9bf4b4199ee3 100644 > --- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h > +++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h > @@ -127,7 +127,7 @@ struct mt76_connac2_mcu_rxd { > u8 rsv1[2]; > u8 s2d_index; > > - u8 tlv[0]; > + u8 tlv[]; > }; > > struct mt76_connac2_patch_hdr { Curiously -fstrict-flex-arrays=3 didn't flag this one in my environment, Ubuntu Lunar. gcc-13 --version gcc-13 (Ubuntu 13-20230320-1ubuntu1) 13.0.1 20230320 (experimental) [master r13-6759-g5194ad1958c] Copyright (C) 2023 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. I did, however, notice some other problems reported by gcc-13 with -fstrict-flex-arrays=3 in drivers/net/wireless/mediatek/mt76 when run against net-next wireless. I've listed them in diff format below. Are these on your radar too? diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.h b/drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.h index 35268b0890ad..d09bb4eed1ec 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.h +++ b/drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.h @@ -24,7 +24,7 @@ struct mt7921_asar_dyn { u8 names[4]; u8 enable; u8 nr_tbl; - struct mt7921_asar_dyn_limit tbl[0]; + struct mt7921_asar_dyn_limit tbl[]; } __packed; struct mt7921_asar_dyn_limit_v2 { @@ -37,7 +37,7 @@ struct mt7921_asar_dyn_v2 { u8 enable; u8 rsvd; u8 nr_tbl; - struct mt7921_asar_dyn_limit_v2 tbl[0]; + struct mt7921_asar_dyn_limit_v2 tbl[]; } __packed; struct mt7921_asar_geo_band { @@ -55,7 +55,7 @@ struct mt7921_asar_geo { u8 names[4]; u8 version; u8 nr_tbl; - struct mt7921_asar_geo_limit tbl[0]; + struct mt7921_asar_geo_limit tbl[]; } __packed; struct mt7921_asar_geo_limit_v2 { @@ -69,7 +69,7 @@ struct mt7921_asar_geo_v2 { u8 version; u8 rsvd; u8 nr_tbl; - struct mt7921_asar_geo_limit_v2 tbl[0]; + struct mt7921_asar_geo_limit_v2 tbl[]; } __packed; struct mt7921_asar_cl { @@ -85,7 +85,7 @@ struct mt7921_asar_fg { u8 rsvd; u8 nr_flag; u8 rsvd1; - u8 flag[0]; + u8 flag[]; } __packed; struct mt7921_acpi_sar {
On 4/7/23 01:23, Simon Horman wrote: > On Thu, Apr 06, 2023 at 08:32:12AM -0600, Gustavo A. R. Silva wrote: >> Zero-length arrays are deprecated [1] and have to be replaced by C99 >> flexible-array members. >> >> This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines >> on memcpy() and help to make progress towards globally enabling >> -fstrict-flex-arrays=3 [2] >> >> Link: https://github.com/KSPP/linux/issues/78 [1] >> Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [2] >> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> > > Reviewed-by: Simon Horman <simon.horman@corigine.com> Thanks :) > >> --- >> drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h >> index a5e6ee4daf92..9bf4b4199ee3 100644 >> --- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h >> +++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h >> @@ -127,7 +127,7 @@ struct mt76_connac2_mcu_rxd { >> u8 rsv1[2]; >> u8 s2d_index; >> >> - u8 tlv[0]; >> + u8 tlv[]; >> }; >> >> struct mt76_connac2_patch_hdr { > > Curiously -fstrict-flex-arrays=3 didn't flag this one in my environment, > Ubuntu Lunar. Yep; that's why I didn't include any warning message in the changelog text this time. And the reason for that is that tlv is not being indexed anywhere in the code. However, it's being used in the pointer arithmetic operation below: drivers/net/wireless/mediatek/mt76/mt7921/mcu.c: 164 rxd = (struct mt76_connac2_mcu_rxd *)skb->data; 165 grant = (struct mt7921_roc_grant_tlv *)(rxd->tlv + 4); which means that it can be considered as an array of size greater than zero at some point. Hence, it should be transformed into a C99 flexible array. > > gcc-13 --version > gcc-13 (Ubuntu 13-20230320-1ubuntu1) 13.0.1 20230320 (experimental) [master r13-6759-g5194ad1958c] > Copyright (C) 2023 Free Software Foundation, Inc. > This is free software; see the source for copying conditions. There is NO > warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. > > I did, however, notice some other problems reported by gcc-13 with > -fstrict-flex-arrays=3 in drivers/net/wireless/mediatek/mt76 > when run against net-next wireless. I've listed them in diff format below. > > Are these on your radar too? Yep; those are being addressed here: https://lore.kernel.org/linux-hardening/ZBTUB%2FkJYQxq%2F6Cj@work/ -- Gustavo > > diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.h b/drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.h > index 35268b0890ad..d09bb4eed1ec 100644 > --- a/drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.h > +++ b/drivers/net/wireless/mediatek/mt76/mt7921/acpi_sar.h > @@ -24,7 +24,7 @@ struct mt7921_asar_dyn { > u8 names[4]; > u8 enable; > u8 nr_tbl; > - struct mt7921_asar_dyn_limit tbl[0]; > + struct mt7921_asar_dyn_limit tbl[]; > } __packed; > > struct mt7921_asar_dyn_limit_v2 { > @@ -37,7 +37,7 @@ struct mt7921_asar_dyn_v2 { > u8 enable; > u8 rsvd; > u8 nr_tbl; > - struct mt7921_asar_dyn_limit_v2 tbl[0]; > + struct mt7921_asar_dyn_limit_v2 tbl[]; > } __packed; > > struct mt7921_asar_geo_band { > @@ -55,7 +55,7 @@ struct mt7921_asar_geo { > u8 names[4]; > u8 version; > u8 nr_tbl; > - struct mt7921_asar_geo_limit tbl[0]; > + struct mt7921_asar_geo_limit tbl[]; > } __packed; > > struct mt7921_asar_geo_limit_v2 { > @@ -69,7 +69,7 @@ struct mt7921_asar_geo_v2 { > u8 version; > u8 rsvd; > u8 nr_tbl; > - struct mt7921_asar_geo_limit_v2 tbl[0]; > + struct mt7921_asar_geo_limit_v2 tbl[]; > } __packed; > > struct mt7921_asar_cl { > @@ -85,7 +85,7 @@ struct mt7921_asar_fg { > u8 rsvd; > u8 nr_flag; > u8 rsvd1; > - u8 flag[0]; > + u8 flag[]; > } __packed; > > struct mt7921_acpi_sar {
On Tue, Apr 11, 2023 at 12:39:06PM -0600, Gustavo A. R. Silva wrote: > [You don't often get email from gustavo@embeddedor.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ] > > On 4/7/23 01:23, Simon Horman wrote: > > On Thu, Apr 06, 2023 at 08:32:12AM -0600, Gustavo A. R. Silva wrote: > > > Zero-length arrays are deprecated [1] and have to be replaced by C99 > > > flexible-array members. > > > > > > This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines > > > on memcpy() and help to make progress towards globally enabling > > > -fstrict-flex-arrays=3 [2] > > > > > > Link: https://github.com/KSPP/linux/issues/78 [1] > > > Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [2] > > > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> > > > > Reviewed-by: Simon Horman <simon.horman@corigine.com> > > Thanks :) > > > > > > --- > > > drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h > > > index a5e6ee4daf92..9bf4b4199ee3 100644 > > > --- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h > > > +++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h > > > @@ -127,7 +127,7 @@ struct mt76_connac2_mcu_rxd { > > > u8 rsv1[2]; > > > u8 s2d_index; > > > > > > - u8 tlv[0]; > > > + u8 tlv[]; > > > }; > > > > > > struct mt76_connac2_patch_hdr { > > > > Curiously -fstrict-flex-arrays=3 didn't flag this one in my environment, > > Ubuntu Lunar. > > Yep; that's why I didn't include any warning message in the changelog text > this time. > > And the reason for that is that tlv is not being indexed anywhere in the > code. However, it's being used in the pointer arithmetic operation below: > > drivers/net/wireless/mediatek/mt76/mt7921/mcu.c: > 164 rxd = (struct mt76_connac2_mcu_rxd *)skb->data; > 165 grant = (struct mt7921_roc_grant_tlv *)(rxd->tlv + 4); > > > which means that it can be considered as an array of size greater than zero > at some point. Hence, it should be transformed into a C99 flexible array. Understood, thanks for the explanation. > > gcc-13 --version > > gcc-13 (Ubuntu 13-20230320-1ubuntu1) 13.0.1 20230320 (experimental) [master r13-6759-g5194ad1958c] > > Copyright (C) 2023 Free Software Foundation, Inc. > > This is free software; see the source for copying conditions. There is NO > > warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. > > > > I did, however, notice some other problems reported by gcc-13 with > > -fstrict-flex-arrays=3 in drivers/net/wireless/mediatek/mt76 > > when run against net-next wireless. I've listed them in diff format below. > > > > Are these on your radar too? > > Yep; those are being addressed here: > > https://lore.kernel.org/linux-hardening/ZBTUB%2FkJYQxq%2F6Cj@work/ Thanks, I had forgotten about that.
diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h index a5e6ee4daf92..9bf4b4199ee3 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h +++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.h @@ -127,7 +127,7 @@ struct mt76_connac2_mcu_rxd { u8 rsv1[2]; u8 s2d_index; - u8 tlv[0]; + u8 tlv[]; }; struct mt76_connac2_patch_hdr {