xfs: Fix xfs_attr_leafblock definition
PATCH 1/1 xfs: Fix xfs_attr_leafblock definition
struct xfs_attr_leafblock contains 'entries' array which is declared with size 1 altough it can in fact contain much more entries. Since this array is followed by further struct members, gcc (at least in version 4.8.3) thinks that the array has the fixed size of 1 element and thus may optimize away all accesses beyond the end of array resulting in non-working code. This problem was only observed with userspace code in xfsprogs, however it's better to be safe in kernel as well and have matching kernel and xfsprogs definitions.
--- fs/xfs/libxfs/xfs_da_format.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
This is a kernel version of the xfsprogs patch I've sent a while ago.
fs/xfs/libxfs/xfs_da_format.h +9 -2
@@ -680,8 +680,15 @@ 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_name_local_t namelist;/* grows from bottom of buf */ -xfs_attr_leaf_name_remote_t valuelist;/* grows from bottom of buf */ +/* +* The rest of the block contains the following structures after the +* leaf entries, growing from the bottom up. The variables are never +* referenced and definining them can actually make gcc optimize away +* accesses to the 'entries' array above index 0 so don't do that. +* +* xfs_attr_leaf_name_local_t namelist; +* xfs_attr_leaf_name_remote_t valuelist; +*/ }xfs_attr_leafblock_t ;/*
Signature · 6 lines
2.1.4 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Quoted 11 lines · Jan Kara
struct
xfs_attr_leafblockcontains 'entries' array which is declared with size 1 altough it can in fact contain much more entries. Since this array is followed by further struct members, gcc (at least in version 4.8.3) thinks that the array has the fixed size of 1 element and thus may optimize away all accesses beyond the end of array resulting in non-working code. This problem was only observed with userspace code in xfsprogs, however it's better to be safe in kernel as well and have matching kernel and xfsprogs definitions.Signed-off-by Jan Kara<[email protected]>---
I hit this bug in SLES12 and RHEL7 XFS kernel code. It is the gcc 4.8's new loop optimization routine. A person can bypass it with the option:
-fno-aggressive-loop-optimizations
but this fixes the source of the problem.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 13 lines · Mark Tinguely
Quoted 11 lines · Jan Kara
struct
xfs_attr_leafblockcontains 'entries' array which is declared with size 1 altough it can in fact contain much more entries. Since this array is followed by further struct members, gcc (at least in version 4.8.3) thinks that the array has the fixed size of 1 element and thus may optimize away all accesses beyond the end of array resulting in non-working code. This problem was only observed with userspace code in xfsprogs, however it's better to be safe in kernel as well and have matching kernel and xfsprogs definitions.Signed-off-by Jan Kara<[email protected]>---
Quoted 7 lines
I hit this bug in SLES12 and RHEL7 XFS kernel code. It is the gcc 4.8's new loop optimization routine. A person can bypass it with the option:
-fno-aggressive-loop-optimizations
but this fixes the source of the problem.Acked-by Mark Tinguely <[email protected]>
Hi Mark - it's great that you had found and identified the exact compiler optimisation that was causing miscompilation of the XFS code.
Troy, what's not great about this is that SGI hasn't seen fit to report this bug upstream or to their distro partners in a prompt manner. Can you please make sure that any other XFS bug fixes that SGI are sitting on get communicated to the appropriate venue so they can be addressed without undue delay?
Thanks,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Quoted 21 lines · Jan Kara
struct
xfs_attr_leafblockcontains 'entries' array which is declared with size 1 altough it can in fact contain much more entries. Since this array is followed by further struct members, gcc (at least in version 4.8.3) thinks that the array has the fixed size of 1 element and thus may optimize away all accesses beyond the end of array resulting in non-working code. This problem was only observed with userspace code in xfsprogs, however it's better to be safe in kernel as well and have matching kernel and xfsprogs definitions.Signed-off-by Jan Kara <[email protected]>--- fs/xfs/libxfs/xfs_da_format.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)This is a kernel version of the xfsprogs patch I've sent a while ago.
fs/xfs/libxfs/xfs_da_format.h +0
-0
fs/xfs/libxfs/xfs_da_format.h typedef struct xfs_attr_leaf_name_remote { · line 686
Quoted 9 lines
fs/xfs/libxfs/xfs_da_format.h +4
-2@@ -680,8 +680,15 @@ 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_name_local_t namelist; /* grows from bottom of buf */ - xfs_attr_leaf_name_remote_t valuelist; /* grows from bottom of buf */ + /* + * The rest of the block contains the following structures after the + * leaf entries, growing from the bottom up. The variables are never + * referenced and definining them can actually make gcc optimize away
Nitpick, s/definining/defining/, maybe can be fixed on commit :)
Don't we have other similar constructs elsewhere? Do they suffer the same fate?
... looks ...
I guess not; the other ones have the variable length array as the last member.
-Eric
fs/xfs/libxfs/xfs_da_format.h typedef struct xfs_attr_leaf_name_remote { · line 694
Quoted 9 lines
fs/xfs/libxfs/xfs_da_format.h +5
-0+* accesses to the 'entries' array above index 0 so don't do that. +* +* xfs_attr_leaf_name_local_t namelist; +* xfs_attr_leaf_name_remote_t valuelist; +*/ } xfs_attr_leafblock_t;/*
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs