]> git.ipfire.org Git - thirdparty/util-linux.git/commit
lsfd: use memset explicitly to fill bpf_attr with zero
authorMasatake YAMATO <yamato@redhat.com>
Sat, 25 Apr 2026 23:57:17 +0000 (08:57 +0900)
committerKarel Zak <kzak@redhat.com>
Mon, 11 May 2026 09:44:48 +0000 (11:44 +0200)
commitd0dca4880f2c0bd91d5cedc34d9ad9c66c8aff35
tree7e851cfe2f5b36a0f0e64b2c7b03213d24139f61
parent4b85ff08c8167975df0085d1e00a4b62459afd1e
lsfd: use memset explicitly to fill bpf_attr with zero

The original code used initialize-lists for initializing
variables (attr) type of union bpf_attr.

However, the folloing syscalls failed with EINVAL:

     syscall(SYS_bpf, BPF_PROG_GET_FD_BY_ID, &attr, sizeof(attr));
     syscall(SYS_bpf, BPF_MAP_GET_FD_BY_ID, &attr, sizeof(attr));

CHECK_ATTR macro of Linux might cause EINVAL:

    /* helper macro to check that unused fields 'union bpf_attr' are zero */
    #define CHECK_ATTR(CMD) \
    memchr_inv((void *) &attr->CMD##_LAST_FIELD + \
       sizeof(attr->CMD##_LAST_FIELD), 0, \
       sizeof(*attr) - \
       offsetof(union bpf_attr, CMD##_LAST_FIELD) - \
       sizeof(attr->CMD##_LAST_FIELD)) != NULL

I doubt initialize-lists worked well.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
lsfd-cmd/unkn.c