fs/ntfs3: Mark ntfs dirty when on-disk struct is corrupted
authorKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Mon, 8 May 2023 07:36:28 +0000 (11:36 +0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 23 Aug 2023 15:52:26 +0000 (17:52 +0200)
[ Upstream commit e0f363a98830e8d7d70fbaf91c07ae0b7c57aafe ]

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/ntfs3/fsntfs.c
fs/ntfs3/index.c
fs/ntfs3/ntfs_fs.h
fs/ntfs3/record.c

index b6e22bc..829b62d 100644 (file)
@@ -154,7 +154,7 @@ int ntfs_fix_post_read(struct NTFS_RECORD_HEADER *rhdr, size_t bytes,
        /* Check errors. */
        if ((fo & 1) || fo + fn * sizeof(short) > SECTOR_SIZE || !fn-- ||
            fn * SECTOR_SIZE > bytes) {
-               return -EINVAL; /* Native chkntfs returns ok! */
+               return -E_NTFS_CORRUPT;
        }
 
        /* Get fixup pointer. */
index 9e9a9ff..495cfb3 100644 (file)
@@ -1103,6 +1103,12 @@ ok:
        *node = in;
 
 out:
+       if (err == -E_NTFS_CORRUPT) {
+               ntfs_inode_err(&ni->vfs_inode, "directory corrupted");
+               ntfs_set_state(ni->mi.sbi, NTFS_DIRTY_ERROR);
+               err = -EINVAL;
+       }
+
        if (ib != in->index)
                kfree(ib);
 
index 24227b2..8c9abaf 100644 (file)
@@ -53,6 +53,8 @@ enum utf16_endian;
 #define E_NTFS_NONRESIDENT             556
 /* NTFS specific error code about punch hole. */
 #define E_NTFS_NOTALIGNED              557
+/* NTFS specific error code when on-disk struct is corrupted. */
+#define E_NTFS_CORRUPT                 558
 
 
 /* sbi->flags */
index 07037ec..ba336c7 100644 (file)
@@ -180,6 +180,12 @@ ok:
        return 0;
 
 out:
+       if (err == -E_NTFS_CORRUPT) {
+               ntfs_err(sbi->sb, "mft corrupted");
+               ntfs_set_state(sbi, NTFS_DIRTY_ERROR);
+               err = -EINVAL;
+       }
+
        return err;
 }