[LTP] [PATCH] syscalls/bpf: zero-initialize bpf_attr including padding bits

Cyril Hrubis chrubis@suse.cz
Thu Feb 6 16:04:29 CET 2025


Hi!
> > I had a closer look here, the map_attr is an union with anonymous
> > structures and I suppose that the problem here is that the padding after
> > the union is no longer cleared and that there have been some new fields
> > added, at least compared to the lapi fallback structures we have and we
> > possibly pass random mess in flags.
> 
> It's not just padding, some fields (from other structs) are also not
> initialized:
> 
> void bpf_map_array_get(const int map_fd,
>                        const uint32_t *const array_indx,
>                        uint64_t *const array_val)
> {
>         union bpf_attr elem_attr = {
>                 .map_fd = map_fd,
>                 .key = ptr_to_u64(array_indx),
>                 .value = ptr_to_u64(array_val),
>                 .flags = 0
>         };
> 
>         printf("should be zero? %u\n", elem_attr.func_info_cnt);
> 
> and I get:
> should be zero? 4202093

That's what I meant, but phrased it wrongly. Padding after the shorter
union fields, which are anonymous structures. That means that quite a
lot of the fields may end up non-zeroed in case that we initialize
a structure that is on the shorter side. I would say that in this case
the optimalization is very evil one, because it looks like these members
should have been zeroed at first.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list