Message ID | 20230106042844.give.885-kees@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp638223wrt; Thu, 5 Jan 2023 20:49:06 -0800 (PST) X-Google-Smtp-Source: AMrXdXt1PJliaVnILuWnAXCBgfge/DJyGRrxFzjKDhvSQrA2E/tjVJunT+EWA4NVFRHdYd9OGUIk X-Received: by 2002:a17:90b:3597:b0:219:b1f0:ddf0 with SMTP id mm23-20020a17090b359700b00219b1f0ddf0mr57890668pjb.36.1672980546307; Thu, 05 Jan 2023 20:49:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672980546; cv=none; d=google.com; s=arc-20160816; b=P0Wjt9rxmcKwC13IlaMRTg61Km0thXbRYLc6TvcC2F6sz60jT32AMArKjrKqzeqOYJ g9gS/udvQ/MfnaiwXy1hMfS6AuVt9lghtU3GqcDBy/kgqsPilf/kc43N9JcIQyRo3NQk xqsNQJ9H0DQID3K/OmWA2+HqVuIODk5sEbkNtsZHMdCa0xIHVMyEIkY+FV/3uyPh4Ndk SM+W3Pdxdx6w2yYwPP7ry9OScqEmbL79UYhLv7zl1ltuWyRyisENIrWMvt3KlBttzp59 2UUMFmXWrxlng/O9CwxVefAQcEdtEmNtkUwA8VVYLPaSqZo88yOn8mA078jCHAwDZtys UF5Q== 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=6MtouSE/c/6IpUkzqBwoQWV9c2KUTTgxJg5BS9SVs/s=; b=asRCHaseJML4fs8bpY6pt/kWcy7gfVyxCsIXUV1BqDPi++3oXPPunJiGn0Y2x2FLd0 VBqrAhyGk2/3mxGrGQe1idwQvTzsOeR8ZtKVpeTF4pMLc5ScJkD+3+WiVeYcoxyreC2I qFlT/N5LE+pbjWI5F8ryXRgvgph2Fwm4y9y5cwNfom+sdPfVDj5/lXc+TM4VUIirROy1 ABA8luGQWPJ9CPaHDLa65ORn0ULQocBtEFdEy1JTy2iqeHz1ATLWsFCuKgyvj2dHujIc MSrFS7t/GWvZiPI8YR21Jv3kkeRWlFciVigNFM8gHcD+GPHlf5ZeGaF5L5H9yJ6j8GGm behQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="l/Ap6Nw8"; 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=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e17-20020a656891000000b0049cd14d3a7esi322614pgt.75.2023.01.05.20.48.53; Thu, 05 Jan 2023 20:49:06 -0800 (PST) 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=@chromium.org header.s=google header.b="l/Ap6Nw8"; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231361AbjAFE2y (ORCPT <rfc822;tmhikaru@gmail.com> + 99 others); Thu, 5 Jan 2023 23:28:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230164AbjAFE2w (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 5 Jan 2023 23:28:52 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12BCB551C6 for <linux-kernel@vger.kernel.org>; Thu, 5 Jan 2023 20:28:51 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id ge16so397477pjb.5 for <linux-kernel@vger.kernel.org>; Thu, 05 Jan 2023 20:28:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=6MtouSE/c/6IpUkzqBwoQWV9c2KUTTgxJg5BS9SVs/s=; b=l/Ap6Nw8wI7NGfkXN/3WQkm0HipP4d8IpiwQ8tbFwy/1MyZlpCxJmVSTHr5Z7CrVyC 6Q84LVsMaaEY0zSlrdKyPYz1zxeU46YvTNbDmyUgyd2Ik8PVgJ63sq/6mBYkfr2vUtz6 HrDNREcM9613KaaDMFTY+467qiJC/fxw1Aego= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=6MtouSE/c/6IpUkzqBwoQWV9c2KUTTgxJg5BS9SVs/s=; b=ocXadK/9qjg6e4M938/14Ho0TcslR6VMkFVPaVIJpH4xjFMLgMsrL2jREMhx95lo8w 6lDFTVZV8tNHB3oUI1UQj5spPaCF8Q0g5yf7lhgm3daDXSF4cyQkLOqYU2ZIw/TMS1g+ YhjBPwQOValJUFUEvwx2BYTqas/q9OQeD6JdaaUVtsLjxZv3AqClr9TwkXDPEDS7BvUr SVQBQj+QPphTiQqOtAbDnAF1pqHAg4bb5VVa0Cekf8MkecqJRnZMoWmTisiLFu8nrqSK io8uyf0DEYaYgfowFD85Qz/5NaPbEm5LCbcnmAovEDBeffOmPHEkd4cVXj2HkClKlhyl 7vEg== X-Gm-Message-State: AFqh2koerxVj2xZCgJZPNT8NAvsD1kOzRUmoeyBmet9wxNMqSjr/TgV1 KDt6B5NvjOrXcC8TllJ3co0Q2Q== X-Received: by 2002:a17:902:b414:b0:186:748e:9383 with SMTP id x20-20020a170902b41400b00186748e9383mr50928233plr.46.1672979330555; Thu, 05 Jan 2023 20:28:50 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id n15-20020a170902d2cf00b00192902287d1sm18749402plc.288.2023.01.05.20.28.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 20:28:49 -0800 (PST) From: Kees Cook <keescook@chromium.org> To: "David S. Miller" <davem@davemloft.net> Cc: Kees Cook <keescook@chromium.org>, Jakub Kicinski <kuba@kernel.org>, Andrew Lunn <andrew@lunn.ch>, kernel test robot <lkp@intel.com>, Oleksij Rempel <linux@rempel-privat.de>, Sean Anderson <sean.anderson@seco.com>, Alexandru Tachici <alexandru.tachici@analog.com>, Amit Cohen <amcohen@nvidia.com>, "Gustavo A. R. Silva" <gustavoars@kernel.org>, Vincent Mailhol <mailhol.vincent@wanadoo.fr>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v3] ethtool: Replace 0-length array with flexible array Date: Thu, 5 Jan 2023 20:28:48 -0800 Message-Id: <20230106042844.give.885-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2121; h=from:subject:message-id; bh=DKp2Eu0HGyg7pTlg/vHwD58jjHq4zOalTg6VuLkK1Ds=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBjt6OAkODbjy1W2ZpLP5aLSnBaokwWRxffKKlCCKzH RHrHiN2JAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCY7ejgAAKCRCJcvTf3G3AJr/wEA CjCp54OIIN2hDjgjrgLc704V/PLrFQSVrJOFBtEnITgTrIx/F9Z4fveot6egvNwYQaeSRQOXiXX6Eb UJHDIwUEuJIn7uhw2o038rVPEF0VtiSchIEOKwyco97aqwmJcqIVlnPzMdUHv5Qptc7G1Pt62Vbmya LFmtlSv/xPCNCaTj+Pp+YTwcj+ijyHZ6Ei9tDce3t71RYp0GUeV/Fgq3FQ94iirCk3ikGqi9huXNti niTraWIXywXJfMr0a8KBOhHnbB48a2o7u1VXC1gE6pHKBqk2NbtyiBu4XgJmJXSckR18FXSNc0II+e xMaQxAghjlxv3DtSrN/H30pqrqAbo/TXEGfoar67rK252904iDkGtPns4MBiVplVIpvyuOKttjwvJN PYkE9pTq6jz/zMeD/LxRaTvwgs8CxGIeqeA3ooEmXkyxuKIncVG+SNk3tEOPoBLjbwx20ALn+n0yDf VfqQJV+nrVunJrFiMW483YCw5E4wgY4Ln3zQSqncqgiitjaP2Jbyn/ZXTvQBFjp85GyMsT/mchyoog 2VKLajUDA+rRpYMW/YYZ3GPlOdwNss3i/eSg1+moD3+9vJwU3KiSBgBADWyz1M/0SkKE3Ftfi9OyVd 8uToWUkUeBWWXgyQx7wNYzuvjahqktiYzj3dWDrljeDT4cZDFRtQdtYwZ1Iw== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham 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?1754220979245460804?= X-GMAIL-MSGID: =?utf-8?q?1754247249205667383?= |
Series |
[v3] ethtool: Replace 0-length array with flexible array
|
|
Commit Message
Kees Cook
Jan. 6, 2023, 4:28 a.m. UTC
Zero-length arrays are deprecated[1]. Replace struct ethtool_rxnfc's
"rule_locs" 0-length array with a flexible array. Detected with GCC 13,
using -fstrict-flex-arrays=3:
net/ethtool/common.c: In function 'ethtool_get_max_rxnfc_channel':
net/ethtool/common.c:558:55: warning: array subscript i is outside array bounds of '__u32[0]' {aka 'unsigned int[]'} [-Warray-bounds=]
558 | .fs.location = info->rule_locs[i],
| ~~~~~~~~~~~~~~~^~~
In file included from include/linux/ethtool.h:19,
from include/uapi/linux/ethtool_netlink.h:12,
from include/linux/ethtool_netlink.h:6,
from net/ethtool/common.c:3:
include/uapi/linux/ethtool.h:1186:41: note: while referencing
'rule_locs'
1186 | __u32 rule_locs[0];
| ^~~~~~~~~
[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: kernel test robot <lkp@intel.com>
Cc: Oleksij Rempel <linux@rempel-privat.de>
Cc: Sean Anderson <sean.anderson@seco.com>
Cc: Alexandru Tachici <alexandru.tachici@analog.com>
Cc: Amit Cohen <amcohen@nvidia.com>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Cc: netdev@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
v3: don't use helper (vincent)
v2: https://lore.kernel.org/lkml/20230105233420.gonna.036-kees@kernel.org
---
include/uapi/linux/ethtool.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Fri. 6 Jan 2023 at 13:28, Kees Cook <keescook@chromium.org> wrote: > Zero-length arrays are deprecated[1]. Replace struct ethtool_rxnfc's > "rule_locs" 0-length array with a flexible array. Detected with GCC 13, > using -fstrict-flex-arrays=3: > > net/ethtool/common.c: In function 'ethtool_get_max_rxnfc_channel': > net/ethtool/common.c:558:55: warning: array subscript i is outside array bounds of '__u32[0]' {aka 'unsigned int[]'} [-Warray-bounds=] > 558 | .fs.location = info->rule_locs[i], > | ~~~~~~~~~~~~~~~^~~ > In file included from include/linux/ethtool.h:19, > from include/uapi/linux/ethtool_netlink.h:12, > from include/linux/ethtool_netlink.h:6, > from net/ethtool/common.c:3: > include/uapi/linux/ethtool.h:1186:41: note: while referencing > 'rule_locs' > 1186 | __u32 rule_locs[0]; > | ^~~~~~~~~ > > [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays Side comment, this link does not mention the __DECLARE_FLEX_ARRAY(). It could be good to add a reference to the helper here. But of course, this is not a criticism of this patch. > Cc: "David S. Miller" <davem@davemloft.net> > Cc: Jakub Kicinski <kuba@kernel.org> > Cc: Andrew Lunn <andrew@lunn.ch> > Cc: kernel test robot <lkp@intel.com> > Cc: Oleksij Rempel <linux@rempel-privat.de> > Cc: Sean Anderson <sean.anderson@seco.com> > Cc: Alexandru Tachici <alexandru.tachici@analog.com> > Cc: Amit Cohen <amcohen@nvidia.com> > Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org> > Cc: Vincent Mailhol <mailhol.vincent@wanadoo.fr> > Cc: netdev@vger.kernel.org > Signed-off-by: Kees Cook <keescook@chromium.org> Reviewed-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr> > --- > v3: don't use helper (vincent) You may want to double check your other patches as well. At least this one is also using the helper when not needed: https://lore.kernel.org/netdev/20230105223642.never.980-kees@kernel.org/T/#u > v2: https://lore.kernel.org/lkml/20230105233420.gonna.036-kees@kernel.org > --- > include/uapi/linux/ethtool.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h > index 58e587ba0450..3135fa0ba9a4 100644 > --- a/include/uapi/linux/ethtool.h > +++ b/include/uapi/linux/ethtool.h > @@ -1183,7 +1183,7 @@ struct ethtool_rxnfc { > __u32 rule_cnt; > __u32 rss_context; > }; > - __u32 rule_locs[0]; > + __u32 rule_locs[]; > }; > > > -- > 2.34.1 >
On Fri. 6 Jan 2023 at 13:28, Kees Cook <keescook@chromium.org> wrote: > Zero-length arrays are deprecated[1]. Replace struct ethtool_rxnfc's > "rule_locs" 0-length array with a flexible array. Detected with GCC 13, > using -fstrict-flex-arrays=3: > > net/ethtool/common.c: In function 'ethtool_get_max_rxnfc_channel': > net/ethtool/common.c:558:55: warning: array subscript i is outside array bounds of '__u32[0]' {aka 'unsigned int[]'} [-Warray-bounds=] > 558 | .fs.location = info->rule_locs[i], > | ~~~~~~~~~~~~~~~^~~ > In file included from include/linux/ethtool.h:19, > from include/uapi/linux/ethtool_netlink.h:12, > from include/linux/ethtool_netlink.h:6, > from net/ethtool/common.c:3: > include/uapi/linux/ethtool.h:1186:41: note: while referencing > 'rule_locs' > 1186 | __u32 rule_locs[0]; > | ^~~~~~~~~ > > [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays > > Cc: "David S. Miller" <davem@davemloft.net> > Cc: Jakub Kicinski <kuba@kernel.org> > Cc: Andrew Lunn <andrew@lunn.ch> > Cc: kernel test robot <lkp@intel.com> > Cc: Oleksij Rempel <linux@rempel-privat.de> > Cc: Sean Anderson <sean.anderson@seco.com> > Cc: Alexandru Tachici <alexandru.tachici@analog.com> > Cc: Amit Cohen <amcohen@nvidia.com> > Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org> > Cc: Vincent Mailhol <mailhol.vincent@wanadoo.fr> > Cc: netdev@vger.kernel.org > Signed-off-by: Kees Cook <keescook@chromium.org> > --- > v3: don't use helper (vincent) v1: https://lore.kernel.org/all/20230105214126.never.757-kees@kernel.org ^^^^^ > v2: https://lore.kernel.org/lkml/20230105233420.gonna.036-kees@kernel.org ^^^^^ v3: https://lore.kernel.org/netdev/20230106042844.give.885-kees@kernel.org ^^^^ Seriously... :) > v2: https://lore.kernel.org/lkml/20230105233420.gonna.036-kees@kernel.org > --- > include/uapi/linux/ethtool.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h > index 58e587ba0450..3135fa0ba9a4 100644 > --- a/include/uapi/linux/ethtool.h > +++ b/include/uapi/linux/ethtool.h > @@ -1183,7 +1183,7 @@ struct ethtool_rxnfc { > __u32 rule_cnt; > __u32 rss_context; > }; > - __u32 rule_locs[0]; > + __u32 rule_locs[]; > };
On Fri, Jan 06, 2023 at 02:47:35PM +0900, Vincent MAILHOL wrote: > On Fri. 6 Jan 2023 at 13:28, Kees Cook <keescook@chromium.org> wrote: > > Zero-length arrays are deprecated[1]. Replace struct ethtool_rxnfc's > > "rule_locs" 0-length array with a flexible array. Detected with GCC 13, > > using -fstrict-flex-arrays=3: > > > > net/ethtool/common.c: In function 'ethtool_get_max_rxnfc_channel': > > net/ethtool/common.c:558:55: warning: array subscript i is outside array bounds of '__u32[0]' {aka 'unsigned int[]'} [-Warray-bounds=] > > 558 | .fs.location = info->rule_locs[i], > > | ~~~~~~~~~~~~~~~^~~ > > In file included from include/linux/ethtool.h:19, > > from include/uapi/linux/ethtool_netlink.h:12, > > from include/linux/ethtool_netlink.h:6, > > from net/ethtool/common.c:3: > > include/uapi/linux/ethtool.h:1186:41: note: while referencing > > 'rule_locs' > > 1186 | __u32 rule_locs[0]; > > | ^~~~~~~~~ > > > > [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays > > > > Cc: "David S. Miller" <davem@davemloft.net> > > Cc: Jakub Kicinski <kuba@kernel.org> > > Cc: Andrew Lunn <andrew@lunn.ch> > > Cc: kernel test robot <lkp@intel.com> > > Cc: Oleksij Rempel <linux@rempel-privat.de> > > Cc: Sean Anderson <sean.anderson@seco.com> > > Cc: Alexandru Tachici <alexandru.tachici@analog.com> > > Cc: Amit Cohen <amcohen@nvidia.com> > > Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org> > > Cc: Vincent Mailhol <mailhol.vincent@wanadoo.fr> > > Cc: netdev@vger.kernel.org > > Signed-off-by: Kees Cook <keescook@chromium.org> > > --- > > v3: don't use helper (vincent) > > v1: https://lore.kernel.org/all/20230105214126.never.757-kees@kernel.org > ^^^^^ > > v2: https://lore.kernel.org/lkml/20230105233420.gonna.036-kees@kernel.org > ^^^^^ > v3: https://lore.kernel.org/netdev/20230106042844.give.885-kees@kernel.org > ^^^^ > > Seriously... :) Hurray! Someone noticed and it's not even April yet. :) *celebrate* -Kees
On Fri, Jan 6, 2023 at 5:28 AM Kees Cook <keescook@chromium.org> wrote: > Zero-length arrays are deprecated[1]. Replace struct ethtool_rxnfc's > "rule_locs" 0-length array with a flexible array. Detected with GCC 13, > using -fstrict-flex-arrays=3: > > net/ethtool/common.c: In function 'ethtool_get_max_rxnfc_channel': > net/ethtool/common.c:558:55: warning: array subscript i is outside array bounds of '__u32[0]' {aka 'unsigned int[]'} [-Warray-bounds=] > 558 | .fs.location = info->rule_locs[i], > | ~~~~~~~~~~~~~~~^~~ > In file included from include/linux/ethtool.h:19, > from include/uapi/linux/ethtool_netlink.h:12, > from include/linux/ethtool_netlink.h:6, > from net/ethtool/common.c:3: > include/uapi/linux/ethtool.h:1186:41: note: while referencing > 'rule_locs' > 1186 | __u32 rule_locs[0]; > | ^~~~~~~~~ > > [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays > > Cc: "David S. Miller" <davem@davemloft.net> > Cc: Jakub Kicinski <kuba@kernel.org> > Cc: Andrew Lunn <andrew@lunn.ch> > Cc: kernel test robot <lkp@intel.com> > Cc: Oleksij Rempel <linux@rempel-privat.de> > Cc: Sean Anderson <sean.anderson@seco.com> > Cc: Alexandru Tachici <alexandru.tachici@analog.com> > Cc: Amit Cohen <amcohen@nvidia.com> > Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org> > Cc: Vincent Mailhol <mailhol.vincent@wanadoo.fr> > Cc: netdev@vger.kernel.org > Signed-off-by: Kees Cook <keescook@chromium.org> > --- > v3: don't use helper (vincent) > v2: https://lore.kernel.org/lkml/20230105233420.gonna.036-kees@kernel.org > --- > include/uapi/linux/ethtool.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h > index 58e587ba0450..3135fa0ba9a4 100644 > --- a/include/uapi/linux/ethtool.h > +++ b/include/uapi/linux/ethtool.h > @@ -1183,7 +1183,7 @@ struct ethtool_rxnfc { > __u32 rule_cnt; > __u32 rss_context; > }; > - __u32 rule_locs[0]; > + __u32 rule_locs[]; Stupid question: Is this syntax allowed in UAPI headers despite not being part of standard C90 or C++? Are we relying on all C/C++ compilers for pre-C99 having gcc/clang extensions?
On Fri. 6 Jan 2023 at 22:19, Jann Horn <jannh@google.com> wrote: > On Fri, Jan 6, 2023 at 5:28 AM Kees Cook <keescook@chromium.org> wrote: > > Zero-length arrays are deprecated[1]. Replace struct ethtool_rxnfc's > > "rule_locs" 0-length array with a flexible array. Detected with GCC 13, > > using -fstrict-flex-arrays=3: > > > > net/ethtool/common.c: In function 'ethtool_get_max_rxnfc_channel': > > net/ethtool/common.c:558:55: warning: array subscript i is outside array bounds of '__u32[0]' {aka 'unsigned int[]'} [-Warray-bounds=] > > 558 | .fs.location = info->rule_locs[i], > > | ~~~~~~~~~~~~~~~^~~ > > In file included from include/linux/ethtool.h:19, > > from include/uapi/linux/ethtool_netlink.h:12, > > from include/linux/ethtool_netlink.h:6, > > from net/ethtool/common.c:3: > > include/uapi/linux/ethtool.h:1186:41: note: while referencing > > 'rule_locs' > > 1186 | __u32 rule_locs[0]; > > | ^~~~~~~~~ > > > > [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays > > > > Cc: "David S. Miller" <davem@davemloft.net> > > Cc: Jakub Kicinski <kuba@kernel.org> > > Cc: Andrew Lunn <andrew@lunn.ch> > > Cc: kernel test robot <lkp@intel.com> > > Cc: Oleksij Rempel <linux@rempel-privat.de> > > Cc: Sean Anderson <sean.anderson@seco.com> > > Cc: Alexandru Tachici <alexandru.tachici@analog.com> > > Cc: Amit Cohen <amcohen@nvidia.com> > > Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org> > > Cc: Vincent Mailhol <mailhol.vincent@wanadoo.fr> > > Cc: netdev@vger.kernel.org > > Signed-off-by: Kees Cook <keescook@chromium.org> > > --- > > v3: don't use helper (vincent) > > v2: https://lore.kernel.org/lkml/20230105233420.gonna.036-kees@kernel.org > > --- > > include/uapi/linux/ethtool.h | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h > > index 58e587ba0450..3135fa0ba9a4 100644 > > --- a/include/uapi/linux/ethtool.h > > +++ b/include/uapi/linux/ethtool.h > > @@ -1183,7 +1183,7 @@ struct ethtool_rxnfc { > > __u32 rule_cnt; > > __u32 rss_context; > > }; > > - __u32 rule_locs[0]; > > + __u32 rule_locs[]; > > Stupid question: Is this syntax allowed in UAPI headers despite not > being part of standard C90 or C++? Are we relying on all C/C++ > compilers for pre-C99 having gcc/clang extensions? The [0] isn't part of the C90 standard either. So having to choose between [0] and [], the latter is the most portable nowadays. If I do a bit of speleology, I can see that C99 flexible array members were used as early as v2.6.19 (released in November 2006): https://elixir.bootlin.com/linux/v2.6.19/source/include/linux/usb/audio.h#L36 This is prior to the include/linux and include/uapi/linux split, but believe me, this usb/audio.h file is indeed part of the uapi. So, yes, using C99 flexible array members in the UAPI is de facto allowed because it was used for the last 16 years. An interesting sub question would be: What are the minimum compiler requirements to build a program using the Linux UAPI? And, after research, I could not find the answer. The requirements to build the kernel are well documented: https://docs.kernel.org/process/changes.html#changes But no clue for the uapi. I guess that at one point in 2006, people decided that it was time to set the minimum requirement to C99. Maybe this matches the end of life of the latest pre-C99 GCC version? The detailed answer must be hidden somewhere on lkml. Yours sincerely, Vincent Mailhol
On Thu, Jan 05, 2023 at 08:28:48PM -0800, Kees Cook wrote: > Zero-length arrays are deprecated[1]. Replace struct ethtool_rxnfc's > "rule_locs" 0-length array with a flexible array. Detected with GCC 13, > using -fstrict-flex-arrays=3: > > net/ethtool/common.c: In function 'ethtool_get_max_rxnfc_channel': > net/ethtool/common.c:558:55: warning: array subscript i is outside array bounds of '__u32[0]' {aka 'unsigned int[]'} [-Warray-bounds=] > 558 | .fs.location = info->rule_locs[i], > | ~~~~~~~~~~~~~~~^~~ > In file included from include/linux/ethtool.h:19, > from include/uapi/linux/ethtool_netlink.h:12, > from include/linux/ethtool_netlink.h:6, > from net/ethtool/common.c:3: > include/uapi/linux/ethtool.h:1186:41: note: while referencing > 'rule_locs' > 1186 | __u32 rule_locs[0]; > | ^~~~~~~~~ > > [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays > > Cc: "David S. Miller" <davem@davemloft.net> > Cc: Jakub Kicinski <kuba@kernel.org> > Cc: Andrew Lunn <andrew@lunn.ch> > Cc: kernel test robot <lkp@intel.com> > Cc: Oleksij Rempel <linux@rempel-privat.de> > Cc: Sean Anderson <sean.anderson@seco.com> > Cc: Alexandru Tachici <alexandru.tachici@analog.com> > Cc: Amit Cohen <amcohen@nvidia.com> > Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org> > Cc: Vincent Mailhol <mailhol.vincent@wanadoo.fr> > Cc: netdev@vger.kernel.org > Signed-off-by: Kees Cook <keescook@chromium.org> Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org> Thanks! -- Gustavo > --- > v3: don't use helper (vincent) > v2: https://lore.kernel.org/lkml/20230105233420.gonna.036-kees@kernel.org > --- > include/uapi/linux/ethtool.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h > index 58e587ba0450..3135fa0ba9a4 100644 > --- a/include/uapi/linux/ethtool.h > +++ b/include/uapi/linux/ethtool.h > @@ -1183,7 +1183,7 @@ struct ethtool_rxnfc { > __u32 rule_cnt; > __u32 rss_context; > }; > - __u32 rule_locs[0]; > + __u32 rule_locs[]; > }; > > > -- > 2.34.1 >
On Fri, Jan 06, 2023 at 02:38:18PM +0900, Vincent MAILHOL wrote: > On Fri. 6 Jan 2023 at 13:28, Kees Cook <keescook@chromium.org> wrote: > > [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays > > Side comment, this link does not mention the __DECLARE_FLEX_ARRAY(). > It could be good to add a reference to the helper here. But of course, > this is not a criticism of this patch. Good point! I've sent a patch for this now. > You may want to double check your other patches as well. At least this > one is also using the helper when not needed: > > https://lore.kernel.org/netdev/20230105223642.never.980-kees@kernel.org/T/#u That one does, actually, need it since otherwise the flex array would be "alone in a struct" which is the other case that C99 irrationally disallows. -Kees
On Fri, Jan 06, 2023 at 11:25:14PM +0900, Vincent MAILHOL wrote: > On Fri. 6 Jan 2023 at 22:19, Jann Horn <jannh@google.com> wrote: > > On Fri, Jan 6, 2023 at 5:28 AM Kees Cook <keescook@chromium.org> wrote: > > > Zero-length arrays are deprecated[1]. Replace struct ethtool_rxnfc's > > > "rule_locs" 0-length array with a flexible array. Detected with GCC 13, > > > using -fstrict-flex-arrays=3: > [...] > > > diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h > > > index 58e587ba0450..3135fa0ba9a4 100644 > > > --- a/include/uapi/linux/ethtool.h > > > +++ b/include/uapi/linux/ethtool.h > > > @@ -1183,7 +1183,7 @@ struct ethtool_rxnfc { > > > __u32 rule_cnt; > > > __u32 rss_context; > > > }; > > > - __u32 rule_locs[0]; > > > + __u32 rule_locs[]; > > > > Stupid question: Is this syntax allowed in UAPI headers despite not > > being part of standard C90 or C++? Are we relying on all C/C++ > > compilers for pre-C99 having gcc/clang extensions? > > The [0] isn't part of the C90 standard either. So having to choose > between [0] and [], the latter is the most portable nowadays. > > If I do a bit of speleology, I can see that C99 flexible array members > were used as early as v2.6.19 (released in November 2006): > > https://elixir.bootlin.com/linux/v2.6.19/source/include/linux/usb/audio.h#L36 > > This is prior to the include/linux and include/uapi/linux split, but > believe me, this usb/audio.h file is indeed part of the uapi. > So, yes, using C99 flexible array members in the UAPI is de facto > allowed because it was used for the last 16 years. > > An interesting sub question would be: > > What are the minimum compiler requirements to build a program using > the Linux UAPI? You're right -- we haven't explicitly documented this. C99 seems like the defacto minimum, though. > And, after research, I could not find the answer. The requirements to > build the kernel are well documented: > > https://docs.kernel.org/process/changes.html#changes > > But no clue for the uapi. I guess that at one point in 2006, people > decided that it was time to set the minimum requirement to C99. Maybe > this matches the end of life of the latest pre-C99 GCC version? The > detailed answer must be hidden somewhere on lkml. I would make the argument that the requirements for building Linux UAPI should match that of building the kernel...
On Fri, Jan 6, 2023, at 21:13, Kees Cook wrote: > On Fri, Jan 06, 2023 at 11:25:14PM +0900, Vincent MAILHOL wrote: >> On Fri. 6 Jan 2023 at 22:19, Jann Horn <jannh@google.com> wrote: >> >> What are the minimum compiler requirements to build a program using >> the Linux UAPI? > > You're right -- we haven't explicitly documented this. C99 seems like > the defacto minimum, though. > >> And, after research, I could not find the answer. The requirements to >> build the kernel are well documented: >> >> https://docs.kernel.org/process/changes.html#changes >> >> But no clue for the uapi. I guess that at one point in 2006, people >> decided that it was time to set the minimum requirement to C99. Maybe >> this matches the end of life of the latest pre-C99 GCC version? The >> detailed answer must be hidden somewhere on lkml. > > I would make the argument that the requirements for building Linux UAPI > should match that of building the kernel... I think it's a bit more nuanced than that: glibc does not require C99 but does include some kernel headers from generic library headers, so I would not make the assumption that it's always safe to use C99 features. On the other hand, Linux specific device drivers whose header is only really used from one application are free to make assumptions about the toolchain. Arnd
Hello: This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <kuba@kernel.org>: On Thu, 5 Jan 2023 20:28:48 -0800 you wrote: > Zero-length arrays are deprecated[1]. Replace struct ethtool_rxnfc's > "rule_locs" 0-length array with a flexible array. Detected with GCC 13, > using -fstrict-flex-arrays=3: > > net/ethtool/common.c: In function 'ethtool_get_max_rxnfc_channel': > net/ethtool/common.c:558:55: warning: array subscript i is outside array bounds of '__u32[0]' {aka 'unsigned int[]'} [-Warray-bounds=] > 558 | .fs.location = info->rule_locs[i], > | ~~~~~~~~~~~~~~~^~~ > In file included from include/linux/ethtool.h:19, > from include/uapi/linux/ethtool_netlink.h:12, > from include/linux/ethtool_netlink.h:6, > from net/ethtool/common.c:3: > include/uapi/linux/ethtool.h:1186:41: note: while referencing > 'rule_locs' > 1186 | __u32 rule_locs[0]; > | ^~~~~~~~~ > > [...] Here is the summary with links: - [v3] ethtool: Replace 0-length array with flexible array https://git.kernel.org/netdev/net-next/c/b466a25c930f You are awesome, thank you!
diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h index 58e587ba0450..3135fa0ba9a4 100644 --- a/include/uapi/linux/ethtool.h +++ b/include/uapi/linux/ethtool.h @@ -1183,7 +1183,7 @@ struct ethtool_rxnfc { __u32 rule_cnt; __u32 rss_context; }; - __u32 rule_locs[0]; + __u32 rule_locs[]; };