lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <53c3c86f-c816-4747-9262-592c3ddc6660@paragon-software.com>
Date:   Wed, 6 Dec 2023 18:08:56 +0300
From:   Konstantin Komarovc <almaz.alexandrovich@...agon-software.com>
To:     <ntfs3@...ts.linux.dev>
CC:     <linux-kernel@...r.kernel.org>, <linux-fsdevel@...r.kernel.org>
Subject: [PATCH 01/16] fs/ntfs3: Improve alternative boot processing


Signed-off-by: Konstantin Komarov <almaz.alexandrovich@...agon-software.com>
---
  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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ