From: Arnd Bergmann <arnd@arndb.de>
To: linux-kernel@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Hannes Frederic Sowa <hannes@stressinduktion.org>,
"David S. Miller" <davem@davemloft.net>
Cc: "Arnd Bergmann" <arnd@arndb.de>,
"Brad Spengler" <spender@grsecurity.net>,
"Daniel Borkmann" <dborkman@redhat.com>,
"Alexei Starovoitov" <ast@plumgrid.com>,
"Kees Cook" <keescook@chromium.org>,
"Martin KaFai Lau" <kafai@fb.com>,
"Song Liu" <songliubraving@fb.com>, "Yonghong Song" <yhs@fb.com>,
"Andrii Nakryiko" <andriin@fb.com>,
"John Fastabend" <john.fastabend@gmail.com>,
"KP Singh" <kpsingh@chromium.org>,
"Stanislav Fomichev" <sdf@google.com>,
"Ilya Leoshkevich" <iii@linux.ibm.com>,
"Toke Høiland-Jørgensen" <toke@redhat.com>,
"Björn Töpel" <bjorn.topel@intel.com>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Jiri Olsa" <jolsa@kernel.org>,
"Pankaj Bharadiya" <pankaj.laxminarayan.bharadiya@intel.com>,
netdev@vger.kernel.org, bpf@vger.kernel.org
Subject: [PATCH 05/15] bpf: avoid gcc-10 stringop-overflow warning
Date: Thu, 30 Apr 2020 23:30:47 +0200 [thread overview]
Message-ID: <20200430213101.135134-6-arnd@arndb.de> (raw)
In-Reply-To: <20200430213101.135134-1-arnd@arndb.de>
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 <arnd@arndb.de>
---
include/linux/filter.h | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/include/linux/filter.h b/include/linux/filter.h
index af37318bb1c5..73d06a39e2d6 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -545,10 +545,8 @@ struct bpf_prog {
unsigned int (*bpf_func)(const void *ctx,
const struct bpf_insn *insn);
/* Instructions for interpreter */
- union {
- struct sock_filter insns[0];
- struct bpf_insn insnsi[0];
- };
+ struct sock_filter insns[0];
+ struct bpf_insn insnsi[];
};
struct sk_filter {
--
2.26.0
next prev parent reply other threads:[~2020-04-30 21:32 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-30 21:30 [PATCH 00/15] gcc-10 warning fixes Arnd Bergmann
2020-04-30 21:30 ` [PATCH 02/15] iwlwifi: mvm: fix gcc-10 zero-length-bounds warning Arnd Bergmann
2020-06-10 12:18 ` Luciano Coelho
2020-04-30 21:30 ` [PATCH 03/15] mwifiex: avoid -Wstringop-overflow warning Arnd Bergmann
2020-05-06 8:43 ` Kalle Valo
2020-04-30 21:30 ` [PATCH 04/15] ath10k: fix gcc-10 zero-length-bounds warnings Arnd Bergmann
2020-04-30 21:45 ` Gustavo A. R. Silva
2020-04-30 21:44 ` Arnd Bergmann
2020-05-04 11:54 ` Kalle Valo
2020-05-04 16:09 ` Gustavo A. R. Silva
2020-05-05 4:56 ` Kalle Valo
2020-04-30 21:30 ` Arnd Bergmann [this message]
2020-05-04 21:06 ` [PATCH 05/15] bpf: avoid gcc-10 stringop-overflow warning Daniel Borkmann
2020-04-30 21:30 ` [PATCH 06/15] netfilter: conntrack: avoid gcc-10 zero-length-bounds warning Arnd Bergmann
2020-05-10 21:48 ` Pablo Neira Ayuso
2020-04-30 21:30 ` [PATCH 07/15] drop_monitor: work around gcc-10 stringop-overflow warning Arnd Bergmann
2020-05-01 11:28 ` Neil Horman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200430213101.135134-6-arnd@arndb.de \
--to=arnd@arndb.de \
--cc=andriin@fb.com \
--cc=ast@kernel.org \
--cc=ast@plumgrid.com \
--cc=bjorn.topel@intel.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dborkman@redhat.com \
--cc=hannes@stressinduktion.org \
--cc=iii@linux.ibm.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kafai@fb.com \
--cc=keescook@chromium.org \
--cc=kpsingh@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pankaj.laxminarayan.bharadiya@intel.com \
--cc=sdf@google.com \
--cc=songliubraving@fb.com \
--cc=spender@grsecurity.net \
--cc=tglx@linutronix.de \
--cc=toke@redhat.com \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).