LVS
lvs-devel
Google
 
Web LinuxVirtualServer.org

Re: [PATCH][next] treewide: uapi: Replace zero-length arrays with flexib

To: Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>
Subject: Re: [PATCH][next] treewide: uapi: Replace zero-length arrays with flexible-array members
Cc: "Gustavo A. R. Silva" <gustavoars@xxxxxxxxxx>, Linux Kernel Mailing List <linux-kernel@xxxxxxxxxxxxxxx>, the arch/x86 maintainers <x86@xxxxxxxxxx>, dm-devel@xxxxxxxxxx, linux-m68k <linux-m68k@xxxxxxxxxxxxxxxxxxxx>, "open list:BROADCOM NVRAM DRIVER" <linux-mips@xxxxxxxxxxxxxxx>, linux-s390 <linux-s390@xxxxxxxxxxxxxxx>, KVM list <kvm@xxxxxxxxxxxxxxx>, Intel Graphics Development <intel-gfx@xxxxxxxxxxxxxxxxxxxxx>, DRI Development <dri-devel@xxxxxxxxxxxxxxxxxxxxx>, netdev <netdev@xxxxxxxxxxxxxxx>, bpf <bpf@xxxxxxxxxxxxxxx>, linux-btrfs <linux-btrfs@xxxxxxxxxxxxxxx>, linux-can@xxxxxxxxxxxxxxx, Linux FS Devel <linux-fsdevel@xxxxxxxxxxxxxxx>, linux1394-devel@xxxxxxxxxxxxxxxxxxxxx, io-uring@xxxxxxxxxxxxxxx, lvs-devel@xxxxxxxxxxxxxxx, MTD Maling List <linux-mtd@xxxxxxxxxxxxxxxxxxx>, kasan-dev <kasan-dev@xxxxxxxxxxxxxxxx>, Linux MMC List <linux-mmc@xxxxxxxxxxxxxxx>, nvdimm@xxxxxxxxxxxxxxx, NetFilter <netfilter-devel@xxxxxxxxxxxxxxx>, coreteam@xxxxxxxxxxxxx, linux-perf-users@xxxxxxxxxxxxxxx, linux-raid@xxxxxxxxxxxxxxx, linux-sctp@xxxxxxxxxxxxxxx, linux-stm32@xxxxxxxxxxxxxxxxxxxxxxxxxxxx, Linux ARM <linux-arm-kernel@xxxxxxxxxxxxxxxxxxx>, scsi <linux-scsi@xxxxxxxxxxxxxxx>, target-devel <target-devel@xxxxxxxxxxxxxxx>, USB list <linux-usb@xxxxxxxxxxxxxxx>, virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx, V9FS Developers <v9fs-developer@xxxxxxxxxxxxxxxxxxxxx>, linux-rdma <linux-rdma@xxxxxxxxxxxxxxx>, ALSA Development Mailing List <alsa-devel@xxxxxxxxxxxxxxxx>, linux-hardening@xxxxxxxxxxxxxxx
From: Kees Cook <keescook@xxxxxxxxxxxx>
Date: Tue, 28 Jun 2022 11:05:53 -0700
On Tue, Jun 28, 2022 at 09:27:21AM +0200, Geert Uytterhoeven wrote:
> Hi Gustavo,
> 
> Thanks for your patch!
> 
> On Mon, Jun 27, 2022 at 8:04 PM Gustavo A. R. Silva
> <gustavoars@xxxxxxxxxx> 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].
> 
> These rules apply to the kernel, but uapi is not considered part of the
> kernel, so different rules apply.  Uapi header files should work with
> whatever compiler that can be used for compiling userspace.

Right, userspace isn't bound by these rules, but the kernel ends up
consuming these structures, so we need to fix them. The [0] -> []
changes (when they are not erroneously being used within other
structures) is valid for all compilers. Flexible arrays are C99; it's
been 23 years. :)

But, yes, where we DO break stuff we need to workaround it, etc.

-- 
Kees Cook

<Prev in Thread] Current Thread [Next in Thread>