From: Kees Cook <keescook@chromium.org>
To: David Lechner <dlechner@baylibre.com>
Cc: "Mark Brown" <broonie@kernel.org>,
"Michael Hennerich" <michael.hennerich@analog.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH 2/3] spi: axi-spi-engine: use __counted_by() attribute
Date: Fri, 1 Mar 2024 12:41:59 -0800 [thread overview]
Message-ID: <202403011235.C326E3D46@keescook> (raw)
In-Reply-To: <20240301-mainline-axi-spi-engine-small-cleanups-v1-2-241dfd2a79f7@baylibre.com>
On Fri, Mar 01, 2024 at 02:25:19PM -0600, David Lechner wrote:
> This adds the __counted_by() attribute to the flex array at the end of
> struct spi_engine_program in the AXI SPI Engine controller driver.
>
> Suggested-by: Nuno Sá <nuno.sa@analog.com>
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---
> drivers/spi/spi-axi-spi-engine.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c
> index d89f75170c9e..e801eed820df 100644
> --- a/drivers/spi/spi-axi-spi-engine.c
> +++ b/drivers/spi/spi-axi-spi-engine.c
> @@ -75,7 +75,7 @@
>
> struct spi_engine_program {
> unsigned int length;
> - uint16_t instructions[];
> + uint16_t instructions[] __counted_by(length);
> };
You'll also need to change places where you deal with changes to
"length", as now accesses to "instructions" will be bounds-checked
by the compiler. For example, this change:
static void spi_engine_program_add_cmd(struct spi_engine_program *p,
bool dry, uint16_t cmd)
{
p->length++;
if (!dry)
p->instructions[p->length - 1] = cmd;
}
--
Kees Cook
next prev parent reply other threads:[~2024-03-01 20:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-01 20:25 [PATCH 0/3] spi: axi-spi-engine: small cleanups David Lechner
2024-03-01 20:25 ` [PATCH 1/3] spi: axi-spi-engine: remove p from struct spi_engine_message_state David Lechner
2024-03-01 20:42 ` Kees Cook
2024-03-01 20:25 ` [PATCH 2/3] spi: axi-spi-engine: use __counted_by() attribute David Lechner
2024-03-01 20:41 ` Kees Cook [this message]
2024-03-01 20:25 ` [PATCH 3/3] spi: axi-spi-engine: use struct_size() macro David Lechner
2024-03-01 20:45 ` 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=202403011235.C326E3D46@keescook \
--to=keescook@chromium.org \
--cc=broonie@kernel.org \
--cc=dlechner@baylibre.com \
--cc=gustavoars@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=michael.hennerich@analog.com \
--cc=nuno.sa@analog.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