linux-xiaomi-chiron/kernel/bpf
Gustavo A. R. Silva 385bbf7b11 bpf, libbpf: Replace zero-length array with flexible-array
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]

sizeof(flexible-array-member) triggers a warning because flexible array
members have incomplete type[1]. There are some instances of code in
which the sizeof operator is being incorrectly/erroneously applied to
zero-length arrays and the result is zero. Such instances may be hiding
some bugs. So, this work (flexible-array member conversions) will also
help to get completely rid of those sorts of issues.

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 7649773293 ("cxgb3/l2t: Fix undefined behaviour")

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20200507185057.GA13981@embeddedor
2020-05-11 16:56:47 +02:00
..
arraymap.c
bpf_iter.c bpf: Implement common macros/helpers for target iterators 2020-05-09 17:05:26 -07:00
bpf_lru_list.c
bpf_lru_list.h
bpf_lsm.c
bpf_struct_ops.c
bpf_struct_ops_types.h
btf.c bpf: Support variable length array in tracing programs 2020-05-09 17:05:27 -07:00
cgroup.c
core.c
cpumap.c
devmap.c
disasm.c
disasm.h
dispatcher.c
hashtab.c
helpers.c
inode.c bpf: Create file bpf iterator 2020-05-09 17:05:26 -07:00
local_storage.c
lpm_trie.c
Makefile bpf: Add task and task/file iterator targets 2020-05-09 17:05:26 -07:00
map_in_map.c
map_in_map.h
map_iter.c bpf: Add bpf_map iterator 2020-05-09 17:05:26 -07:00
offload.c
percpu_freelist.c
percpu_freelist.h
queue_stack_maps.c bpf, libbpf: Replace zero-length array with flexible-array 2020-05-11 16:56:47 +02:00
reuseport_array.c
stackmap.c
syscall.c bpf: Add bpf_map iterator 2020-05-09 17:05:26 -07:00
sysfs_btf.c
task_iter.c bpf: Add task and task/file iterator targets 2020-05-09 17:05:26 -07:00
tnum.c
trampoline.c
verifier.c bpf: Handle spilled PTR_TO_BTF_ID properly when checking stack_boundary 2020-05-09 17:05:27 -07:00
xskmap.c