]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_repair: validate inode di_flags field
authorDave Chinner <dchinner@redhat.com>
Tue, 22 Feb 2011 21:47:50 +0000 (08:47 +1100)
committerDave Chinner <david@fromorbit.com>
Tue, 22 Feb 2011 21:47:50 +0000 (08:47 +1100)
xfs-reapir is not validating the di_flags field in the inode for
sanity. Block fuzzing indicates that we are not picking situations
like the RT bit being set on filesystems without realtime devices.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Alex Elder <aelder@sgi.com>
repair/dinode.c

index bf04c6ee544c215c25b89b562871fae7f84917e0..fad15b24a306270abfd3f20b34f394f38624ddf7 100644 (file)
@@ -2530,6 +2530,68 @@ process_dinode_int(xfs_mount_t *mp,
                goto clear_bad_out;
        }
 
+       /*
+        * check that we only have valid flags set, and those that are set make
+        * sense.
+        */
+       if (dinoc->di_flags) {
+               uint16_t flags = be16_to_cpu(dinoc->di_flags);
+
+               if (flags & ~XFS_DIFLAG_ANY) {
+                       do_warn(_("Bad flags set in inode %llu"), lino);
+                       flags &= ~XFS_DIFLAG_ANY;
+               }
+
+               if (flags & (XFS_DIFLAG_REALTIME | XFS_DIFLAG_RTINHERIT)) {
+                       /* need an rt-dev! */
+                       if (!rt_name) {
+                               do_warn(_(
+       "inode %llu has RT flag set but there is no RT device"), lino);
+                               flags &= ~(XFS_DIFLAG_REALTIME |
+                                               XFS_DIFLAG_RTINHERIT);
+                       }
+               }
+               if (flags & XFS_DIFLAG_NEWRTBM_BIT) {
+                       /* must be a rt bitmap inode */
+                       if (lino != mp->m_sb.sb_rbmino) {
+                               do_warn(_("inode %llu not rt bitmap"), lino);
+                               flags &= ~XFS_DIFLAG_NEWRTBM_BIT;
+                       }
+               }
+               if (flags & (XFS_DIFLAG_RTINHERIT |
+                            XFS_DIFLAG_EXTSZINHERIT |
+                            XFS_DIFLAG_PROJINHERIT |
+                            XFS_DIFLAG_NOSYMLINKS)) {
+                       /* must be a directory */
+                       if (di_mode && !S_ISDIR(di_mode)) {
+                               do_warn(_(
+                       "directory flags set on non-directory inode %llu"),
+                                       lino);
+                               flags &= ~(XFS_DIFLAG_RTINHERIT |
+                                               XFS_DIFLAG_EXTSZINHERIT |
+                                               XFS_DIFLAG_PROJINHERIT |
+                                               XFS_DIFLAG_NOSYMLINKS);
+                       }
+               }
+               if (flags & (XFS_DIFLAG_REALTIME | XFS_XFLAG_EXTSIZE)) {
+                       /* must be a file */
+                       if (di_mode && !S_ISREG(di_mode)) {
+                               do_warn(_(
+                       "file flags set on non-file inode %llu"), lino);
+                               flags &= ~(XFS_DIFLAG_REALTIME |
+                                               XFS_XFLAG_EXTSIZE);
+                       }
+               }
+               if (!verify_mode && flags != be16_to_cpu(dinoc->di_flags)) {
+                       if (!no_modify) {
+                               do_warn(_(", fixing bad flags.\n"));
+                               dinoc->di_flags = cpu_to_be16(flags);
+                               *dirty = 1;
+                       } else
+                               do_warn(_(", would fix bad flags.\n"));
+               }
+       }
+
        if (verify_mode)
                return retval;