]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_repair: check inode nsec for obviously garbage values
authorDarrick J. Wong <darrick.wong@oracle.com>
Wed, 23 May 2018 21:30:48 +0000 (16:30 -0500)
committerEric Sandeen <sandeen@redhat.com>
Wed, 23 May 2018 21:30:48 +0000 (16:30 -0500)
It makes no sense to have an nsec value that is larger than 1 second,
so zero the field if this is the case.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
repair/dinode.c

index 58a509b0134862d7a356648982fcb801c6131c42..3728507e6061a36ba5567019eb8ad327c5ba740d 100644 (file)
@@ -2233,6 +2233,28 @@ _("would clear obsolete nlink field in version 2 inode %" PRIu64 ", currently %d
        return dirty;
 }
 
+/* Check nanoseconds of a timestamp don't exceed 1 second. */
+static void
+check_nsec(
+       const char              *name,
+       xfs_ino_t               lino,
+       struct xfs_timestamp    *t,
+       int                     *dirty)
+{
+       if (be32_to_cpu(t->t_nsec) < 1000000000)
+               return;
+
+       do_warn(
+_("Bad %s nsec %u on inode %" PRIu64 ", "), name, be32_to_cpu(t->t_nsec), lino);
+       if (no_modify) {
+               do_warn(_("would reset to zero\n"));
+       } else {
+               do_warn(_("resetting to zero\n"));
+               t->t_nsec = 0;
+               *dirty = 1;
+       }
+}
+
 /*
  * returns 0 if the inode is ok, 1 if the inode is corrupt
  * check_dups can be set to 1 *only* when called by the
@@ -2749,6 +2771,13 @@ _("Cannot have CoW extent size of zero on cowextsize inode %" PRIu64 ", "),
                }
        }
 
+       /* nsec fields cannot be larger than 1 billion */
+       check_nsec("atime", lino, &dino->di_atime, dirty);
+       check_nsec("mtime", lino, &dino->di_mtime, dirty);
+       check_nsec("ctime", lino, &dino->di_ctime, dirty);
+       if (dino->di_version >= 3)
+               check_nsec("crtime", lino, &dino->di_crtime, dirty);
+
        /*
         * general size/consistency checks:
         */