Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp720542ybf; Wed, 26 Feb 2020 21:56:50 -0800 (PST) X-Google-Smtp-Source: APXvYqzIvKJ+x9QGEk+KzHr4H4ZOsuEuivJ+FeYcJnmoKE3yrm5UrXuicIlavVJ3NLjgDZ43teb2 X-Received: by 2002:aca:ac10:: with SMTP id v16mr1960362oie.123.1582783010468; Wed, 26 Feb 2020 21:56:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582783010; cv=none; d=google.com; s=arc-20160816; b=AiOEjUgrE/SLYDP92wqIMHAaghgTj/0X5Fz/9HmE2TFdVYH7/H+vclvWHqtesiW0zP +PS0Y/bx1plR7MS5SC0ZCPsU37iUOOeG5ucrE0jDA7WTi2Byeq/X7EQ//zEbaimBMDgz P7dwa2l4ucBBL+3B9vVqMoFru21CJJ5iAOd+0B+RT2f2MvXIjv8l9UGiH/NHr9DDeuwR Yii+V5iXum3cwuwJXrOUFe8HTQlrTx541UOjZ7yWoOjSs53F0zG8sjoT0CoICLOtqNEz CtJeTJfCGTs261yqA+/t5+u7cu1nxr9e3/7GOlcbsV6jcK5E/WnONr60daRaVtR8k8qA dpiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=P6aHPbAF9StUXLthROKGx6IfSp0KfuH6bpOcTrHBCB8=; b=nQBVn+IkrnQ4/0nPJZENJ1dqgCLvD0gT9YBehA7/DvPpC0yM8FNo/vIMlTC7WfNue8 nPu502lJh40DdN2r7xP/wSIrTLo7ObWbXDqsCZyct/rYBfjaekX9XY4T35VJACOEHdYM F1hy7B1fDqUrD5GKsU7auKDRwSYJ1p60S5reuPKcvp1p4NF7SCgGHlUDZSHbaDqBVAE0 1ZHFo8KnmTToB4tZZKsX0/KkAgppwv0CjGKYQZ01ZvsZQ/K9H5GZhWyAr0NcPTOdB0Hj KfwErnY1fu7Au/LxT7Cao9EUJkpwLHpl4JH3RiWSR90uPxwOgO20LSb03v0UEIPlecUh /tEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=O0AdVHRQ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s8si808591oic.7.2020.02.26.21.56.39; Wed, 26 Feb 2020 21:56:50 -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; dkim=pass header.i=@kernel.org header.s=default header.b=O0AdVHRQ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728402AbgB0F42 (ORCPT + 99 others); Thu, 27 Feb 2020 00:56:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:55024 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725805AbgB0F41 (ORCPT ); Thu, 27 Feb 2020 00:56:27 -0500 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2612B24672; Thu, 27 Feb 2020 05:56:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582782987; bh=R9VEd0NDGHG23l9/8f5bs/P9pgnOwscgs82TKBNxFEs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=O0AdVHRQx3VDctsBvC4N0ZihEthjvsr47cIp4X2kbDDo0TpIBiIJYkWRRyTETJfm4 WBnTiFWPOEu7ubiL5KG7koSy3y1RoaqAcmRXw/1c7Ww7wJeHptWKYWJxQt10pargoD w5Sr27uxuvChFnoxAAAnC/XoMCPptP/Cd4rnMq4o= Received: by mail-lf1-f52.google.com with SMTP id c23so1119976lfi.7; Wed, 26 Feb 2020 21:56:27 -0800 (PST) X-Gm-Message-State: ANhLgQ3hGWWRy1Rn6jZMmpyWGwLOQeQYXJK06gofew1DP6d1MSGQpQVq 1ru7R1sS3HIMqDA8fPTAq34jVxrn2URFg2A6lL0= X-Received: by 2002:a19:4a0f:: with SMTP id x15mr1096322lfa.172.1582782985300; Wed, 26 Feb 2020 21:56:25 -0800 (PST) MIME-Version: 1.0 References: <20200227001744.GA3317@embeddedor> In-Reply-To: <20200227001744.GA3317@embeddedor> From: Song Liu Date: Wed, 26 Feb 2020 21:56:13 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] bpf: Replace zero-length array with flexible-array member To: "Gustavo A. R. Silva" Cc: Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , Networking , bpf , open list Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 26, 2020 at 4:16 PM 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 Acked-by: Song Liu