xfs: enhance dinode verifier
PATCH 1/1 xfs: enhance dinode verifier
Add several more validations to xfs_dinode_verify:
- For LOCAL data fork formats, di_nextents must be 0.
- For LOCAL attr fork formats, di_anextents must be 0.
- For inodes with no attr fork offset,
- format must be XFS_DINODE_FMT_EXTENTS if set at all
- di_anextents must be 0.
---
fs/xfs/libxfs/xfs_inode_buf.c +15 -0
@@ -458,6 +458,8 @@ xfs_dinode_verify(return __this_address;if (di_size >XFS_DFORK_DSIZE (dip, mp))return __this_address; +if (dip->di_nextents) +return __this_address;/* fall through */ case XFS_DINODE_FMT_EXTENTS :case XFS_DINODE_FMT_BTREE :
@@ -476,12 +478,25 @@ xfs_dinode_verify(if (XFS_DFORK_Q (dip)) {switch (dip->di_aformat) {case XFS_DINODE_FMT_LOCAL : +if (dip->di_anextents) +return __this_address; +/* fall through */ case XFS_DINODE_FMT_EXTENTS :case XFS_DINODE_FMT_BTREE :break ;default :return __this_address; } + }else {/* No attr fork */ +switch (dip->di_aformat) { +case 0 :/* Uninitialized OK */ +case XFS_DINODE_FMT_EXTENTS : +break ; +default : +return __this_address; + } +if (dip->di_anextents) +return __this_address; }/* only version 3 or greater inodes are extensively verified here */
PATCH v2 1/1 xfs: enhance dinode verifier
Add several more validations to xfs_dinode_verify:
- For LOCAL data fork formats, di_nextents must be 0.
- For LOCAL attr fork formats, di_anextents must be 0.
- For inodes with no attr fork offset,
- format must be XFS_DINODE_FMT_EXTENTS if set at all
- di_anextents must be 0.
Thanks to dchinner for pointing out a couple related checks I had forgotten to add.
---
V2: due credit :)
fs/xfs/libxfs/xfs_inode_buf.c +15 -0
@@ -458,6 +458,8 @@ xfs_dinode_verify(return __this_address;if (di_size >XFS_DFORK_DSIZE (dip, mp))return __this_address; +if (dip->di_nextents) +return __this_address;/* fall through */ case XFS_DINODE_FMT_EXTENTS :case XFS_DINODE_FMT_BTREE :
@@ -476,12 +478,25 @@ xfs_dinode_verify(if (XFS_DFORK_Q (dip)) {switch (dip->di_aformat) {case XFS_DINODE_FMT_LOCAL : +if (dip->di_anextents) +return __this_address; +/* fall through */ case XFS_DINODE_FMT_EXTENTS :case XFS_DINODE_FMT_BTREE :break ;default :return __this_address; } + }else {/* No attr fork */ +switch (dip->di_aformat) { +case 0 :/* Uninitialized OK */ +case XFS_DINODE_FMT_EXTENTS : +break ; +default : +return __this_address; + } +if (dip->di_anextents) +return __this_address; }/* only version 3 or greater inodes are extensively verified here */
Quoted 35 lines · Eric Sandeen
Add several more validations to
xfs_dinode_verify:- For LOCAL data fork formats,
di_nextentsmust be 0.
- For LOCAL attr fork formats,di_anextentsmust be 0.
- For inodes with no attr fork offset,
- format must beXFS_DINODE_FMT_EXTENTSif set at all
-di_anextentsmust be 0.Thanks to dchinner for pointing out a couple related checks I had forgotten to add.
Signed-off-by Eric Sandeen <[email protected]>---
V2: due credit :)
fs/xfs/libxfs/xfs_inode_buf.c +4
-0@@ -458,6 +458,8 @@ xfs_dinode_verify(return __this_address;if (di_size >XFS_DFORK_DSIZE (dip, mp))return __this_address; +if (dip->di_nextents) +return __this_address;/* fall through */ case XFS_DINODE_FMT_EXTENTS :case XFS_DINODE_FMT_BTREE :@@ -476,12 +478,25 @@ xfs_dinode_verify(if (XFS_DFORK_Q (dip)) {switch (dip->di_aformat) {case XFS_DINODE_FMT_LOCAL : +if (dip->di_anextents) +return __this_address;
fs/xfs/libxfs/xfs_inode_buf.c xfs_dinode_verify( · line 492
Quoted 10 lines
fs/xfs/libxfs/xfs_inode_buf.c +4
-0+/* fall through */ case XFS_DINODE_FMT_EXTENTS :case XFS_DINODE_FMT_BTREE :break ;default :return __this_address; } + }else {/* No attr fork */ +switch (dip->di_aformat) { +case 0 :/* Uninitialized OK */
Might be a good idea to point out that a newly allocated inode chunk will have all these fields set to zero (as I apparently stumble over this about once every 10-11 months).
Also, uh, does xfs_repair catch these? :D
--D
Quoted 16 lines
fs/xfs/libxfs/xfs_inode_buf.c +7
-1+case XFS_DINODE_FMT_EXTENTS : +break ; +default : +return __this_address; + } +if (dip->di_anextents) +return __this_address; }/* only version 3 or greater inodes are extensively verified here */ --To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 2 lines · Darrick J. Wong
Quoted 1 line · Eric Sandeen
Add several more validations to
xfs_dinode_verify:
...
Quoted 11 lines
Quoted 11 lines
fs/xfs/libxfs/xfs_inode_buf.c +3
-0@@ -476,12 +478,25 @@ xfs_dinode_verify(if (XFS_DFORK_Q (dip)) {switch (dip->di_aformat) {case XFS_DINODE_FMT_LOCAL : +if (dip->di_anextents) +return __this_address; +/* fall through */ case XFS_DINODE_FMT_EXTENTS :case XFS_DINODE_FMT_BTREE :break ;default :
Quoted 8 lines
fs/xfs/libxfs/xfs_inode_buf.c xfs_dinode_verify( · line 492
Quoted 5 lines
fs/xfs/libxfs/xfs_inode_buf.c +3
-0return __this_address; } + }else {/* No attr fork */ +switch (dip->di_aformat) { +case 0 :/* Uninitialized OK */ Might be a good idea to point out that a newly allocated inode chunk will have all these fields set to zero
Well, that was the intent of my terse comment... I can write a longer one, clearly it did not do the trick?
-Eric
PATCH v3 1/1 xfs: enhance dinode verifier
In reply to Eric SandeenAdd several more validations to xfs_dinode_verify:
- For LOCAL data fork formats, di_nextents must be 0.
- For LOCAL attr fork formats, di_anextents must be 0.
- For inodes with no attr fork offset,
- format must be XFS_DINODE_FMT_EXTENTS if set at all
- di_anextents must be 0.
Thanks to dchinner for pointing out a couple related checks I had forgotten to add.
---
V2: due credit
V3: clarify the no-offset / no-format cases in a comment
fs/xfs/libxfs/xfs_inode_buf.c +21 -0
@@ -466,6 +466,8 @@return __this_address;if (di_size >XFS_DFORK_DSIZE (dip, mp))return __this_address; +if (dip->di_nextents) +return __this_address;/* fall through */ case XFS_DINODE_FMT_EXTENTS :case XFS_DINODE_FMT_BTREE :
@@ -484,12 +486,31 @@if (XFS_DFORK_Q (dip)) {switch (dip->di_aformat) {case XFS_DINODE_FMT_LOCAL : +if (dip->di_anextents) +return __this_address; +/* fall through */ case XFS_DINODE_FMT_EXTENTS :case XFS_DINODE_FMT_BTREE :break ;default :return __this_address; } + }else { +/* +* If there is no fork offset, this may be a freshly-made inode +* in a new disk cluster, in which case di_aformat is zeroed. +* Otherwise, such an inode must be in EXTENTS format; this goes +* for freed inodes as well. +*/ +switch (dip->di_aformat) { +case 0 : +case XFS_DINODE_FMT_EXTENTS : +break ; +default : +return __this_address; + } +if (dip->di_anextents) +return __this_address; }/* only version 3 or greater inodes are extensively verified here */
Quoted 8 lines · Eric Sandeen
Add several more validations to
xfs_dinode_verify:- For LOCAL data fork formats,
di_nextentsmust be 0.
- For LOCAL attr fork formats,di_anextentsmust be 0.
- For inodes with no attr fork offset,
- format must beXFS_DINODE_FMT_EXTENTSif set at all
-di_anextentsmust be 0.
Quoted 4 lines
Thanks to dchinner for pointing out a couple related checks I had forgotten to add.
Signed-off-by Eric Sandeen <[email protected]>
Looks ok, will try to figure out what the online repair ramifications are...
--D
Quoted 55 lines
---
V2: due credit
V3: clarify the no-offset / no-format cases in a commentfs/xfs/libxfs/xfs_inode_buf.c +21
-1@@ -466,6 +466,8 @@return __this_address;if (di_size >XFS_DFORK_DSIZE (dip, mp))return __this_address; +if (dip->di_nextents) +return __this_address;/* fall through */ case XFS_DINODE_FMT_EXTENTS :case XFS_DINODE_FMT_BTREE :@@ -484,12 +486,31 @@if (XFS_DFORK_Q (dip)) {switch (dip->di_aformat) {case XFS_DINODE_FMT_LOCAL : +if (dip->di_anextents) +return __this_address; +/* fall through */ case XFS_DINODE_FMT_EXTENTS :case XFS_DINODE_FMT_BTREE :break ;default :return __this_address; } + }else { +/* +* If there is no fork offset, this may be a freshly-made inode +* in a new disk cluster, in which case di_aformat is zeroed. +* Otherwise, such an inode must be in EXTENTS format; this goes +* for freed inodes as well. +*/ +switch (dip->di_aformat) { +case 0 : +case XFS_DINODE_FMT_EXTENTS : +break ; +default : +return __this_address; + } +if (dip->di_anextents) +return __this_address; }/* only version 3 or greater inodes are extensively verified here */ --To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 10 lines · Eric Sandeen
Add several more validations to
xfs_dinode_verify:- For LOCAL data fork formats,
di_nextentsmust be 0.
- For LOCAL attr fork formats,di_anextentsmust be 0.
- For inodes with no attr fork offset,
- format must beXFS_DINODE_FMT_EXTENTSif set at all
-di_anextentsmust be 0.Thanks to dchinner for pointing out a couple related checks I had forgotten to add.
Darrick, maybe also add:
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=199377
If you still can
-Eric
Quoted 57 lines
Signed-off-by Eric Sandeen <[email protected]>---
V2: due credit
V3: clarify the no-offset / no-format cases in a commentfs/xfs/libxfs/xfs_inode_buf.c +21
-1@@ -466,6 +466,8 @@return __this_address;if (di_size >XFS_DFORK_DSIZE (dip, mp))return __this_address; +if (dip->di_nextents) +return __this_address;/* fall through */ case XFS_DINODE_FMT_EXTENTS :case XFS_DINODE_FMT_BTREE :@@ -484,12 +486,31 @@if (XFS_DFORK_Q (dip)) {switch (dip->di_aformat) {case XFS_DINODE_FMT_LOCAL : +if (dip->di_anextents) +return __this_address; +/* fall through */ case XFS_DINODE_FMT_EXTENTS :case XFS_DINODE_FMT_BTREE :break ;default :return __this_address; } + }else { +/* +* If there is no fork offset, this may be a freshly-made inode +* in a new disk cluster, in which case di_aformat is zeroed. +* Otherwise, such an inode must be in EXTENTS format; this goes +* for freed inodes as well. +*/ +switch (dip->di_aformat) { +case 0 : +case XFS_DINODE_FMT_EXTENTS : +break ; +default : +return __this_address; + } +if (dip->di_anextents) +return __this_address; }/* only version 3 or greater inodes are extensively verified here */ --To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html