Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp428199ybv; Thu, 13 Feb 2020 03:12:27 -0800 (PST) X-Google-Smtp-Source: APXvYqzDH0vOeJGbU90O2TQL8+kPoYCAjy4o9jYmwFE0c6HzAa4xtUNdNgO4ppTNAOTgoz8az9WW X-Received: by 2002:a9d:7ad9:: with SMTP id m25mr12343267otn.13.1581592347706; Thu, 13 Feb 2020 03:12:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581592347; cv=none; d=google.com; s=arc-20160816; b=tPqwnOcBuER56y9adr86U9DptqC5NaWCrZLSixhQ84lO5fPTV+xyUmqmNf2mTGDPxk UeMOdyNwjwpwuuETzGYowvwgllKvMIKzSfEx8bPuvacHeMkeMDIICE7GHLMNv7nWg59e yTAu7yIre7UcEgNLhhQrjNj8VhHxpSYb8TsMtKF5zz3WNpV6vzKfGHr1bsdz86Yn3Ukr a0IX39GpgyjFa3YUSVCqX7NHqXXTdbYzE0jzUoOQYLlVvDEsNc0KOcmEW+wb6NJA02Bk YyyF9EDmTQiBQV1SHqmAFB4N/kL8s6VJt27pTaWBRO1aSuqe2/HUCguFStjZbFKTcBFk +Zdw== 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=HjbPZrEbtFmqBlxSEQ8uJW/5jdaC0VtLl/huovljPNk=; b=z63pfaJPxYZzzjxWll9fv3vsfQfOA5uGclYq8/s5jttKnuVJmEUxRfAST/wSStzkpC rhgBuU5K6O78prUP9M/gJzeTS8eaawHiEyEW3wNj3WhPNvNe+KYtNtZ4OaXGDgj65bB4 PrkxZrXXA9sTqJVYMC1sbxPu4dhtWYDpHw0fRlNvbChH0O5MipZicNCHSON05b4gCoeQ KOCzsEMqvTyWvJIOB272ryEwwXtaDePV5uleleU5Q9kOhiQVDiIwpBu0TZMO+9oJOIpt wWLAcnvk7VStQNAFf5VsOJh5uHGpuS2KRLW2S57LXf6ONngywvzlRa+GUTH/dWElWIKB 9IGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XvOWm20J; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u21si922342otq.137.2020.02.13.03.12.16; Thu, 13 Feb 2020 03:12:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-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=@linaro.org header.s=google header.b=XvOWm20J; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729674AbgBMLMO (ORCPT + 99 others); Thu, 13 Feb 2020 06:12:14 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:36226 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726232AbgBMLMO (ORCPT ); Thu, 13 Feb 2020 06:12:14 -0500 Received: by mail-wm1-f66.google.com with SMTP id p17so6196393wma.1 for ; Thu, 13 Feb 2020 03:12:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=HjbPZrEbtFmqBlxSEQ8uJW/5jdaC0VtLl/huovljPNk=; b=XvOWm20J8V2hJtzrfZP9BsSVOpuodtNgDW83ikwOXQBl1TJEaHj94NjxXPbANZznnn OGeoiFim/TK2WS9FCW6wBzogEtRGt/GftYzZYxRSO2j/4Z8PlHtExSFMfKeNvzb68q4s VHUvSQnHlzcXp9lIlZR0ciHcdLkOKKAb3r95vbLVJPBEKQdKAXNswuQ5kQ3eEYINkKYN RdA+VK/zmq0+7J2Gjh88EuIZhmEuQYsplNQEeumrTzXXenYqvwuSSYCHNM+6nTw9mAv6 SIk8xIsuQtJMYYEPDWMZR7Cz4nLV0JJVzvcaRxen8iRwyIMMpITMHTk/EPimIERJXwGL RC2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=HjbPZrEbtFmqBlxSEQ8uJW/5jdaC0VtLl/huovljPNk=; b=i1XYks201RHmgNWL4hTK+HKHcVJpKKVnNQo8Y2yARmU+adOnEU5rynVtweR8DDE0sb NFI/7XafRfWsCBhFMcJqO7E8TRmeTPbTyuPJJ4AN3ambPFcoUX1DTRqXhsNmnvs37ZT7 dnQPF/tpNScF1syRLjboO/1IxNpUKHSySzDlpHzAiwdUwvJ00o6OOrKHcagkvz1hEuBo n3HMEwV3p9K9YUiBTndvfusHU2udYCWFfKSvxsytaJeEiIRxB8lfgDk3a9CKwwQqAl7c yBki0rl7VeRS5R5WsxGgCW9xQKDN0T7/n0ILCy+vUZ5TDqQCvd0bttI1aftiQiuCoCSN DQbA== X-Gm-Message-State: APjAAAXXxXHN5C9UhgCIzj7+sCQAycKQM1cOoaDBohgQHq2v8eO+83Zs gpZdn5ddlNKuWYjHYMs5ljo1xgIcp0DFiHd1mMSXjw== X-Received: by 2002:a7b:cc81:: with SMTP id p1mr5174972wma.62.1581592332274; Thu, 13 Feb 2020 03:12:12 -0800 (PST) MIME-Version: 1.0 References: <20200211174126.GA29960@embeddedor> In-Reply-To: From: Ard Biesheuvel Date: Thu, 13 Feb 2020 11:11:59 +0000 Message-ID: Subject: Re: [PATCH] treewide: Replace zero-length arrays with flexible-array member To: Geert Uytterhoeven Cc: "Gustavo A. R. Silva" , Linux Kernel Mailing List , Kees Cook , "David S. Miller" , Greg KH , Linux Crypto Mailing List , netdev , USB list Content-Type: text/plain; charset="UTF-8" Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Thu, 13 Feb 2020 at 12:09, Geert Uytterhoeven wrote: > > Hi Gustavo, > > On Tue, Feb 11, 2020 at 10:49 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 > > unadvertenly introduced[3] to the codebase from now on. > > > > All these instances of code were found with the help of the following > > Coccinelle script: > > > > @@ > > identifier S, member, array; > > type T1, T2; > > @@ > > > > struct S { > > ... > > T1 member; > > T2 array[ > > - 0 > > ]; > > }; > > I've stumbled across one more in include/uapi/linux/usb/ch9.h: > > struct usb_key_descriptor { > __u8 bLength; > __u8 bDescriptorType; > > __u8 tTKID[3]; > __u8 bReserved; > __u8 bKeyData[0]; > } __attribute__((packed)); > > And it seems people are (ab)using one-sized arrays for flexible arrays, too: > > struct usb_string_descriptor { > __u8 bLength; > __u8 bDescriptorType; > > __le16 wData[1]; /* UTF-16LE encoded */ > } __attribute__ ((packed)); > > As this is UAPI, we have to be careful for regressions, though. > These were probably taken straight from the specification. The [1] trick is used a lot in the UEFI specification as well, for instance.