Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3229806iog; Mon, 27 Jun 2022 11:57:09 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tmujq73F+RBlQnu+erLyXFUp9AmCqg6wjedw5aJa0N8b22HBoY3iS6jD6ZysCoM/nfpkf7 X-Received: by 2002:a17:907:2d9e:b0:726:a03a:16c4 with SMTP id gt30-20020a1709072d9e00b00726a03a16c4mr6657755ejc.742.1656356229283; Mon, 27 Jun 2022 11:57:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656356229; cv=none; d=google.com; s=arc-20160816; b=H9CfxXLiVt1kaQGpM5+W+FSRri40wvtf5+3oJ4R8eMC2bXVTXq9pcgZYCXmVZhBmID gPgauQ79wpDHZkcDteB3No0Zd2zGwqd3Orv5gTobz6h45rhk6FQTxNJVc8/d3stPnaDY i3Hni4m55JFSBkKVsgn5iX7nKnuXrI63hjAMdhmx6p9CVsn1cgSYJoMKq8fqsPFzVDib KJClNzmUha9owosJtjM3iqw/JSkyKYrM3gBVKuIsOdutbDp+1ObDAL5dMeHuZRlv7n7j XQ9NF3qo4J7/m2OXtDZMoJfxGs/vHBZ1jcrxFX5NdHTXlHiNbbhprx/1KnGOgnrRsRCx KNpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=AXbYc1DfxA1uzkELOZ3xvJsCsFp/8g/0yhmM1jF7ilY=; b=LDEoiMohQFUMuh4SR4qOj/SLIY0/CzmWfpAZnTZk1IGwxDXTU3EXQc6wfWlJAlgwDt Zla1fV1zOu/OZYh/w6Nt3tKUBwOhWSW2WJW/nqZJ+vXOK6cr6oyT4jSg4aGYIov0izBU 7rQopXK6dt8/uXhKDNX9YoRPc3ErXmEynHmEzUn0GScQ6MImP3oLTYxbgZ+2rGIeY7+t bD3cRhaPy4Ij3mOKSAuI4P3Fi1TBiptMl+rI0m9bYwOwW90ZwMrknp7pdn8x86u1Meqx 5vSSCM/GRD47aELfmyMX7DwrCvTp/DxDTQgR+0awNV/oe/U+yRT4WWZGZtn/Nn/JZpKr 0sOg== 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 l16-20020a056402255000b004358f57d80asi14876007edb.452.2022.06.27.11.56.44; Mon, 27 Jun 2022 11:57:09 -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; 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 S240295AbiF0Sbz (ORCPT + 99 others); Mon, 27 Jun 2022 14:31:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240226AbiF0Sbn (ORCPT ); Mon, 27 Jun 2022 14:31:43 -0400 Received: from www62.your-server.de (www62.your-server.de [213.133.104.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD7B91E3DF; Mon, 27 Jun 2022 11:27:42 -0700 (PDT) Received: from sslproxy03.your-server.de ([88.198.220.132]) by www62.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1o5tSV-000G0X-5e; Mon, 27 Jun 2022 20:27:39 +0200 Received: from [85.1.206.226] (helo=linux.home) by sslproxy03.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o5tSU-000TKD-AF; Mon, 27 Jun 2022 20:27:38 +0200 Subject: Re: [PATCH][next] treewide: uapi: Replace zero-length arrays with flexible-array members To: "Gustavo A. R. Silva" , Kees Cook , linux-kernel@vger.kernel.org Cc: x86@kernel.org, dm-devel@redhat.com, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-s390@vger.kernel.org, kvm@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-can@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux1394-devel@lists.sourceforge.net, io-uring@vger.kernel.org, lvs-devel@vger.kernel.org, linux-mtd@lists.infradead.org, kasan-dev@googlegroups.com, linux-mmc@vger.kernel.org, nvdimm@lists.linux.dev, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, linux-perf-users@vger.kernel.org, linux-raid@vger.kernel.org, linux-sctp@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-usb@vger.kernel.org, virtualization@lists.linux-foundation.org, v9fs-developer@lists.sourceforge.net, linux-rdma@vger.kernel.org, alsa-devel@alsa-project.org, linux-hardening@vger.kernel.org References: <20220627180432.GA136081@embeddedor> From: Daniel Borkmann Message-ID: <6bc1e94c-ce1d-a074-7d0c-8dbe6ce22637@iogearbox.net> Date: Mon, 27 Jun 2022 20:27:37 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20220627180432.GA136081@embeddedor> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.103.6/26586/Mon Jun 27 10:06:41 2022) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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: X-Mailing-List: linux-kernel@vger.kernel.org On 6/27/22 8:04 PM, Gustavo A. R. Silva wrote: > There is a regular need in the kernel to provide a way to declare > having a dynamically sized set of trailing elements in a structure. > Kernel code should always use “flexible array members”[1] for these > cases. The older style of one-element or zero-length arrays should > no longer be used[2]. > > This code was transformed with the help of Coccinelle: > (linux-5.19-rc2$ spatch --jobs $(getconf _NPROCESSORS_ONLN) --sp-file script.cocci --include-headers --dir . > output.patch) > > @@ > identifier S, member, array; > type T1, T2; > @@ > > struct S { > ... > T1 member; > T2 array[ > - 0 > ]; > }; > > -fstrict-flex-arrays=3 is coming and we need to land these changes > to prevent issues like these in the short future: > > ../fs/minix/dir.c:337:3: warning: 'strcpy' will always overflow; destination buffer has size 0, > but the source string has length 2 (including NUL byte) [-Wfortify-source] > strcpy(de3->name, "."); > ^ > > Since these are all [0] to [] changes, the risk to UAPI is nearly zero. If > this breaks anything, we can use a union with a new member name. > > [1] https://en.wikipedia.org/wiki/Flexible_array_member > [2] https://www.kernel.org/doc/html/v5.16/process/deprecated.html#zero-length-and-one-element-arrays > > Link: https://github.com/KSPP/linux/issues/78 > Build-tested-by: https://lore.kernel.org/lkml/62b675ec.wKX6AOZ6cbE71vtF%25lkp@intel.com/ > Signed-off-by: Gustavo A. R. Silva > --- > Hi all! > > JFYI: I'm adding this to my -next tree. :) Fyi, this breaks BPF CI: https://github.com/kernel-patches/bpf/runs/7078719372?check_suite_focus=true [...] progs/map_ptr_kern.c:314:26: error: field 'trie_key' with variable sized type 'struct bpf_lpm_trie_key' not at the end of a struct or class is a GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end] struct bpf_lpm_trie_key trie_key; ^ 1 error generated. make: *** [Makefile:519: /tmp/runner/work/bpf/bpf/tools/testing/selftests/bpf/map_ptr_kern.o] Error 1 make: *** Waiting for unfinished jobs.... Error: Process completed with exit code 2.