KSPP / linux

Linux kernel source tree (Kernel Self Protection Project)
https://kernsec.org/wiki/index.php/Kernel_Self_Protection_Project
Other
82 stars 5 forks source link

"error: XFS: sizeof(struct xfs_attr_leafblock_t) is wrong" in fs/xfs/xfs_super.c #54

Closed GustavoARSilva closed 8 months ago

GustavoARSilva commented 4 years ago

When replacing the one-element array entries[1] with a flexible-array member in struct xfs_attr_leafblock:

diff --git a/fs/xfs/libxfs/xfs_da_format.h b/fs/xfs/libxfs/xfs_da_format.h
index 08c0a4d98b89..6d9fea2e5e9c 100644
--- a/fs/xfs/libxfs/xfs_da_format.h
+++ b/fs/xfs/libxfs/xfs_da_format.h
@@ -631,7 +631,7 @@ typedef struct xfs_attr_leaf_name_remote {

 typedef struct xfs_attr_leafblock {
        xfs_attr_leaf_hdr_t     hdr;    /* constant-structure header block */
-       xfs_attr_leaf_entry_t   entries[1];     /* sorted on key, not name */
+       xfs_attr_leaf_entry_t   entries[];      /* sorted on key, not name */
        /*
         * The rest of the block contains the following structures after the
         * leaf entries, growing from the bottom up. The variables are never

the following error shows up:

                 from fs/xfs/xfs_super.c:7:
In function ‘xfs_check_ondisk_structs’,
    inlined from ‘init_xfs_fs’ at fs/xfs/xfs_super.c:2071:2:
./include/linux/compiler.h:394:38: error: call to ‘__compiletime_assert_1648’ declared with attribute error: XFS: sizeof(xfs_attr_leafblock_t) is wrong, expected 40
  394 |  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
      |                                      ^
./include/linux/compiler.h:375:4: note: in definition of macro ‘__compiletime_assert’
  375 |    prefix ## suffix();    \
      |    ^~~~~~
./include/linux/compiler.h:394:2: note: in expansion of macro ‘_compiletime_assert’
  394 |  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
      |  ^~~~~~~~~~~~~~~~~~~
./include/linux/build_bug.h:39:37: note: in expansion of macro ‘compiletime_assert’
   39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
      |                                     ^~~~~~~~~~~~~~~~~~
fs/xfs/xfs_ondisk.h:10:2: note: in expansion of macro ‘BUILD_BUG_ON_MSG’
   10 |  BUILD_BUG_ON_MSG(sizeof(structname) != (size), "XFS: sizeof(" \
      |  ^~~~~~~~~~~~~~~~
fs/xfs/xfs_ondisk.h:86:2: note: in expansion of macro ‘XFS_CHECK_STRUCT_SIZE’
   86 |  XFS_CHECK_STRUCT_SIZE(xfs_attr_leafblock_t,  40);
      |  ^~~~~~~~~~~~~~~~~~~~~
scripts/Makefile.build:272: recipe for target 'fs/xfs/xfs_super.o' failed

See flexible-array conversions issue.

kees commented 8 months ago

Fixed in commit a49bbce.