From: "Darrick J. Wong" <djwong@kernel.org>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH][next] xfs: Replace one-element arrays with flexible-array members
Date: Fri, 3 Feb 2023 13:32:16 -0800 [thread overview]
Message-ID: <Y919YPKebVjQWwTM@magnolia> (raw)
In-Reply-To: <Y9xiYmVLRIKdpJcC@work>
On Thu, Feb 02, 2023 at 07:24:50PM -0600, Gustavo A. R. Silva wrote:
> One-element arrays are deprecated, and we are replacing them with flexible
> array members instead. So, replace one-element arrays with flexible-array
> members in structures xfs_attr_leaf_name_local and
> xfs_attr_leaf_name_remote.
>
> The only binary differences reported after the changes are all like
> these:
>
> fs/xfs/libxfs/xfs_attr_leaf.o
> _@@ -435,7 +435,7 @@
> 3b8: movzbl 0x2(%rbx),%eax
> 3bc: rol $0x8,%bp
> 3c0: movzwl %bp,%ebp
> - 3c3: lea 0x2(%rax,%rbp,1),%ebx
> + 3c3: lea 0x3(%rax,%rbp,1),%ebx
> 3c7: call 3cc <xfs_attr_leaf_entsize+0x8c>
> 3c8: R_X86_64_PLT32 __tsan_func_exit-0x4
> 3cc: or $0x3,%ebx
> _@@ -454,7 +454,7 @@
> 3ea: movzbl 0x8(%rbx),%ebx
> 3ee: call 3f3 <xfs_attr_leaf_entsize+0xb3>
> 3ef: R_X86_64_PLT32 __tsan_func_exit-0x4
> - 3f3: add $0xa,%ebx
> + 3f3: add $0xb,%ebx
> 3f6: or $0x3,%ebx
> 3f9: add $0x1,%ebx
> 3fc: mov %ebx,%eax
>
> similar changes in fs/xfs/scrub/attr.o and fs/xfs/xfs.o object files.
>
> And the reason for this is because of the round_up() macro called in
> functions xfs_attr_leaf_entsize_remote() and xfs_attr_leaf_entsize_local(),
> which is compensanting for the one-byte reduction in size (due to the
> flex-array transformation) of structures xfs_attr_leaf_name_remote and
> xfs_attr_leaf_name_local. So, sizes remain the same before and after
> changes.
>
> This helps with the ongoing efforts to tighten the FORTIFY_SOURCE
> routines on memcpy() and help us make progress towards globally
> enabling -fstrict-flex-arrays=3 [1].
>
> Link: https://github.com/KSPP/linux/issues/79
> Link: https://github.com/KSPP/linux/issues/251
> Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1]
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
> fs/xfs/libxfs/xfs_da_format.h | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/fs/xfs/libxfs/xfs_da_format.h b/fs/xfs/libxfs/xfs_da_format.h
> index 25e2841084e1..e1e62ebb0c44 100644
> --- a/fs/xfs/libxfs/xfs_da_format.h
> +++ b/fs/xfs/libxfs/xfs_da_format.h
> @@ -620,14 +620,14 @@ typedef struct xfs_attr_leaf_entry { /* sorted on key, not name */
> typedef struct xfs_attr_leaf_name_local {
> __be16 valuelen; /* number of bytes in value */
> __u8 namelen; /* length of name bytes */
> - __u8 nameval[1]; /* name/value bytes */
> + __u8 nameval[]; /* name/value bytes */
> } xfs_attr_leaf_name_local_t;
>
> typedef struct xfs_attr_leaf_name_remote {
> __be32 valueblk; /* block number of value bytes */
> __be32 valuelen; /* number of bytes in value */
> __u8 namelen; /* length of name bytes */
> - __u8 name[1]; /* name bytes */
> + __u8 name[]; /* name bytes */
Does the large comment about m68k problems in xfs_ondisk.h need updating
here?
--D
> } xfs_attr_leaf_name_remote_t;
>
> typedef struct xfs_attr_leafblock {
> @@ -747,13 +747,13 @@ xfs_attr3_leaf_name_local(xfs_attr_leafblock_t *leafp, int idx)
> */
> static inline int xfs_attr_leaf_entsize_remote(int nlen)
> {
> - return round_up(sizeof(struct xfs_attr_leaf_name_remote) - 1 +
> + return round_up(sizeof(struct xfs_attr_leaf_name_remote) +
> nlen, XFS_ATTR_LEAF_NAME_ALIGN);
> }
>
> static inline int xfs_attr_leaf_entsize_local(int nlen, int vlen)
> {
> - return round_up(sizeof(struct xfs_attr_leaf_name_local) - 1 +
> + return round_up(sizeof(struct xfs_attr_leaf_name_local) +
> nlen + vlen, XFS_ATTR_LEAF_NAME_ALIGN);
> }
>
> --
> 2.34.1
>
next prev parent reply other threads:[~2023-02-03 21:32 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-03 1:24 [PATCH][next] xfs: Replace one-element arrays with flexible-array members Gustavo A. R. Silva
2023-02-03 17:53 ` Kees Cook
2023-02-06 19:17 ` Gustavo A. R. Silva
2023-02-03 21:32 ` Darrick J. Wong [this message]
2023-02-05 22:51 ` Dave Chinner
2023-02-06 0:21 ` Gustavo A. R. Silva
-- strict thread matches above, loose matches on Subject: below --
2021-03-02 15:05 Gustavo A. R. Silva
2021-03-09 17:42 ` Darrick J. Wong
2021-03-09 19:57 ` Gustavo A. R. Silva
2021-03-09 21:26 ` Darrick J. Wong
2021-03-09 22:03 ` Gustavo A. R. Silva
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=Y919YPKebVjQWwTM@magnolia \
--to=djwong@kernel.org \
--cc=gustavoars@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-xfs@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;
as well as URLs for NNTP newsgroup(s).