2023-12-06 15:25:18

by Konstantin Komarov

[permalink] [raw]
Subject: [PATCH 00/16] fs/ntfs3: Bugfix and refactoring

This series contains various fixes and refactoring for ntfs3.
Improved alternative boot processing, reduced stack usage.

Konstantin Komarov (16):
  fs/ntfs3: Improve alternative boot processing
  fs/ntfs3: Modified fix directory element type detection
  fs/ntfs3: Improve ntfs_dir_count
  fs/ntfs3: Correct hard links updating when dealing with DOS names
  fs/ntfs3: Print warning while fixing hard links count
  fs/ntfs3: Reduce stack usage
  fs/ntfs3: Fix multithreaded stress test
  fs/ntfs3: Fix detected field-spanning write (size 8) of single field
    "le->name"
  fs/ntfs3: Correct use bh_read
  fs/ntfs3: Add file_modified
  fs/ntfs3: Drop suid and sgid bits as a part of fpunch
  fs/ntfs3: Implement super_operations::shutdown
  fs/ntfs3: ntfs3_forced_shutdown use int instead of bool
  fs/ntfs3: Add and fix comments
  fs/ntfs3: Add NULL ptr dereference checking at the end of
    attr_allocate_frame()
  fs/ntfs3: Fix c/mtime typo

 fs/ntfs3/attrib.c  |  41 +++++----
 fs/ntfs3/dir.c     |  44 ++++++---
 fs/ntfs3/file.c    |  59 +++++++++---
 fs/ntfs3/frecord.c |   5 +-
 fs/ntfs3/fslog.c   | 218 ++++++++++++++++++++-------------------------
 fs/ntfs3/fsntfs.c  |   5 +-
 fs/ntfs3/inode.c   |  30 +++++--
 fs/ntfs3/namei.c   |  12 +++
 fs/ntfs3/ntfs.h    |   2 +-
 fs/ntfs3/ntfs_fs.h |  11 ++-
 fs/ntfs3/record.c  |  16 +++-
 fs/ntfs3/super.c   |  47 ++++++----
 fs/ntfs3/xattr.c   |   3 +
 13 files changed, 302 insertions(+), 191 deletions(-)

--
2.34.1


2023-12-06 15:25:30

by Konstantin Komarov

[permalink] [raw]
Subject: [PATCH 16/16] fs/ntfs3: Fix c/mtime typo


Signed-off-by: Konstantin Komarov <[email protected]>
---
 fs/ntfs3/frecord.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ntfs3/frecord.c b/fs/ntfs3/frecord.c
index 8744ba36d422..6ff4f70ba077 100644
--- a/fs/ntfs3/frecord.c
+++ b/fs/ntfs3/frecord.c
@@ -3291,7 +3291,7 @@ int ni_write_inode(struct inode *inode, int sync,
const char *hint)
             modified = true;
         }

-        ts = inode_get_mtime(inode);
+        ts = inode_get_ctime(inode);
         dup.c_time = kernel2nt(&ts);
         if (std->c_time != dup.c_time) {
             std->c_time = dup.c_time;
--
2.34.1

2023-12-06 15:25:30

by Konstantin Komarov

[permalink] [raw]
Subject: [PATCH 01/16] fs/ntfs3: Improve alternative boot processing


Signed-off-by: Konstantin Komarov <[email protected]>
---
 fs/ntfs3/super.c | 35 +++++++++++++++++------------------
 1 file changed, 17 insertions(+), 18 deletions(-)

diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c
index 9153dffde950..09d61c6c90aa 100644
--- a/fs/ntfs3/super.c
+++ b/fs/ntfs3/super.c
@@ -866,6 +866,7 @@ static int ntfs_init_from_boot(struct super_block
*sb, u32 sector_size,
     u16 fn, ao;
     u8 cluster_bits;
     u32 boot_off = 0;
+    sector_t boot_block = 0;
     const char *hint = "Primary boot";

     /* Save original dev_size. Used with alternative boot. */
@@ -873,11 +874,11 @@ static int ntfs_init_from_boot(struct super_block
*sb, u32 sector_size,

     sbi->volume.blocks = dev_size >> PAGE_SHIFT;

-    bh = ntfs_bread(sb, 0);
+read_boot:
+    bh = ntfs_bread(sb, boot_block);
     if (!bh)
-        return -EIO;
+        return boot_block ? -EINVAL : -EIO;

-check_boot:
     err = -EINVAL;

     /* Corrupted image; do not read OOB */
@@ -1108,26 +1109,24 @@ static int ntfs_init_from_boot(struct
super_block *sb, u32 sector_size,
     }

 out:
-    if (err == -EINVAL && !bh->b_blocknr && dev_size0 > PAGE_SHIFT) {
+    brelse(bh);
+
+    if (err == -EINVAL && !boot_block && dev_size0 > PAGE_SHIFT) {
         u32 block_size = min_t(u32, sector_size, PAGE_SIZE);
         u64 lbo = dev_size0 - sizeof(*boot);

-        /*
-          * Try alternative boot (last sector)
-         */
-        brelse(bh);
-
-        sb_set_blocksize(sb, block_size);
-        bh = ntfs_bread(sb, lbo >> blksize_bits(block_size));
-        if (!bh)
-            return -EINVAL;
-
+        boot_block = lbo >> blksize_bits(block_size);
         boot_off = lbo & (block_size - 1);
-        hint = "Alternative boot";
-        dev_size = dev_size0; /* restore original size. */
-        goto check_boot;
+        if (boot_block && block_size >= boot_off + sizeof(*boot)) {
+            /*
+             * Try alternative boot (last sector)
+             */
+            sb_set_blocksize(sb, block_size);
+            hint = "Alternative boot";
+            dev_size = dev_size0; /* restore original size. */
+            goto read_boot;
+        }
     }
-    brelse(bh);

     return err;
 }
--
2.34.1

2023-12-06 15:25:48

by Konstantin Komarov

[permalink] [raw]
Subject: [PATCH 15/16] fs/ntfs3: Add NULL ptr dereference checking at the end of attr_allocate_frame()

It is preferable to exit through the out: label because
internal debugging functions are located there.

Signed-off-by: Konstantin Komarov <[email protected]>
---
 fs/ntfs3/attrib.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/fs/ntfs3/attrib.c b/fs/ntfs3/attrib.c
index 4b78b669a3bd..646e2dad1b75 100644
--- a/fs/ntfs3/attrib.c
+++ b/fs/ntfs3/attrib.c
@@ -1743,8 +1743,10 @@ int attr_allocate_frame(struct ntfs_inode *ni,
CLST frame, size_t compr_size,
             le_b = NULL;
             attr_b = ni_find_attr(ni, NULL, &le_b, ATTR_DATA, NULL,
                           0, NULL, &mi_b);
-            if (!attr_b)
-                return -ENOENT;
+            if (!attr_b) {
+                err = -ENOENT;
+                goto out;
+            }

             attr = attr_b;
             le = le_b;
@@ -1825,13 +1827,15 @@ int attr_allocate_frame(struct ntfs_inode *ni,
CLST frame, size_t compr_size,
 ok:
     run_truncate_around(run, vcn);
 out:
-    if (new_valid > data_size)
-        new_valid = data_size;
+    if (attr_b) {
+        if (new_valid > data_size)
+            new_valid = data_size;

-    valid_size = le64_to_cpu(attr_b->nres.valid_size);
-    if (new_valid != valid_size) {
-        attr_b->nres.valid_size = cpu_to_le64(valid_size);
-        mi_b->dirty = true;
+        valid_size = le64_to_cpu(attr_b->nres.valid_size);
+        if (new_valid != valid_size) {
+            attr_b->nres.valid_size = cpu_to_le64(valid_size);
+            mi_b->dirty = true;
+        }
     }

     return err;
--
2.34.1