Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp803620ybv; Thu, 13 Feb 2020 09:47:57 -0800 (PST) X-Google-Smtp-Source: APXvYqxTF5rQ590hynzdZdXD4cdFY/e/+FF2nd5WfvspF/8Ehv+mNof4mZyT3X22f/AjfK189WfD X-Received: by 2002:aca:5083:: with SMTP id e125mr876256oib.96.1581616077608; Thu, 13 Feb 2020 09:47:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581616077; cv=none; d=google.com; s=arc-20160816; b=V0hJ6Sj6HFKj9Wj4iGpCSQEpa04Q6dGDtV2SPupAU1TnOqgtn67pUcsyb+d7WZfmf4 22sQrZPRNdQZ+4/SqJsYVQrLBbQGqn5R0F7LwVbt5NFbftUOlE1S/Xy6odOSKkVeE6VD uuUB2GOoYeTZ15Lqvh5gDY1evu0gZCWsVE8CU5R5yGLRYMxgz0kJk4aPJStM5u7pkY8z tWYvJFsQgtVUcCjE1mX3f6r5l8qfdi3Iq7oSOo6AVf1CTujyWcVNoICSshFnB1YxPRhS PHx4tK4m075krXRZ6fI4AbzlY7EUtZRe2ETO8hzJiBop6HXC8SqSc+zpqcB8NgTM5fwI jTsQ== 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=QqYQBHl3dLMvD5Z6qSR6RJN0d5WnItMFfOyEDAwMXCo=; b=RxLOR2ukel6xVU8MffOdpqoHhzYLHUtMEVJKGDSwACu3c9YzcaqcLRgzs4ii4M0lgl WJobrdxJZ9Dei33X/LGPqI3iEIKyKfoSMMwVgcmlwI8LHks4dm8RTi8b6U5wx4PQDD91 Neydwbf7XUNvirsEDzdV8kEEIiMIxtrhXJz6eQN+cdAqPzcXkdVIXco7+yS4eZH/jtC3 6fFnnQZSYX2i1y/ENv/LdaA/1Kkmsk+ezOcSTiAMUIijDV89El8lFWhujT1fV5C61ABf SPOLzkJxFO2ig1fQWnL2TZusmHLtOQ/qLO8g41CJDH5TqULNYHv0s1KMYPVHbkPEPmlj Ct0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ki5E6dMo; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w77si1461297oif.216.2020.02.13.09.47.44; Thu, 13 Feb 2020 09:47:57 -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=@gmail.com header.s=20161025 header.b=Ki5E6dMo; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727926AbgBMRrk (ORCPT + 99 others); Thu, 13 Feb 2020 12:47:40 -0500 Received: from mail-qk1-f195.google.com ([209.85.222.195]:44361 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725781AbgBMRrj (ORCPT ); Thu, 13 Feb 2020 12:47:39 -0500 Received: by mail-qk1-f195.google.com with SMTP id v195so6470465qkb.11; Thu, 13 Feb 2020 09:47:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=QqYQBHl3dLMvD5Z6qSR6RJN0d5WnItMFfOyEDAwMXCo=; b=Ki5E6dMoRZTUfdResgbYtn48OiDJhJPt96efZpVZTxXU67/iLnRdLnKFw9WEU17QuL 9ioG/sMDQHwiaAceH9BlAVI9a9EOTUJGm08R9ZowZop97ko6cxgIURBG+An33EitrxTm cX3MJZ/GOoSXQCQJq+hi5x4r1J/xLale9rxUVyImfQLWEJ9yHSmoxqXZn4OPHS3THAVW eDG05oPrM5tcP08hokvE+qfGHn6Cm3TjOOvUsggVbOpQIJnITD1Z6d+IYstqNRQSmiPr N3e1lMd305ayw9ONHgRzU/7w0t3rUSD6VMbwIO22+UuNPaq5DYkb9RJhfZgac6gLkhXg kM/Q== 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=QqYQBHl3dLMvD5Z6qSR6RJN0d5WnItMFfOyEDAwMXCo=; b=uXFdQ9mCWNxXDR3kvDVc1KFl0tE9oQ4RCeBpgWsMAEaGRROGPFGxs7Cuxci7S5J80g 8Z1fi4Nljjm7ZIixUvRBhUTn7A3HaLKvZiD1bSQnG95yoGXDc+Jv1m3QEZSYmIVUhHKa rEl5U9+Xms75hd6Mt6wAcPD20L8wq/D7vutF8ZRUSbwCfbAe3lLEkunvDpx5Sv/D9Mse O2Glh67+EZEa7K5XLPoX/caYrUsFcEYIsS/eB4p3OSjv4kabnf8BrFNI6SmQn+/J/Fa+ BswSd+Tn3zNjQsODhkCg22s8FQ0Oi5vdEL15rEeuYzNSvfi4+yxp1GVMSNOwCcAlZnPI pZZQ== X-Gm-Message-State: APjAAAWOav5BP/FCr6lY5FCHh4At30jMOEwFF1Qi1J7aPtuCSYvMAgB8 UVRGbMI5J7L2pKys7gISBWZUHoGw0pSpt7X+wE0= X-Received: by 2002:a05:620a:14a2:: with SMTP id x2mr16976934qkj.36.1581616057237; Thu, 13 Feb 2020 09:47:37 -0800 (PST) MIME-Version: 1.0 References: <20200213152416.GA1873@embeddedor> In-Reply-To: <20200213152416.GA1873@embeddedor> From: Andrii Nakryiko Date: Thu, 13 Feb 2020 09:47:25 -0800 Message-ID: Subject: Re: [PATCH] bpf: queue_stack_maps: 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 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 > kernel/bpf/queue_stack_maps.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/bpf/queue_stack_maps.c b/kernel/bpf/queue_stack_maps.c > index f697647ceb54..30e1373fd437 100644 > --- a/kernel/bpf/queue_stack_maps.c > +++ b/kernel/bpf/queue_stack_maps.c > @@ -19,7 +19,7 @@ struct bpf_queue_stack { > u32 head, tail; > u32 size; /* max_entries + 1 */ > > - char elements[0] __aligned(8); > + char elements[] __aligned(8); > }; > > static struct bpf_queue_stack *bpf_queue_stack(struct bpf_map *map) > -- > 2.25.0 >