From: Kees Cook <keescook@chromium.org>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Kent Overstreet <kent.overstreet@linux.dev>,
Brian Foster <bfoster@redhat.com>,
linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH][next] bcachefs: Use DECLARE_FLEX_ARRAY() helper and fix multiple -Warray-bounds warnings
Date: Mon, 6 Nov 2023 16:08:00 -0800 [thread overview]
Message-ID: <202311061607.FFD1D68@keescook> (raw)
In-Reply-To: <ZUloNt0HSulJgZNH@work>
On Mon, Nov 06, 2023 at 04:27:02PM -0600, Gustavo A. R. Silva wrote:
> Transform zero-length array `s` into a proper flexible-array
> member in `struct snapshot_table` via the DECLARE_FLEX_ARRAY()
> helper; and fix tons of the following -Warray-bounds warnings:
>
> fs/bcachefs/snapshot.h:36:21: warning: array subscript <unknown> is outside array bounds of 'struct snapshot_t[0]' [-Warray-bounds=]
> fs/bcachefs/snapshot.h:36:21: warning: array subscript <unknown> is outside array bounds of 'struct snapshot_t[0]' [-Warray-bounds=]
> fs/bcachefs/snapshot.c:135:70: warning: array subscript <unknown> is outside array bounds of 'struct snapshot_t[0]' [-Warray-bounds=]
> fs/bcachefs/snapshot.h:36:21: warning: array subscript <unknown> is outside array bounds of 'struct snapshot_t[0]' [-Warray-bounds=]
> fs/bcachefs/snapshot.h:36:21: warning: array subscript <unknown> is outside array bounds of 'struct snapshot_t[0]' [-Warray-bounds=]
> fs/bcachefs/snapshot.h:36:21: warning: array subscript <unknown> is outside array bounds of 'struct snapshot_t[0]' [-Warray-bounds=]
>
> This helps with the ongoing efforts to globally enable -Warray-bounds.
>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
> fs/bcachefs/subvolume_types.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/bcachefs/subvolume_types.h b/fs/bcachefs/subvolume_types.h
> index 86833445af20..2d2e66a4e468 100644
> --- a/fs/bcachefs/subvolume_types.h
> +++ b/fs/bcachefs/subvolume_types.h
> @@ -20,7 +20,7 @@ struct snapshot_t {
> };
>
> struct snapshot_table {
> - struct snapshot_t s[0];
> + DECLARE_FLEX_ARRAY(struct snapshot_t, s);
> };
Yup, this is the current way forward for 0-to-flex transformations in
unions or alone in structs (until it's supported correctly by GCC and
Clang, which is in progress).
Reviewed-by: Kees Cook <keescook@chromium.org>
-Kees
--
Kees Cook
next prev parent reply other threads:[~2023-11-07 0:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-06 22:27 [PATCH][next] bcachefs: Use DECLARE_FLEX_ARRAY() helper and fix multiple -Warray-bounds warnings Gustavo A. R. Silva
2023-11-07 0:08 ` Kees Cook [this message]
2023-11-07 0:43 ` Kent Overstreet
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=202311061607.FFD1D68@keescook \
--to=keescook@chromium.org \
--cc=bfoster@redhat.com \
--cc=gustavoars@kernel.org \
--cc=kent.overstreet@linux.dev \
--cc=linux-bcachefs@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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