Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace a couple of one-element arrays with flex-array members in fs/xfs/libxfs/xfs_da_format.h #251

Closed
GustavoARSilva opened this issue Feb 2, 2023 · 1 comment
Labels

Comments

@GustavoARSilva
Copy link
Collaborator

GustavoARSilva commented Feb 2, 2023

fs/xfs/libxfs/xfs_da_format.h:

620 typedef struct xfs_attr_leaf_name_local {
621         __be16  valuelen;               /* number of bytes in value */
622         __u8    namelen;                /* length of name bytes */
623         __u8    nameval[1];              /* name/value bytes */
624 } xfs_attr_leaf_name_local_t;
625 
626 typedef struct xfs_attr_leaf_name_remote {
627         __be32  valueblk;               /* block number of value bytes */
628         __be32  valuelen;               /* number of bytes in value */
629         __u8    namelen;                /* length of name bytes */
630         __u8    name[1];         /* name bytes */
631 } xfs_attr_leaf_name_remote_t;

Also, worth noting is that these fake flex-arrays are currently being used as arguments in calls to memcpy():

fs/xfs/libxfs/xfs_attr_leaf.c:

-		memcpy((char *)name_loc->nameval, args->name, args->namelen);
-		memcpy((char *)&name_loc->nameval[args->namelen], args->value,
-		memcpy((char *)name_rmt->name, args->name, args->namelen);
@GustavoARSilva GustavoARSilva self-assigned this Feb 2, 2023
@GustavoARSilva GustavoARSilva changed the title Replace a couple of one-element arrays into flex-array members in fs/xfs/libxfs/xfs_da_format.h Replace a couple of one-element arrays with flex-array members in fs/xfs/libxfs/xfs_da_format.h Feb 2, 2023
@GustavoARSilva GustavoARSilva added the [PATCH] Exists A patch exists to address the issue label Feb 3, 2023
solbjorn pushed a commit to solbjorn/linux that referenced this issue Feb 4, 2023
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: KSPP#79
Link: KSPP#251
Link: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/602902.html [1]
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
@kees kees added [Linux] v6.5 Released in Linux kernel v6.5 and removed [PATCH] Exists A patch exists to address the issue labels Feb 6, 2024
@kees
Copy link

kees commented Feb 6, 2024

Fixed in commit a49bbce.

@kees kees closed this as completed Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants