From: Przemek Kitszel <przemyslaw.kitszel@intel.com>
To: Yabin Cui <yabinc@google.com>,
Nick Desaulniers <ndesaulniers@google.com>
Cc: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<llvm@lists.linux.dev>,
Steffen Klassert <steffen.klassert@secunet.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Nathan Chancellor <nathan@kernel.org>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>
Subject: Re: [PATCH] Fix initializing a static union variable
Date: Fri, 21 Jun 2024 13:01:35 +0200 [thread overview]
Message-ID: <929107ae-2ed3-4d3b-b719-62b7ccd60413@intel.com> (raw)
In-Reply-To: <20240620181736.1270455-1-yabinc@google.com>
On 6/20/24 20:17, Yabin Cui wrote:
> saddr_wildcard is a static union variable initialized with {}.
> But c11 standard doesn't guarantee initializing all fields as
> zero for this case. As in https://godbolt.org/z/rWvdv6aEx,
> clang only initializes the first field as zero, but the bits
> corresponding to other (larger) members are undefined.
Nice finding!
You have to add a Fixes tag, perhaps:
Fixes: 08ec9af1c062 ("xfrm: Fix xfrm_state_find() wrt. wildcard source
address.")
And the other thing is that I would change the order in the union, to
have largest element as the first. Would be best to also add such check
into static analysis tool/s.
>
> Signed-off-by: Yabin Cui <yabinc@google.com>
> ---
> net/xfrm/xfrm_state.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
> index 649bb739df0d..9bc69d703e5c 100644
> --- a/net/xfrm/xfrm_state.c
> +++ b/net/xfrm/xfrm_state.c
> @@ -1139,7 +1139,7 @@ xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr,
> struct xfrm_policy *pol, int *err,
> unsigned short family, u32 if_id)
> {
> - static xfrm_address_t saddr_wildcard = { };
> + static const xfrm_address_t saddr_wildcard;
> struct net *net = xp_net(pol);
> unsigned int h, h_wildcard;
> struct xfrm_state *x, *x0, *to_put;
prev parent reply other threads:[~2024-06-21 11:01 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-20 18:17 [PATCH] Fix initializing a static union variable Yabin Cui
2024-06-20 19:31 ` Nick Desaulniers
2024-06-20 19:47 ` Nick Desaulniers
2024-06-20 19:54 ` Nick Desaulniers
2024-06-21 11:24 ` Ballman, Aaron
2024-06-21 20:49 ` Yabin Cui
2024-06-21 11:07 ` Herbert Xu
2024-06-23 16:51 ` Linus Torvalds
2024-06-23 17:05 ` Linus Torvalds
2024-06-24 18:04 ` Yabin Cui
2024-06-21 11:01 ` Przemek Kitszel [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=929107ae-2ed3-4d3b-b719-62b7ccd60413@intel.com \
--to=przemyslaw.kitszel@intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=herbert@gondor.apana.org.au \
--cc=justinstitt@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=steffen.klassert@secunet.com \
--cc=yabinc@google.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