LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Vincent MAILHOL <mailhol.vincent@wanadoo.fr>
Cc: Wolfgang Grandegger <wg@grandegger.com>,
	Marc Kleine-Budde <mkl@pengutronix.de>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Arunachalam Santhanam <arunachalam.santhanam@in.bosch.com>,
	linux-can <linux-can@vger.kernel.org>,
	netdev <netdev@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>,
	linux-hardening@vger.kernel.org
Subject: Re: [PATCH] can: etas_es58x: Replace 0-element raw_msg array
Date: Wed, 18 Aug 2021 02:03:16 -0700	[thread overview]
Message-ID: <202108180159.5C1CEE70F@keescook> (raw)
In-Reply-To: <CAMZ6RqLecbytJFQDC35n7YiqBbrB3--POofnXFeH77Zi2xzqWA@mail.gmail.com>

On Wed, Aug 18, 2021 at 04:55:20PM +0900, Vincent MAILHOL wrote:
> At the end, the only goal of raw_msg[] is to have a tag pointing
> to the beginning of the union. It would be virtually identical to
> something like:
> |    u8 raw_msg[];
> |    union {
> |        /* ... */
> |    } __packed ;
> 
> I had a look at your work and especially at your struct_group() macro.
> Do you think it would make sense to introduce a union_group()?
> 
> Result would look like:
> 
> |    union_group_attr(urb_msg, __packed, /* raw_msg renamed to urb_msg */
> |        struct es58x_fd_tx_conf_msg tx_conf_msg;
> |        u8 tx_can_msg_buf[ES58X_FD_TX_BULK_MAX * ES58X_FD_CANFD_TX_LEN];
> |        u8 rx_can_msg_buf[ES58X_FD_RX_BULK_MAX * ES58X_FD_CANFD_RX_LEN];
> |        struct es58x_fd_echo_msg echo_msg[ES58X_FD_ECHO_BULK_MAX];
> |        struct es58x_fd_rx_event_msg rx_event_msg;
> |        struct es58x_fd_tx_ack_msg tx_ack_msg;
> |        __le64 timestamp;
> |        __le32 rx_cmd_ret_le32;
> |    );
> 
> And I can then use urb_msg in place of the old raw_msg (might
> need a bit of rework here and there but I can take care of it).
> 
> This is the most pretty way I can think of to remove this zero length array.
> Keeping the raw_msg[] but with another size seems odd to me.
> 
> Or maybe I would be the only one using this feature in the full
> tree? In that case, maybe it would make sense to keep the
> union_group_attr() macro local to the etas_es58x driver?

I actually ended up with something close to this idea, but more
generalized for other cases in the kernel. There was a sane way to
include a "real" flexible array in a union (or alone in a struct), so
I've proposed this flex_array() helper:
https://lore.kernel.org/lkml/20210818081118.1667663-2-keescook@chromium.org/

and then it's just a drop-in replacement for all the places that need
this fixed, including etas_es58x:
https://lore.kernel.org/lkml/20210818081118.1667663-3-keescook@chromium.org/#Z30drivers:net:can:usb:etas_es58x:es581_4.h

Hopefully this will work out; I think it's as clean as we can get for
now. :)

-- 
Kees Cook

  reply	other threads:[~2021-08-18  9:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-18  3:40 Kees Cook
2021-08-18  5:13 ` Vincent MAILHOL
2021-08-18  6:48   ` Kees Cook
2021-08-18  7:55     ` Vincent MAILHOL
2021-08-18  9:03       ` Kees Cook [this message]
2021-08-18  9:33         ` Vincent MAILHOL
2021-08-19  0:02           ` Kees Cook

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=202108180159.5C1CEE70F@keescook \
    --to=keescook@chromium.org \
    --cc=arunachalam.santhanam@in.bosch.com \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mailhol.vincent@wanadoo.fr \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=wg@grandegger.com \
    --subject='Re: [PATCH] can: etas_es58x: Replace 0-element raw_msg array' \
    /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

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).