All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Alexander Lobakin <aleksander.lobakin@intel.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Larysa Zaremba <larysa.zaremba@intel.com>,
	netdev@vger.kernel.org,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	linux-kernel@vger.kernel.org, Eric Dumazet <edumazet@google.com>,
	intel-wired-lan@lists.osuosl.org,
	linux-hardening@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	"David S. Miller" <davem@davemloft.net>
Subject: Re: [Intel-wired-lan] [PATCH net-next 1/3] virtchnl: fix fake 1-elem arrays in structs allocated as `nents + 1` - 1
Date: Fri, 4 Aug 2023 01:27:02 -0700	[thread overview]
Message-ID: <202308040126.ADDA993@keescook> (raw)
In-Reply-To: <20230728155207.10042-2-aleksander.lobakin@intel.com>

On Fri, Jul 28, 2023 at 05:52:05PM +0200, Alexander Lobakin wrote:
> The two most problematic virtchnl structures are virtchnl_rss_key and
> virtchnl_rss_lut. Their "flex" arrays have the type of u8, thus, when
> allocating / checking, the actual size is calculated as `sizeof +
> nents - 1 byte`. But their sizeof() is not 1 byte larger than the size
> of such structure with proper flex array, it's two bytes larger due to
> the padding. That said, their size is always 1 byte larger unless
> there are no tail elements -- then it's +2 bytes.
> Add virtchnl_struct_size() macro which will handle this case (and later
> other cases as well). Make its calling conv the same as we call
> struct_size() to allow it to be drop-in, even though it's unlikely to
> become possible to switch to generic API. The macro will calculate a
> proper size of a structure with a flex array at the end, so that it
> becomes transparent for the compilers, but add the difference from the
> old values, so that the real size of sorta-ABI-messages doesn't change.
> Use it on the allocation side in IAVF and the receiving side (defined
> as static inline in virtchnl.h) for the mentioned two structures.
> 
> Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>

This is a novel approach to solving the ABI issues for a 1-elem
conversion, but I have been convinced it's a workable approach here. :)
Thanks for doing this conversion!

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook
_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan@osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan

WARNING: multiple messages have this Message-ID (diff)
From: Kees Cook <keescook@chromium.org>
To: Alexander Lobakin <aleksander.lobakin@intel.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Larysa Zaremba <larysa.zaremba@intel.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	netdev@vger.kernel.org, linux-hardening@vger.kernel.org,
	intel-wired-lan@lists.osuosl.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next 1/3] virtchnl: fix fake 1-elem arrays in structs allocated as `nents + 1` - 1
Date: Fri, 4 Aug 2023 01:27:02 -0700	[thread overview]
Message-ID: <202308040126.ADDA993@keescook> (raw)
In-Reply-To: <20230728155207.10042-2-aleksander.lobakin@intel.com>

On Fri, Jul 28, 2023 at 05:52:05PM +0200, Alexander Lobakin wrote:
> The two most problematic virtchnl structures are virtchnl_rss_key and
> virtchnl_rss_lut. Their "flex" arrays have the type of u8, thus, when
> allocating / checking, the actual size is calculated as `sizeof +
> nents - 1 byte`. But their sizeof() is not 1 byte larger than the size
> of such structure with proper flex array, it's two bytes larger due to
> the padding. That said, their size is always 1 byte larger unless
> there are no tail elements -- then it's +2 bytes.
> Add virtchnl_struct_size() macro which will handle this case (and later
> other cases as well). Make its calling conv the same as we call
> struct_size() to allow it to be drop-in, even though it's unlikely to
> become possible to switch to generic API. The macro will calculate a
> proper size of a structure with a flex array at the end, so that it
> becomes transparent for the compilers, but add the difference from the
> old values, so that the real size of sorta-ABI-messages doesn't change.
> Use it on the allocation side in IAVF and the receiving side (defined
> as static inline in virtchnl.h) for the mentioned two structures.
> 
> Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>

This is a novel approach to solving the ABI issues for a 1-elem
conversion, but I have been convinced it's a workable approach here. :)
Thanks for doing this conversion!

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

  parent reply	other threads:[~2023-08-04  8:27 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-28 15:52 [Intel-wired-lan] [PATCH net-next 0/3] virtchnl: fix fake 1-elem arrays Alexander Lobakin
2023-07-28 15:52 ` Alexander Lobakin
2023-07-28 15:52 ` [Intel-wired-lan] [PATCH net-next 1/3] virtchnl: fix fake 1-elem arrays in structs allocated as `nents + 1` - 1 Alexander Lobakin
2023-07-28 15:52   ` Alexander Lobakin
2023-07-28 22:43   ` [Intel-wired-lan] " Kees Cook
2023-07-28 22:43     ` Kees Cook
2023-08-01 13:08     ` [Intel-wired-lan] " Alexander Lobakin
2023-08-01 13:08       ` Alexander Lobakin
2023-08-04  8:27   ` Kees Cook [this message]
2023-08-04  8:27     ` Kees Cook
2023-08-04 15:42     ` [Intel-wired-lan] " Alexander Lobakin
2023-08-04 15:42       ` Alexander Lobakin
2023-08-04 17:29       ` [Intel-wired-lan] " Kees Cook
2023-08-04 17:29         ` Kees Cook
2023-08-04 17:33         ` [Intel-wired-lan] " Alexander Lobakin
2023-08-04 17:33           ` Alexander Lobakin
2023-08-16 12:48           ` [Intel-wired-lan] " Romanowski, Rafal
2023-08-16 12:48             ` Romanowski, Rafal
2023-07-28 15:52 ` [Intel-wired-lan] [PATCH net-next 2/3] virtchnl: fix fake 1-elem arrays in structures allocated as `nents + 1` Alexander Lobakin
2023-07-28 15:52   ` Alexander Lobakin
2023-08-04  8:29   ` [Intel-wired-lan] " Kees Cook
2023-08-04  8:29     ` Kees Cook
2023-08-16 12:49     ` [Intel-wired-lan] " Romanowski, Rafal
2023-08-16 12:49       ` Romanowski, Rafal
2023-07-28 15:52 ` [Intel-wired-lan] [PATCH net-next 3/3] virtchnl: fix fake 1-elem arrays for structures allocated as `nents` Alexander Lobakin
2023-07-28 15:52   ` Alexander Lobakin
2023-08-04  8:30   ` [Intel-wired-lan] " Kees Cook
2023-08-04  8:30     ` Kees Cook
2023-08-16 12:51     ` [Intel-wired-lan] " Romanowski, Rafal
2023-08-16 12:51       ` Romanowski, Rafal
2023-08-03 15:55 ` [Intel-wired-lan] [PATCH net-next 0/3] virtchnl: fix fake 1-elem arrays Alexander Lobakin
2023-08-03 15:55   ` Alexander Lobakin
2023-08-04 16:38 ` [Intel-wired-lan] " Alexander Lobakin
2023-08-04 16:38   ` Alexander Lobakin
2023-08-04 18:07   ` [Intel-wired-lan] " Tony Nguyen
2023-08-04 18:07     ` Tony Nguyen
2023-08-04 18:09     ` [Intel-wired-lan] " Alexander Lobakin
2023-08-04 18:09       ` Alexander Lobakin
2023-08-16 12:48       ` [Intel-wired-lan] " Romanowski, Rafal
2023-08-16 12:48         ` Romanowski, Rafal

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=202308040126.ADDA993@keescook \
    --to=keescook@chromium.org \
    --cc=aleksander.lobakin@intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gustavoars@kernel.org \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=kuba@kernel.org \
    --cc=larysa.zaremba@intel.com \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.