From: Kees Cook <kees@kernel.org>
To: Gal Pressman <gal@nvidia.com>
Cc: netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
Tariq Toukan <tariqt@nvidia.com>,
Louis Peens <louis.peens@corigine.com>,
Simon Horman <horms@kernel.org>, David Ahern <dsahern@kernel.org>,
Pravin B Shelar <pshelar@ovn.org>,
Yotam Gigi <yotam.gi@gmail.com>,
Jamal Hadi Salim <jhs@mojatatu.com>,
Cong Wang <xiyou.wangcong@gmail.com>,
Jiri Pirko <jiri@resnulli.us>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
dev@openvswitch.org, linux-hardening@vger.kernel.org,
Ilya Maximets <i.maximets@ovn.org>,
Alexander Lobakin <aleksander.lobakin@intel.com>,
Cosmin Ratiu <cratiu@nvidia.com>
Subject: Re: [PATCH net-next v4 2/2] net: Add options as a flexible array to struct ip_tunnel_info
Date: Wed, 19 Feb 2025 09:28:40 -0800 [thread overview]
Message-ID: <202502190928.D2C5927D0@keescook> (raw)
In-Reply-To: <20250219143256.370277-3-gal@nvidia.com>
On Wed, Feb 19, 2025 at 04:32:56PM +0200, Gal Pressman wrote:
> Remove the hidden assumption that options are allocated at the end of
> the struct, and teach the compiler about them using a flexible array.
>
> With this, we can revert the unsafe_memcpy() call we have in
> tun_dst_unclone() [1], and resolve the false field-spanning write
> warning caused by the memcpy() in ip_tunnel_info_opts_set().
>
> The layout of struct ip_tunnel_info remains the same with this patch.
> Before this patch, there was an implicit padding at the end of the
> struct, options would be written at 'info + 1' which is after the
> padding.
> This will remain the same as this patch explicitly aligns 'options'.
> The alignment is needed as the options are later casted to different
> structs, and might result in unaligned memory access.
>
> Pahole output before this patch:
> struct ip_tunnel_info {
> struct ip_tunnel_key key; /* 0 64 */
>
> /* XXX last struct has 1 byte of padding */
>
> /* --- cacheline 1 boundary (64 bytes) --- */
> struct ip_tunnel_encap encap; /* 64 8 */
> struct dst_cache dst_cache; /* 72 16 */
> u8 options_len; /* 88 1 */
> u8 mode; /* 89 1 */
>
> /* size: 96, cachelines: 2, members: 5 */
> /* padding: 6 */
> /* paddings: 1, sum paddings: 1 */
> /* last cacheline: 32 bytes */
> };
>
> Pahole output after this patch:
> struct ip_tunnel_info {
> struct ip_tunnel_key key; /* 0 64 */
>
> /* XXX last struct has 1 byte of padding */
>
> /* --- cacheline 1 boundary (64 bytes) --- */
> struct ip_tunnel_encap encap; /* 64 8 */
> struct dst_cache dst_cache; /* 72 16 */
> u8 options_len; /* 88 1 */
> u8 mode; /* 89 1 */
>
> /* XXX 6 bytes hole, try to pack */
>
> u8 options[] __attribute__((__aligned__(16))); /* 96 0 */
>
> /* size: 96, cachelines: 2, members: 6 */
> /* sum members: 90, holes: 1, sum holes: 6 */
> /* paddings: 1, sum paddings: 1 */
> /* forced alignments: 1, forced holes: 1, sum forced holes: 6 */
> /* last cacheline: 32 bytes */
> } __attribute__((__aligned__(16)));
>
> [1] Commit 13cfd6a6d7ac ("net: Silence false field-spanning write warning in metadata_dst memcpy")
>
> Link: https://lore.kernel.org/all/53D1D353-B8F6-4ADC-8F29-8C48A7C9C6F1@kernel.org/
> Suggested-by: Kees Cook <kees@kernel.org>
> Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com>
> Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
> Signed-off-by: Gal Pressman <gal@nvidia.com>
Thanks for these updates and the pahole output. :)
Reviewed-by: Kees Cook <kees@kernel.org>
--
Kees Cook
next prev parent reply other threads:[~2025-02-19 17:28 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-19 14:32 [PATCH net-next v4 0/2] Flexible array for ip tunnel options Gal Pressman
2025-02-19 14:32 ` [PATCH net-next v4 1/2] ip_tunnel: Use ip_tunnel_info() helper instead of 'info + 1' Gal Pressman
2025-02-19 17:28 ` Kees Cook
2025-02-19 14:32 ` [PATCH net-next v4 2/2] net: Add options as a flexible array to struct ip_tunnel_info Gal Pressman
2025-02-19 17:28 ` Kees Cook [this message]
2025-02-20 21:30 ` [PATCH net-next v4 0/2] Flexible array for ip tunnel options patchwork-bot+netdevbpf
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=202502190928.D2C5927D0@keescook \
--to=kees@kernel.org \
--cc=aleksander.lobakin@intel.com \
--cc=andrew+netdev@lunn.ch \
--cc=cratiu@nvidia.com \
--cc=davem@davemloft.net \
--cc=dev@openvswitch.org \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=gal@nvidia.com \
--cc=gustavoars@kernel.org \
--cc=horms@kernel.org \
--cc=i.maximets@ovn.org \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=louis.peens@corigine.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pshelar@ovn.org \
--cc=tariqt@nvidia.com \
--cc=xiyou.wangcong@gmail.com \
--cc=yotam.gi@gmail.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;
as well as URLs for NNTP newsgroup(s).