BPF List
 help / color / mirror / Atom feed
From: Daniel Borkmann <daniel@iogearbox.net>
To: Yonghong Song <yonghong.song@linux.dev>, bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	kernel-team@fb.com, Martin KaFai Lau <martin.lau@kernel.org>
Subject: Re: [PATCH bpf-next v3] libbpf: Fix potential uninitialized tail padding with LIBBPF_OPTS_RESET
Date: Wed, 8 Nov 2023 06:38:35 +0100	[thread overview]
Message-ID: <332d7a0b-d763-2e6f-3c70-e8e73de1b5a2@iogearbox.net> (raw)
In-Reply-To: <20231107201511.2548645-1-yonghong.song@linux.dev>

On 11/7/23 9:15 PM, Yonghong Song wrote:
> Martin reported that there is a libbpf complaining of non-zero-value tail
> padding with LIBBPF_OPTS_RESET macro if struct bpf_netkit_opts is modified
> to have a 4-byte tail padding. This only happens to clang compiler.
> The commend line is: ./test_progs -t tc_netkit_multi_links
> Martin and I did some investigation and found this indeed the case and
> the following are the investigation details.

[...]

Too bad we need this detour, but fix lgtm, thanks!

> diff --git a/tools/lib/bpf/libbpf_common.h b/tools/lib/bpf/libbpf_common.h
> index b7060f254486..8fe248e14eb6 100644
> --- a/tools/lib/bpf/libbpf_common.h
> +++ b/tools/lib/bpf/libbpf_common.h
> @@ -79,11 +79,14 @@
>    */
>   #define LIBBPF_OPTS_RESET(NAME, ...)					    \
>   	do {								    \
> -		memset(&NAME, 0, sizeof(NAME));				    \
> -		NAME = (typeof(NAME)) {					    \
> -			.sz = sizeof(NAME),				    \
> -			__VA_ARGS__					    \
> -		};							    \
> +		typeof(NAME) ___##NAME = ({ 				    \
> +			memset(&___##NAME, 0, sizeof(NAME));		    \
> +			(typeof(NAME)) {				    \
> +				.sz = sizeof(NAME),			    \
> +				__VA_ARGS__				    \
> +			};						    \
> +		});							    \
> +		memcpy(&NAME, &___##NAME, sizeof(NAME));		    \
>   	} while (0)
>   
>   #endif /* __LIBBPF_LIBBPF_COMMON_H */
> 


      parent reply	other threads:[~2023-11-08  5:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-07 20:15 [PATCH bpf-next v3] libbpf: Fix potential uninitialized tail padding with LIBBPF_OPTS_RESET Yonghong Song
2023-11-08  0:40 ` patchwork-bot+netdevbpf
2023-11-08  5:38 ` Daniel Borkmann [this message]

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=332d7a0b-d763-2e6f-3c70-e8e73de1b5a2@iogearbox.net \
    --to=daniel@iogearbox.net \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=kernel-team@fb.com \
    --cc=martin.lau@kernel.org \
    --cc=yonghong.song@linux.dev \
    /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