fs/ntfs3: accept $Bad covering the last partial cluster
Subsystems (2)
PATCH 1/1 fs/ntfs3: accept $Bad covering the last partial cluster
From: Zhan Xusheng <[email protected]>
ntfs3 refuses a volume that Windows, chkdsk and the ntfs driver accept:
ntfs3: ino=8, mi_enum_attr
ntfs3: Mark volume as dirty due to NTFS errors
ntfs3: Failed to load $BadClus (-22)
The volume has 64 KiB clusters and 7337721855 sectors of 512 bytes, one sector short of a cluster multiple, so sbi->used.bitmap.nbits is 57325951. Its $BadClus:$Bad covers 57325952 clusters: evcn is 57325951 and alloc_size is 512 bytes over sbi->volume.size. mi_enum_attr() rejects both values.
To reproduce, run mkntfs -c 65536 on a 256 MiB image (524287 sectors, 4095 whole clusters), then extend the $Bad run to 4096 clusters and set evcn, alloc_size and data_size to match, in both $MFT and $MFTMirr. ntfsfix accepts the image; ntfs3 does not mount it.
Compare alloc_size and evcn with the volume size rounded up to a whole cluster. run_unpack() still checks real LCNs against nbits, so only a sparse run can reach the extra cluster.
---
Tested in a VM on 7.4-rc3 (20eef29b7c84) with images forged as above, 64K and 4K clusters: before, mount fails with -EINVAL; after, mount, write, fill to ENOSPC and remount work, and ntfsfix -n stays clean. An image whose $Bad extends one cluster further is still rejected.
fs/ntfs3/record.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
fs/ntfs3/record.c +8 -6
@@ -317,10 +317,10 @@ struct ATTRIB *mi_enum_attr(struct ntfs_inode *ni, struct mft_inode *mi,* since "(u64)-1 + 1" is 0 and "0 > 0" is false. * * For a non-empty attribute evcn is a cluster index and must lie -* within the volume (sbi->used.bitmap.nbits, set up in -* ntfs_init_from_boot() before any caller of mi_enum_attr() runs). -* Bounding evcn also prevents a malformed value close to U64_MAX -* from slipping through the near-wrap "evcn + 1" upper bound. +* within the volume rounded up to a whole cluster: $BadClus:$Bad +* may cover the partial cluster at the end. Bounding evcn also +* prevents a malformed value close to U64_MAX from slipping through +* the near-wrap "evcn + 1" upper bound. */ svcn =le64_to_cpu (attr->nres.svcn); evcn =le64_to_cpu (attr->nres.evcn);
@@ -338,7 +338,9 @@ struct ATTRIB *mi_enum_attr(struct ntfs_inode *ni, struct mft_inode *mi,#endif }else {/* Check out of volume for normal attribute. */ -if (evcn !=U64_MAX && evcn >= mi->sbi->used.bitmap.nbits) +if (evcn !=U64_MAX && + evcn >=ntfs_up_cluster (mi->sbi, mi->sbi->volume.size) >> + mi->sbi->cluster_bits) goto out; }
@@ -370,7 +372,7 @@ struct ATTRIB *mi_enum_attr(struct ntfs_inode *ni, struct mft_inode *mi,if (attr->nres.c_unit) goto out; -if (alloc_size > mi->sbi->volume.size) +if (alloc_size >ntfs_up_cluster (mi->sbi, mi->sbi->volume.size)) goto out; }
base-commit: 20eef29b7c8465ac98d7dd6d6f2ac07a8d8056ca
Signature · 1 line
2.43.0