Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5941042ybv; Tue, 18 Feb 2020 06:53:48 -0800 (PST) X-Google-Smtp-Source: APXvYqxNK9AN0lpgAofGC9SPgaEVNRlwMC+eQMHHJhDjMEBMi9Oi6CcVLoXmjDt3gRW0nMvYmU+2 X-Received: by 2002:a9d:4e93:: with SMTP id v19mr14019183otk.200.1582037628108; Tue, 18 Feb 2020 06:53:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582037628; cv=none; d=google.com; s=arc-20160816; b=lN5crY6knn9i0LGus1pzuhY7lztYROCpc0vHZaQNJeRy3m27DoklCGiguUddUe01Us 9T6Sy/1hKUDWOZsDdj/ciejNeXmbVOes5zm//dkVH6RdxYqQiU99LhCGEklxU11zbYdJ f3rzp8RqDzNfeTTCYgLWlQ3O8VmAYFelX90E8hVgaNWwBE9t1LtalGtLVkGw2m/FPS/f z8oZHuGzF8q3zTpQBnxKVh1XdSvfMioSzrNUsMxGvngqeKCyL2v82pA3HSRk+BhYGFyC GlK7AdKmk8L234Ivg+sc8hIexKHIE3fNAeHp2KO/vGsnfQEzD6YP4qU2aa7jAnGFK0E4 exMA== 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=Bhqm2wnMCm8LEeRaZjiLW6mgJM0uois/4lyyJ7246Mo=; b=DGxDXn/M4eVxRia0MsqYzqzGiE2cVu4hTb+ZFNXdyGR/XgEchQJ9FapPqIYV9cdELq 8pVRxy3qPBmkOeMRdWXOVa//H2n930Yn9Q8pu3VrZypQ4amSlBBX95ij3EdahkVZHN+D XoyMmS1vAvA7e+p8nRIMGudnAwVGG7REu6aw9P1rxtI+Vt/JK7z8QxRvdtaOc7+ECcX+ lAWulcAjA8N9xNJSGYIuMPoKj15mujsigN3hWZw4d/6azREVL3B5zEy/cjfwNscaKrE+ OBOQoOLXhDvpZItawkVEO0w1EM4s/4p8CzdxwJrFhLCkSx8bjcV/H9JcaKgsLhEXKr8K 4Q7Q== 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 p26si1805502oto.240.2020.02.18.06.53.34; Tue, 18 Feb 2020 06:53:48 -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 S1726723AbgBROx3 (ORCPT + 99 others); Tue, 18 Feb 2020 09:53:29 -0500 Received: from www62.your-server.de ([213.133.104.62]:50180 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726540AbgBROx2 (ORCPT ); Tue, 18 Feb 2020 09:53:28 -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 1j44FP-0002Mk-PX; Tue, 18 Feb 2020 15:53:15 +0100 Received: from [2001:1620:665:0:5795:5b0a:e5d5:5944] (helo=linux-3.fritz.box) by sslproxy03.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j44FP-0009S1-Dl; Tue, 18 Feb 2020 15:53:15 +0100 Subject: Re: [PATCH] bpf: queue_stack_maps: Replace zero-length array with flexible-array member To: Andrii Nakryiko , "Gustavo A. R. Silva" Cc: Alexei Starovoitov , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , Networking , bpf , open list References: <20200213152416.GA1873@embeddedor> From: Daniel Borkmann Message-ID: <8c212e06-dc1f-3a47-ba3e-8f408ba7a972@iogearbox.net> Date: Tue, 18 Feb 2020 15:53:14 +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: 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.1/25727/Tue Feb 18 15:05:00 2020) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/13/20 6:47 PM, Andrii Nakryiko wrote: > On Thu, Feb 13, 2020 at 7:22 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 > > Sure, why not, though I don't think that's the only one (e.g., > bpf_storage_buffer's data is zero-length as well). > > Acked-by: Andrii Nakryiko +1, Gustavo, there are several such instances in the whole BPF subsystem. Please combine them all into a single patch, including https://patchwork.ozlabs.org/patch/1239563/, and resubmit. Thanks, Daniel