Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp2464796rwl; Fri, 6 Jan 2023 06:51:17 -0800 (PST) X-Google-Smtp-Source: AMrXdXtTC9Ts6duxMrwc3/xWfA6+8GOgZbIrzrjXjPgx6wo4DtY7jIn3sVh2epgt97W2HS58NJe7 X-Received: by 2002:a17:902:8647:b0:193:10b9:8fc8 with SMTP id y7-20020a170902864700b0019310b98fc8mr1512036plt.47.1673016677252; Fri, 06 Jan 2023 06:51:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673016677; cv=none; d=google.com; s=arc-20160816; b=f7XfNtGA2ibrrII9qq7RkYVQVykSKeMK4P8hqh8nglX8l2D9e7e6IGZdWvier9kJwp bVdyUDsynEMsk1b1hfYUcx8MhNj3YYcj193IfN6O4lqENzw0epRRMxkGFZStbcMM0bMP OvRaxBFrz+u4TFzGYvb96qbBecHAqFtBPX4101ZpBfPCyRDYv06Q0KtfaBR+HC/SiSu4 SXFv7GMoKd6yQUQJXm6NSnxT++l5jOzUutNzcpFOtkv42l7OAI10yh6kyAJe29hVABfe 4hy2qA0lCyXYXnznHa9Xso+sCYh+PLKgVtkfZdHKhMfR8smez2YHsILODQYEwYpkiYgQ qZvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=ZnhpvIy2ZsoQIvjxqkh6LV97wMF7pwAzJclzOI/EkUA=; b=RyjbIOMjQSlo+jJR3guq/jFlapyMB+1cMxbeuK5TjhWE8DWnj6r4EBgwHYldHlOO2n i6BLWwWXdZfyl9rnQh2EbXtn9gPWGQLKHPvjZ0X+DOpgDEM1QS0SdtNkpgF1aFloBtjk bvr62bdiQQtMg8nYp/cPq2Or3v45yy5IkLOCs835TFyF+nOJNAmyT2u+HLEL/vzNX9H9 jNyQwODwd2y36Rc6SYUUNiRj6Vif/HPrKg7L6GnvsWeAeH5zwEwvQj7zsRVU4xRkKRqg 74tiIkxtrkoGC+byQTiEC4CJLc0a1Hc2y2iMUPuAT6elJpOQpt3Ij8jpOUfuuN4oIEoi IcMA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x12-20020a1709027c0c00b0018666611f85si1088351pll.508.2023.01.06.06.51.09; Fri, 06 Jan 2023 06:51:17 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229601AbjAFOZe (ORCPT + 54 others); Fri, 6 Jan 2023 09:25:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234693AbjAFOZ2 (ORCPT ); Fri, 6 Jan 2023 09:25:28 -0500 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36C857BDCA; Fri, 6 Jan 2023 06:25:27 -0800 (PST) Received: by mail-pf1-f181.google.com with SMTP id z7so1131153pfq.13; Fri, 06 Jan 2023 06:25:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ZnhpvIy2ZsoQIvjxqkh6LV97wMF7pwAzJclzOI/EkUA=; b=gJpZEqK8J9iUXg6/NaMcM7g+hrm6Idxwqlmg2b1oNBbzs6/lK/Loxi/Aw5Qxq0QDSL Wzp5ZdvcMC4ujm8MnXlIKhlnF8ZUjqHI9TH5AiZQCCNsNoap4tu6GunKKk2qjR9HqW4u J8ghWWq4JwmMmYkbOBsS0ok57pIMsqzoE1eL+gu9TQ/GvYMfgTCZ3WS8K0VTnen/BsOz IOFqTOn25Q3HJoK9P6IJtl2knqLE86CIWndu/O6NDO83G/uhQPltF5L8o531fSzkeM2g 9oT9VV09XCANxxPLCJrBuhnGbPQxclXN1S079dOK5hzQ5PI8+k39fAOhRvDnuH1PoWTf dWsw== X-Gm-Message-State: AFqh2koRrzxuFn0EPfhR9C0HyGBKOJMf9T2VMmVWRQZn8W0lbSysSCzL x34QhEVBo7gsiSewxncoEuIKxMqnO4m9/mggJlY= X-Received: by 2002:a63:2106:0:b0:483:f80c:cdf3 with SMTP id h6-20020a632106000000b00483f80ccdf3mr2608100pgh.70.1673015126142; Fri, 06 Jan 2023 06:25:26 -0800 (PST) MIME-Version: 1.0 References: <20230106042844.give.885-kees@kernel.org> In-Reply-To: From: Vincent MAILHOL Date: Fri, 6 Jan 2023 23:25:14 +0900 Message-ID: Subject: Re: [PATCH v3] ethtool: Replace 0-length array with flexible array To: Jann Horn Cc: Kees Cook , "David S. Miller" , Jakub Kicinski , Andrew Lunn , kernel test robot , Oleksij Rempel , Sean Anderson , Alexandru Tachici , Amit Cohen , "Gustavo A. R. Silva" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Linux API Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no 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: X-Mailing-List: linux-kernel@vger.kernel.org On Fri. 6 Jan 2023 at 22:19, Jann Horn wrote: > On Fri, Jan 6, 2023 at 5:28 AM 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" > > Cc: Jakub Kicinski > > Cc: Andrew Lunn > > Cc: kernel test robot > > Cc: Oleksij Rempel > > Cc: Sean Anderson > > Cc: Alexandru Tachici > > Cc: Amit Cohen > > Cc: "Gustavo A. R. Silva" > > Cc: Vincent Mailhol > > Cc: netdev@vger.kernel.org > > Signed-off-by: Kees Cook > > --- > > 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