From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
To: <ntfs3@lists.linux.dev>
Cc: <linux-kernel@vger.kernel.org>, <linux-fsdevel@vger.kernel.org>,
<kari.argillander@gmail.com>
Subject: [PATCH v2 2/3] fs/ntfs3: Reject mount if boot's cluster size < media sector size
Date: Tue, 28 Sep 2021 20:18:07 +0300 [thread overview]
Message-ID: <228cbe20-87d6-4020-55fb-111d22e2b487@paragon-software.com> (raw)
In-Reply-To: <a7c2e6d3-68a1-25f7-232e-935ae9e5f6c8@paragon-software.com>
If we continue to work in this case, then we can corrupt fs.
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
---
fs/ntfs3/super.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c
index aff90f70e7bf..890c5d9d6d60 100644
--- a/fs/ntfs3/super.c
+++ b/fs/ntfs3/super.c
@@ -763,9 +763,20 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,
sbi->mft.lbo = mlcn << sbi->cluster_bits;
sbi->mft.lbo2 = mlcn2 << sbi->cluster_bits;
- if (sbi->cluster_size < sbi->sector_size)
+ /* Compare boot's cluster and sector. */
+ if (sbi->cluster_size < boot_sector_size)
goto out;
+ /* Compare boot's cluster and media sector. */
+ if (sbi->cluster_size < sector_size) {
+ /* No way to use ntfs_get_block in this case. */
+ ntfs_err(
+ sb,
+ "Failed to mount 'cause NTFS's cluster size (%u) is less than media sector size (%u)",
+ sbi->cluster_size, sector_size);
+ goto out;
+ }
+
sbi->cluster_mask = sbi->cluster_size - 1;
sbi->cluster_mask_inv = ~(u64)sbi->cluster_mask;
sbi->record_size = record_size = boot->record_size < 0
--
2.33.0
next prev parent reply other threads:[~2021-09-28 17:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-28 17:16 [PATCH v2 0/3] fs/ntfs3: Refactoring of super.c Konstantin Komarov
2021-09-28 17:17 ` [PATCH v2 1/3] fs/ntfs3: Fix memory leak if fill_super failed Konstantin Komarov
2021-09-28 17:44 ` Kari Argillander
2021-09-29 16:55 ` Konstantin Komarov
2021-09-28 17:18 ` Konstantin Komarov [this message]
2021-09-28 18:03 ` [PATCH v2 2/3] fs/ntfs3: Reject mount if boot's cluster size < media sector size Kari Argillander
2021-09-28 17:18 ` [PATCH v2 3/3] fs/ntfs3: Refactoring of ntfs_init_from_boot Konstantin Komarov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=228cbe20-87d6-4020-55fb-111d22e2b487@paragon-software.com \
--to=almaz.alexandrovich@paragon-software.com \
--cc=kari.argillander@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ntfs3@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).