Skip to contentSkip to conversation

xfs: don't treat unknown di_flags[2] as corruption in scrub

PATCH In review Eric Sandeen 4 participants 7 messages Sep 18, 2018 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: don't treat unknown di_flags[2] as corruption in scrub

xchk_inode_flags[2]() currently treats any di_flags[2] values that the running kernel doesn't recognize as corruption, and calls xchk_ino_set_corrupt() if they are set. However, it's entirely possible that these flags were set in some newer kernel and are quite valid, but ignored in this kernel.

(Validators don't care one bit about unknown di_flags[2].)

Call xchk_ino_set_warning instead, because this may or may not actually indicate a problem.

---

fs/xfs/scrub/inode.c +4 -2
index 5b3b177..e53ed83 100644
@@ -126,8 +126,9 @@
 {
 	struct xfs_mount	*mp = sc->mp;
 
+	/* Unknown di_flags could simply be from newer kernel */
 	if (flags & ~XFS_DIFLAG_ANY)
-		goto bad;
+		xchk_ino_set_warning(sc, ino);
 
 	/* rt flags require rt device */
 	if ((flags & (XFS_DIFLAG_REALTIME | XFS_DIFLAG_RTINHERIT)) &&
@@ -172,8 +173,9 @@
 {
 	struct xfs_mount	*mp = sc->mp;
 
+	/* Unknown di_flags2 could simply be from newer kernel */
 	if (flags2 & ~XFS_DIFLAG2_ANY)
-		goto bad;
+		xchk_ino_set_warning(sc, ino);
 
 	/* reflink flag requires reflink feature */
 	if ((flags2 & XFS_DIFLAG2_REFLINK) &&
Reviewed-by on v1 1/1
#1 lore raw

fs/xfs/scrub/inode.c

Quoted 19 lines · Eric Sandeen

xchk_inode_flags[2]() currently treats any di_flags[2] values that the running kernel doesn't recognize as corruption, and calls xchk_ino_set_corrupt() if they are set. However, it's entirely possible that these flags were set in some newer kernel and are quite valid, but ignored in this kernel.

(Validators don't care one bit about unknown di_flags[2].)

Call xchk_ino_set_warning instead, because this may or may not actually indicate a problem.

---

fs/xfs/scrub/inode.c +0 -0
index 5b3b177..e53ed83 100644
@@ -126,8 +126,9 @@

Would be nice to know which function this is, but it otherwise seems fine to me:

--D

Quoted 22 lines
fs/xfs/scrub/inode.c +4 -2
 {
 	struct xfs_mount	*mp = sc->mp;
 
+	/* Unknown di_flags could simply be from newer kernel */
 	if (flags & ~XFS_DIFLAG_ANY)
-		goto bad;
+		xchk_ino_set_warning(sc, ino);
 
 	/* rt flags require rt device */
 	if ((flags & (XFS_DIFLAG_REALTIME | XFS_DIFLAG_RTINHERIT)) &&
@@ -172,8 +173,9 @@
 {
 	struct xfs_mount	*mp = sc->mp;
 
+	/* Unknown di_flags2 could simply be from newer kernel */
 	if (flags2 & ~XFS_DIFLAG2_ANY)
-		goto bad;
+		xchk_ino_set_warning(sc, ino);
 
 	/* reflink flag requires reflink feature */
 	if ((flags2 & XFS_DIFLAG2_REFLINK) &&
#2 lore raw
In reply to Eric Sandeen
Quoted 19 lines · Eric Sandeen

xchk_inode_flags[2]() currently treats any di_flags[2] values that the running kernel doesn't recognize as corruption, and calls xchk_ino_set_corrupt() if they are set. However, it's entirely possible that these flags were set in some newer kernel and are quite valid, but ignored in this kernel.

(Validators don't care one bit about unknown di_flags[2].)

Call xchk_ino_set_warning instead, because this may or may not actually indicate a problem.

---

fs/xfs/scrub/inode.c +0 -0
index 5b3b177..e53ed83 100644

fs/xfs/scrub/inode.c line 131

Quoted 7 lines
fs/xfs/scrub/inode.c +2 -1
@@ -126,8 +126,9 @@
 {
 	struct xfs_mount	*mp = sc->mp;
 
+	/* Unknown di_flags could simply be from newer kernel */
 	if (flags & ~XFS_DIFLAG_ANY)
-		goto bad;
+		xchk_ino_set_warning(sc, ino);

There's only one flag in that set, right? And we only need that flag for a future v2 inode features we add? i.e. any new feature will be on a v3 inode format because the v2 format is the legacy inode format and we're not developing new features for it.

[ There's also the minor issue that the remaining flag bit in di_flags is reserved for the "more flags" flag bit so that we know to grab flags from some other padding in the inode we redefined to hold more flags in the v2 inode format. But that's irrelevant now because it's a legacy format. ]

IOWs, I think the original code here is just fine because we're not going to add new v2 format inode features in the future.

fs/xfs/scrub/inode.c line 178

Quoted 11 lines
fs/xfs/scrub/inode.c +2 -1
 	/* rt flags require rt device */
 	if ((flags & (XFS_DIFLAG_REALTIME | XFS_DIFLAG_RTINHERIT)) &&
@@ -172,8 +173,9 @@
 {
 	struct xfs_mount	*mp = sc->mp;
 
+	/* Unknown di_flags2 could simply be from newer kernel */
 	if (flags2 & ~XFS_DIFLAG2_ANY)
-		goto bad;
+		xchk_ino_set_warning(sc, ino);

This bit it fine, though :)

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#3 lore raw
Quoted 23 lines · Dave Chinner
Quoted 22 lines · Eric Sandeen

xchk_inode_flags[2]() currently treats any di_flags[2] values that the running kernel doesn't recognize as corruption, and calls xchk_ino_set_corrupt() if they are set. However, it's entirely possible that these flags were set in some newer kernel and are quite valid, but ignored in this kernel.

(Validators don't care one bit about unknown di_flags[2].)

Call xchk_ino_set_warning instead, because this may or may not actually indicate a problem.

---

fs/xfs/scrub/inode.c +0 -0
index 5b3b177..e53ed83 100644
@@ -126,8 +126,9 @@
 {
 	struct xfs_mount	*mp = sc->mp;
 
Quoted 6 lines

fs/xfs/scrub/inode.c line 131

Quoted 4 lines
fs/xfs/scrub/inode.c +2 -1
+	/* Unknown di_flags could simply be from newer kernel */
 	if (flags & ~XFS_DIFLAG_ANY)
-		goto bad;
+		xchk_ino_set_warning(sc, ino);

There's only one flag in that set, right?

Yes, (1 << 15).

Quoted 4 lines

And we only need that flag
for a future v2 inode features we add? i.e. any new feature will be on a v3 inode format because the v2 format is the legacy inode format and we're not developing new features for it.

Ok...

Quoted 8 lines

[ There's also the minor issue that the remaining flag bit in di_flags is reserved for the "more flags" flag bit so that we know to grab flags from some other padding in the inode we redefined to hold more flags in the v2 inode format. But that's irrelevant now because it's a legacy format. ]

IOWs, I think the original code here is just fine because we're not going to add new v2 format inode features in the future.

Ok, if we're absolutely 100% sure that no future kernel will ever use that flag, then yes, it's corruption if it's ever found to be set. I wasn't quite ready to draw that line in the sand.

Should probably #define a new XFS_DIFLAG_NEVER or something then, to make it crystal clear?

-Eric

#4 lore raw
Quoted 49 lines · Eric Sandeen
Quoted 23 lines · Dave Chinner
Quoted 22 lines · Eric Sandeen

xchk_inode_flags[2]() currently treats any di_flags[2] values that the running kernel doesn't recognize as corruption, and calls xchk_ino_set_corrupt() if they are set. However, it's entirely possible that these flags were set in some newer kernel and are quite valid, but ignored in this kernel.

(Validators don't care one bit about unknown di_flags[2].)

Call xchk_ino_set_warning instead, because this may or may not actually indicate a problem.

---

fs/xfs/scrub/inode.c +0 -0
index 5b3b177..e53ed83 100644
@@ -126,8 +126,9 @@
 {
 	struct xfs_mount	*mp = sc->mp;
 
Quoted 6 lines

fs/xfs/scrub/inode.c line 131

Quoted 4 lines
fs/xfs/scrub/inode.c +2 -1
+	/* Unknown di_flags could simply be from newer kernel */
 	if (flags & ~XFS_DIFLAG_ANY)
-		goto bad;
+		xchk_ino_set_warning(sc, ino);

There's only one flag in that set, right?

Yes, (1 << 15).

Quoted 4 lines

And we only need that flag
for a future v2 inode features we add? i.e. any new feature will be on a v3 inode format because the v2 format is the legacy inode format and we're not developing new features for it.

Ok...

Quoted 8 lines

[ There's also the minor issue that the remaining flag bit in di_flags is reserved for the "more flags" flag bit so that we know to grab flags from some other padding in the inode we redefined to hold more flags in the v2 inode format. But that's irrelevant now because it's a legacy format. ]

IOWs, I think the original code here is just fine because we're not going to add new v2 format inode features in the future.

Quoted 6 lines

Ok, if we're absolutely 100% sure that no future kernel will ever use that flag, then yes, it's corruption if it's ever found to be set. I wasn't quite ready to draw that line in the sand.

Should probably #define a new XFS_DIFLAG_NEVER or something then, to make it crystal clear?

Perhaps so. Don't really care one way or the other.

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#5 lore raw

PATCH v2 1/1 xfs: don't treat unknown di_flags2 as corruption in scrub

In reply to Eric Sandeen

xchk_inode_flags2() currently treats any di_flags2 values that the running kernel doesn't recognize as corruption, and calls xchk_ino_set_corrupt() if they are set. However, it's entirely possible that these flags were set in some newer kernel and are quite valid, but ignored in this kernel.

(Validators don't care one bit about unknown di_flags2.)

Call xchk_ino_set_warning instead, because this may or may not actually indicate a problem.

---

V2: continue to treat unknown di_flag value as corruption, and add
comments about how the last di_flag bit cannot be used.

fs/xfs/libxfs/xfs_format.h +2 -0
index 059bc44c27e8..afbe336600e1 100644
@@ -1016,6 +1016,8 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)
 #define XFS_DIFLAG_EXTSZINHERIT_BIT 12	/* inherit inode extent size */
 #define XFS_DIFLAG_NODEFRAG_BIT     13	/* do not reorganize/defragment */
 #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
+/* Do not use bit 15, di_flags is legacy and unchanging now */
+
 #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
 #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
 #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
fs/xfs/scrub/inode.c +3 -1
index 5b3b177c0fc9..8fb29540af45 100644
@@ -126,6 +126,7 @@ xchk_inode_flags(
 {
 	struct xfs_mount	*mp = sc->mp;
 
+	/* di_flags are all taken, last bit cannot be used */
 	if (flags & ~XFS_DIFLAG_ANY)
 		goto bad;
 
@@ -172,8 +173,9 @@ xchk_inode_flags2(
 {
 	struct xfs_mount	*mp = sc->mp;
 
+	/* Unknown di_flags2 could be from a future kernel */
 	if (flags2 & ~XFS_DIFLAG2_ANY)
-		goto bad;
+		xchk_ino_set_warning(sc, ino);
 
 	/* reflink flag requires reflink feature */
 	if ((flags2 & XFS_DIFLAG2_REFLINK) &&
Reviewed-by on v2 1/1
#6 lore raw

Re: [PATCH V2] xfs: don't treat unknown di_flags2 as corruption in scrub

Quoted 6 lines · Eric Sandeen

xchk_inode_flags2() currently treats any di_flags2 values that the running kernel doesn't recognize as corruption, and calls xchk_ino_set_corrupt() if they are set. However, it's entirely possible that these flags were set in some newer kernel and are quite valid, but ignored in this kernel.

Quoted 6 lines

(Validators don't care one bit about unknown di_flags2.)

Call xchk_ino_set_warning instead, because this may or may not actually indicate a problem.

Looks ok,

--D

Quoted 42 lines

---

V2: continue to treat unknown di_flag value as corruption, and add
comments about how the last di_flag bit cannot be used.

fs/xfs/libxfs/xfs_format.h +2 -0
index 059bc44c27e8..afbe336600e1 100644
@@ -1016,6 +1016,8 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)
 #define XFS_DIFLAG_EXTSZINHERIT_BIT 12	/* inherit inode extent size */
 #define XFS_DIFLAG_NODEFRAG_BIT     13	/* do not reorganize/defragment */
 #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
+/* Do not use bit 15, di_flags is legacy and unchanging now */
+
 #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
 #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
 #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
fs/xfs/scrub/inode.c +3 -1
index 5b3b177c0fc9..8fb29540af45 100644
@@ -126,6 +126,7 @@ xchk_inode_flags(
 {
 	struct xfs_mount	*mp = sc->mp;
 
+	/* di_flags are all taken, last bit cannot be used */
 	if (flags & ~XFS_DIFLAG_ANY)
 		goto bad;
 
@@ -172,8 +173,9 @@ xchk_inode_flags2(
 {
 	struct xfs_mount	*mp = sc->mp;
 
+	/* Unknown di_flags2 could be from a future kernel */
 	if (flags2 & ~XFS_DIFLAG2_ANY)
-		goto bad;
+		xchk_ino_set_warning(sc, ino);
 
 	/* reflink flag requires reflink feature */
 	if ((flags2 & XFS_DIFLAG2_REFLINK) &&