Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp78083ybf; Thu, 27 Feb 2020 16:26:25 -0800 (PST) X-Google-Smtp-Source: APXvYqz8VJxqAHKdZa83vfBXeFHWXTGVgoRGNQi+XGywAdzFc0Y7Nj1MusZqKPU0S/+zfrY/nfWM X-Received: by 2002:a05:6830:154c:: with SMTP id l12mr1205308otp.275.1582849585730; Thu, 27 Feb 2020 16:26:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582849585; cv=none; d=google.com; s=arc-20160816; b=gboG4d2nevQbXlP40XeiQ2LO770A6ceGfT0Df2guNn2U8LDHbkYAuV4C28xLrhDPBR vdQk0Q/kFZC9h2o9lYcAaKBxG0OAzGylzGJuVe3rimL1/OCOaOrF5flXua9n4Lh2j6I6 ixXRGBvs0h260F67fXWfhmE69Wun6F8bitzIldSidLWvlzVqaRpDnwubWk+pMl2LudPs 9GTcMk8obm7Eej0VgklQIZ4AaUJfSjfmETw/Hn28z8cx7N05QnIz9+XBXqvec5UN1Hk9 HE61oMOL34+EL6leJRIqyLtgOQsTxzQvTAAqecVCJjJxPh3hpYMaD/R5sND9cURYqD6I dr/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=jgc/qymmxEhWYoOcr4bEfVGdNzSv086/dLovMfgor7w=; b=W4IG4SJNOXWKG7QStXEcPKvgQw288HN8gW5qQi8eQnLaIxKFRJYkMyd7YO74cMaK69 GFthbITibWhGr2GwLylHD0IYmO/yOcaCmoYERNxIIo3Hw+z0PhsKzGFX9gzYCposN9Eq qurXNbphNhXfIrp1vI7QW8pk6mJ2nNyfceGRZWOjqkPbE6PZ5JbKPTGrrs4o544Q+4TD DAkspfL6mFI6KOkJD3aeW6fR/2C2JtukWm3HPrwSUoqYGq3/4uhJ6cJvdLNCjFgny1J4 rxow0dV3QUmTZIXTwRaBky2fKn0wijqxJCzTbOZFhvWxXbDTHoYNg6/qFQ7zZkjwsWgD 7VYw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m17si792623oie.187.2020.02.27.16.26.13; Thu, 27 Feb 2020 16:26:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730144AbgB1A0J (ORCPT + 99 others); Thu, 27 Feb 2020 19:26:09 -0500 Received: from www62.your-server.de ([213.133.104.62]:57252 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729984AbgB1A0J (ORCPT ); Thu, 27 Feb 2020 19:26:09 -0500 Received: from sslproxy03.your-server.de ([88.198.220.132]) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1j7TTW-0006JB-97; Fri, 28 Feb 2020 01:25:54 +0100 Received: from [85.7.42.192] (helo=pc-9.home) by sslproxy03.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j7TTV-0003Mj-UT; Fri, 28 Feb 2020 01:25:53 +0100 Subject: Re: [PATCH] bpf: Replace zero-length array with flexible-array member To: "Gustavo A. R. Silva" , Alexei Starovoitov , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org References: <20200227001744.GA3317@embeddedor> From: Daniel Borkmann Message-ID: <1c4b814a-0f7d-ae10-9bc0-086b2bd6dea0@iogearbox.net> Date: Fri, 28 Feb 2020 01:25:49 +0100 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: <20200227001744.GA3317@embeddedor> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.102.2/25735/Thu Feb 27 20:18:16 2020) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/27/20 1:17 AM, Gustavo A. R. Silva wrote: > The current codebase makes use of the zero-length array language > extension to the C90 standard, but the preferred mechanism to declare > variable-length types such as these ones is a flexible array member[1][2], > introduced in C99: > > struct foo { > int stuff; > struct boo array[]; > }; > > By making use of the mechanism above, we will get a compiler warning > in case the flexible array does not occur last in the structure, which > will help us prevent some kind of undefined behavior bugs from being > inadvertently introduced[3] to the codebase from now on. > > Also, notice that, dynamic memory allocations won't be affected by > this change: > > "Flexible array members have incomplete type, and so the sizeof operator > may not be applied. As a quirk of the original implementation of > zero-length arrays, sizeof evaluates to zero."[1] > > This issue was found with the help of Coccinelle. > > [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html > [2] https://github.com/KSPP/linux/issues/21 > [3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour") > > Signed-off-by: Gustavo A. R. Silva Applied, thanks!