Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4017242ybz; Mon, 4 May 2020 14:09:12 -0700 (PDT) X-Google-Smtp-Source: APiQypJzljvBJ3bFutwsfwmMPE73w/4cstzg+aok4iFPzFoUZfEqlWKuT+oY8eNCQmmzX8yUbd/8 X-Received: by 2002:aa7:d5d4:: with SMTP id d20mr16847033eds.369.1588626552606; Mon, 04 May 2020 14:09:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588626552; cv=none; d=google.com; s=arc-20160816; b=yKGU6CFa2dpvYZErkmaMqyYgnzbBMw8lyeFjGI8+laqE8K36+zRxEc/qEtzUiDn3Bo NTR9eVibtCTCvpMKw9Fta0Kit2aVJaJ8mspqRymxyeyLnqdPNeM/dCcgY2DoXQqJLdQO MKeQ58qoh0nGEex9yNvw/JYp04V/ZP1mu7USDkivHOsSWAywopPk2LK0wLxd/OU0nCqt i/yVQCdINU2oYvx/fLphcoF3qxKbPqXrptftZ6+T6iroBgQAu6YG8IPGbKFPugFJhhc6 nwmNBTqRnMn5kIyMmYXbrtEXtFsfIQKOQfjl+XcjQEtbl4X8Ir/fs+xAY07o96AtBXtZ ybwQ== 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=TTMjEGZ2GL2N64+dW0y1lOw1YfQ6TJjeRpCNnZxdL9s=; b=uZVCgNWILwhlxlHVvHEKi/d8+Hz6qUExMB47MqwrBW16v/Vp8W0BvJ18ioxmuXv0w+ M+5n00uEVa8X5g/5lNotUDROpGXFIdHqNyqcorvhr3quPB0CLa7auwNGFThhQtxLmTQA EaMtF+MUZul4JrBEXKRlEbKOvS53kLMav6ty9/xUn8O4dMIlJsVcPq7w0RHHUgkTY0SV ygWo0AQ0/IbLM4rxi9hrDC/QXA3wHcDqx8D1txWDf1Ovjx9bGQqYs2qLx9GRdJfTk63C 8YkiVlrj3zUis+n6NWae+PPvbHtIKvXwRzJvu9UBwTEY83b4aE9p2JmhRyH9bcsQ8o/v gghQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c22si98070edr.408.2020.05.04.14.08.49; Mon, 04 May 2020 14:09:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726950AbgEDVHP (ORCPT + 99 others); Mon, 4 May 2020 17:07:15 -0400 Received: from www62.your-server.de ([213.133.104.62]:32810 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726334AbgEDVHP (ORCPT ); Mon, 4 May 2020 17:07:15 -0400 Received: from sslproxy05.your-server.de ([78.46.172.2]) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1jViIn-0001Gq-FV; Mon, 04 May 2020 23:07:01 +0200 Received: from [178.195.186.98] (helo=pc-9.home) by sslproxy05.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jViIm-000G0e-PC; Mon, 04 May 2020 23:07:00 +0200 Subject: Re: [PATCH 05/15] bpf: avoid gcc-10 stringop-overflow warning To: Arnd Bergmann , linux-kernel@vger.kernel.org, Alexei Starovoitov , Hannes Frederic Sowa , "David S. Miller" Cc: Brad Spengler , Daniel Borkmann , Alexei Starovoitov , Kees Cook , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh , Stanislav Fomichev , Ilya Leoshkevich , =?UTF-8?Q?Toke_H=c3=b8iland-J=c3=b8rgensen?= , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Thomas Gleixner , Jiri Olsa , Pankaj Bharadiya , netdev@vger.kernel.org, bpf@vger.kernel.org References: <20200430213101.135134-1-arnd@arndb.de> <20200430213101.135134-6-arnd@arndb.de> From: Daniel Borkmann Message-ID: Date: Mon, 4 May 2020 23:06:59 +0200 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: <20200430213101.135134-6-arnd@arndb.de> 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/25802/Mon May 4 14:12:31 2020) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/30/20 11:30 PM, Arnd Bergmann wrote: > gcc-10 warns about accesses to zero-length arrays: > > kernel/bpf/core.c: In function 'bpf_patch_insn_single': > cc1: warning: writing 8 bytes into a region of size 0 [-Wstringop-overflow=] > In file included from kernel/bpf/core.c:21: > include/linux/filter.h:550:20: note: at offset 0 to object 'insnsi' with size 0 declared here > 550 | struct bpf_insn insnsi[0]; > | ^~~~~~ > > In this case, we really want to have two flexible-array members, > but that is not possible. Removing the union to make insnsi a > flexible-array member while leaving insns as a zero-length array > fixes the warning, as nothing writes to the other one in that way. > > This trick only works on linux-3.18 or higher, as older versions > had additional members in the union. > > Fixes: 60a3b2253c41 ("net: bpf: make eBPF interpreter images read-only") > Signed-off-by: Arnd Bergmann Not pretty but looks okay to me, both have the same offset afterwards in the pahole dump as well. struct bpf_prog { [...] unsigned int (*bpf_func)(const void *, const struct bpf_insn *); /* 48 8 */ struct sock_filter insns[0]; /* 56 0 */ struct bpf_insn insnsi[]; /* 56 0 */ /* size: 56, cachelines: 1, members: 21 */ /* sum members: 50, holes: 1, sum holes: 4 */ /* sum bitfield members: 10 bits, bit holes: 1, sum bit holes: 6 bits */ /* last cacheline: 56 bytes */ }; Applied to bpf-next, thanks!