xfs: check v5 superblock features early
PATCH 1/1 xfs: check v5 superblock features early
When working on a new features that reuses the existing pad in the superblock, I noticed that mounting such a file system on an old kernel logs a rather confusing warning:
XFS (vdc): Metadir superblock padding fields must be zero.
This is because we only validate the various feature fields in v5 superblocks after the common superblock validation helper is called.
Fix this by calling the feature validation first. To make this more obvious, rename xfs_validate_sb_read to xfs_validate_sb_features and only call it for v5 file systems.
--- fs/xfs/libxfs/xfs_sb.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
fs/xfs/libxfs/xfs_sb.c +7 -8
@@ -189,15 +189,12 @@ xfs_sb_version_to_features(return features; } -/* Check all the superblock fields we care about when reading one in. */ +/* Check for compatible v5 superblock features when reading a superblock */ STATIC int -xfs_validate_sb_read ( +xfs_validate_sb_features (struct xfs_mount *mp,struct xfs_sb *sbp) { -if (!xfs_sb_is_v5 (sbp)) -return 0 ; -/* * Version 5 superblock feature mask validation. Reject combinations * the kernel cannot support up front before checking anything else.
@@ -1118,10 +1115,12 @@ xfs_sb_read_verify(* because _verify_common checks the on-disk values. */ __xfs_sb_from_disk (&sb, dsb, false); +if (xfs_sb_is_v5 (&sb)) { + error =xfs_validate_sb_features (mp, &sb); +if (error) + goto out_error; + } error =xfs_validate_sb_common (mp, bp, &sb); -if (error) - goto out_error; - error =xfs_validate_sb_read (mp, &sb); out_error:if (error == -EFSCORRUPTED || error == -EFSBADCRC )
Signature · 1 line
2.53.0
Quoted 4 lines · Christoph Hellwig
When working on a new features that reuses the existing pad in the superblock, I noticed that mounting such a file system on an old kernel logs a rather confusing warning:
Quoted 8 lines
XFS (vdc): Metadir superblock padding fields must be zero.
This is because we only validate the various feature fields in v5 superblocks after the common superblock validation helper is called.
Fix this by calling the feature validation first. To make this more obvious, rename
xfs_validate_sb_readtoxfs_validate_sb_featuresand only call it for v5 file systems.
Shouldn't it be called xfs_validate_v5_sb_features then?
Oh. There's already a xfs_sb_validate_v5_features function that checks that the v4 feature bits are set correctly for a v5 filesystem, and it would be confusing to have both. Could we move the code in xfs_validate_sb_read into xfs_sb_validate_v5_features instead?
If you do that, then xfs_sb_good_version will validate the feature bit recognition, which it doesn't do now. I'm not sure what weird side effects might result from that though.
Quoted 2 lines
Fixes eca383fcd63b ("xfs: refactor superblock verifiers")Signed-off-by Christoph Hellwig <[email protected]>
Quoted 27 lines
--- fs/xfs/libxfs/xfs_sb.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)fs/xfs/libxfs/xfs_sb.c +2
-5@@ -189,15 +189,12 @@ xfs_sb_version_to_features(return features; } -/* Check all the superblock fields we care about when reading one in. */ +/* Check for compatible v5 superblock features when reading a superblock */ STATIC int -xfs_validate_sb_read ( +xfs_validate_sb_features (struct xfs_mount *mp,struct xfs_sb *sbp) { -if (!xfs_sb_is_v5 (sbp)) -return 0 ; -/* * Version 5 superblock feature mask validation. Reject combinations * the kernel cannot support up front before checking anything else.
fs/xfs/libxfs/xfs_sb.c xfs_sb_read_verify( · line 1119
Quoted 5 lines
fs/xfs/libxfs/xfs_sb.c +2
-0@@ -1118,10 +1115,12 @@ xfs_sb_read_verify(* because _verify_common checks the on-disk values. */ __xfs_sb_from_disk (&sb, dsb, false); +if (xfs_sb_is_v5 (&sb)) { + error =xfs_validate_sb_features (mp, &sb);
By putting xfs_validate_sb_features ahead of xfs_validate_sb_common, I think we now validate the V5 feature bits (if the V5 versionnum is set) before checking the superblock magic. Right?
--D
Quoted 14 lines
fs/xfs/libxfs/xfs_sb.c +3
-3+if (error) + goto out_error; + } error =xfs_validate_sb_common (mp, bp, &sb); -if (error) - goto out_error; - error =xfs_validate_sb_read (mp, &sb); out_error:if (error == -EFSCORRUPTED || error == -EFSBADCRC )Signature · 1 line
2.53.0
Quoted 14 lines · Darrick J. Wong
Quoted 4 lines · Christoph Hellwig
When working on a new features that reuses the existing pad in the superblock, I noticed that mounting such a file system on an old kernel logs a rather confusing warning:
Quoted 8 lines
XFS (vdc): Metadir superblock padding fields must be zero.
This is because we only validate the various feature fields in v5 superblocks after the common superblock validation helper is called.
Fix this by calling the feature validation first. To make this more obvious, rename
xfs_validate_sb_readtoxfs_validate_sb_featuresand only call it for v5 file systems.
Quoted 5 lines
Shouldn't it be called
xfs_validate_v5_sb_featuresthen?Oh. There's already a
xfs_sb_validate_v5_featuresfunction that checks that the v4 feature bits are set correctly for a v5 filesystem, and it would be confusing to have both.
Or just stick to the old name :)
Quoted 2 lines
Could we move the code in
xfs_validate_sb_readintoxfs_sb_validate_v5_featuresinstead?
But yes, that does look sensible as well.
Quoted 3 lines
If you do that, then
xfs_sb_good_versionwill validate the feature bit recognition, which it doesn't do now. I'm not sure what weird side effects might result from that though.
None in the kernel, but userspace has a lot more callers that need a careful look.
Quoted 26 lines · Christoph Hellwig
Quoted 14 lines · Darrick J. Wong
Quoted 4 lines · Christoph Hellwig
When working on a new features that reuses the existing pad in the superblock, I noticed that mounting such a file system on an old kernel logs a rather confusing warning:
Quoted 8 lines
XFS (vdc): Metadir superblock padding fields must be zero.
This is because we only validate the various feature fields in v5 superblocks after the common superblock validation helper is called.
Fix this by calling the feature validation first. To make this more obvious, rename
xfs_validate_sb_readtoxfs_validate_sb_featuresand only call it for v5 file systems.Quoted 5 lines
Shouldn't it be called
xfs_validate_v5_sb_featuresthen?Oh. There's already a
xfs_sb_validate_v5_featuresfunction that checks that the v4 feature bits are set correctly for a v5 filesystem, and it would be confusing to have both.Or just stick to the old name :)
Quoted 2 lines
Could we move the code in
xfs_validate_sb_readintoxfs_sb_validate_v5_featuresinstead?
Quoted 8 lines
But yes, that does look sensible as well.
Quoted 3 lines
If you do that, then
xfs_sb_good_versionwill validate the feature bit recognition, which it doesn't do now. I'm not sure what weird side effects might result from that though.None in the kernel, but userspace has a lot more callers that need a careful look.
I /think/ the only visible change to userspace is that the code in repair that checks v5 feature flag recognition now becomes defunct because libxfs_sb_good_version will catch it first. But the xfs_validate_sb_read code will already log (more or less) the same complaint so I don't think it will have any real effect.
--D
Quoted 33 lines · Darrick J. Wong
Quoted 32 lines · Christoph Hellwig
Quoted 14 lines · Darrick J. Wong
Quoted 4 lines · Christoph Hellwig
When working on a new features that reuses the existing pad in the superblock, I noticed that mounting such a file system on an old kernel logs a rather confusing warning:
Quoted 8 lines
XFS (vdc): Metadir superblock padding fields must be zero.
This is because we only validate the various feature fields in v5 superblocks after the common superblock validation helper is called.
Fix this by calling the feature validation first. To make this more obvious, rename
xfs_validate_sb_readtoxfs_validate_sb_featuresand only call it for v5 file systems.Quoted 5 lines
Shouldn't it be called
xfs_validate_v5_sb_featuresthen?Oh. There's already a
xfs_sb_validate_v5_featuresfunction that checks that the v4 feature bits are set correctly for a v5 filesystem, and it would be confusing to have both.Or just stick to the old name :)
Quoted 2 lines
Could we move the code in
xfs_validate_sb_readintoxfs_sb_validate_v5_featuresinstead?But yes, that does look sensible as well.
Quoted 3 lines
If you do that, then
xfs_sb_good_versionwill validate the feature bit recognition, which it doesn't do now. I'm not sure what weird side effects might result from that though.
Quoted 8 lines
Quoted 2 lines
None in the kernel, but userspace has a lot more callers that need a careful look.
I /think/ the only visible change to userspace is that the code in repair that checks v5 feature flag recognition now becomes defunct because
libxfs_sb_good_versionwill catch it first. But thexfs_validate_sb_readcode will already log (more or less) the same complaint so I don't think it will have any real effect.
Yeah. OTOH we now also add it to writes.
I think I'll reduce scope for this patch and drop the renaming and just do the check earlier for a trivial backportable fix.
Then I'll add your above idea to my started work of refactoring the sb verifier for reuse in xfs_repair for the next merge window or whenver I get to it.
Quoted 37 lines · Christoph Hellwig
Quoted 36 lines · Darrick J. Wong
Quoted 34 lines · Christoph Hellwig
Quoted 14 lines · Darrick J. Wong
Quoted 4 lines · Christoph Hellwig
When working on a new features that reuses the existing pad in the superblock, I noticed that mounting such a file system on an old kernel logs a rather confusing warning:
Quoted 8 lines
XFS (vdc): Metadir superblock padding fields must be zero.
This is because we only validate the various feature fields in v5 superblocks after the common superblock validation helper is called.
Fix this by calling the feature validation first. To make this more obvious, rename
xfs_validate_sb_readtoxfs_validate_sb_featuresand only call it for v5 file systems.Quoted 5 lines
Shouldn't it be called
xfs_validate_v5_sb_featuresthen?Oh. There's already a
xfs_sb_validate_v5_featuresfunction that checks that the v4 feature bits are set correctly for a v5 filesystem, and it would be confusing to have both.Or just stick to the old name :)
Quoted 2 lines
Could we move the code in
xfs_validate_sb_readintoxfs_sb_validate_v5_featuresinstead?But yes, that does look sensible as well.
Quoted 3 lines
If you do that, then
xfs_sb_good_versionwill validate the feature bit recognition, which it doesn't do now. I'm not sure what weird side effects might result from that though.None in the kernel, but userspace has a lot more callers that need a careful look.
Quoted 7 lines
Quoted 5 lines
I /think/ the only visible change to userspace is that the code in repair that checks v5 feature flag recognition now becomes defunct because
libxfs_sb_good_versionwill catch it first. But thexfs_validate_sb_readcode will already log (more or less) the same complaint so I don't think it will have any real effect.Yeah. OTOH we now also add it to writes.
<shrug> xfs_validate_sb_write already checks the feature bits, so adding it to the common function is no big deal.
Quoted 6 lines
I think I'll reduce scope for this patch and drop the renaming and just do the check earlier for a trivial backportable fix.
Then I'll add your above idea to my started work of refactoring the sb verifier for reuse in
xfs_repairfor the next merge window or whenver I get to it.
OK.
--D