Skip to content

Commit ea59d9d

Browse files
deepanshu406gregkh
authored andcommitted
fs/ntfs3: fix missing run load for vcn0 in attr_data_get_block_locked()
[ Upstream commit d7ea849 ] When a compressed or sparse attribute has its clusters frame-aligned, vcn is rounded down to the frame start using cmask, which can result in vcn != vcn0. In this case, vcn and vcn0 may reside in different attribute segments. The code already handles the case where vcn is in a different segment by loading its runs before allocation. However, it fails to load runs for vcn0 when vcn0 resides in a different segment than vcn. This causes run_lookup_entry() to return SPARSE_LCN for vcn0 since its segment was never loaded into the in-memory run list, triggering the WARN_ON(1). Fix this by adding a missing check for vcn0 after the existing vcn segment check. If vcn0 falls outside the current segment range [svcn, evcn1), find and load the attribute segment containing vcn0 before performing the run lookup. The following scenario triggers the bug: attr_data_get_block_locked() vcn = vcn0 & cmask <- vcn != vcn0 after frame alignment load runs for vcn segment <- vcn0 segment not loaded! attr_allocate_clusters() <- allocation succeeds run_lookup_entry(vcn0) <- vcn0 not in run -> SPARSE_LCN WARN_ON(1) <- bug fires here! Reported-by: syzbot+c1e9aedbd913fadad617@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=c1e9aedbd913fadad617 Fixes: c380b52 ("fs/ntfs3: Change new sparse cluster processing") Signed-off-by: Deepanshu Kartikey <Kartikey406@gmail.com> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 3ca13af commit ea59d9d

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

fs/ntfs3/attrib.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,20 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn,
10451045
if (err)
10461046
goto out;
10471047
}
1048+
1049+
if (vcn0 < svcn || evcn1 <= vcn0) {
1050+
struct ATTRIB *attr2;
1051+
1052+
attr2 = ni_find_attr(ni, attr_b, &le_b, ATTR_DATA, NULL,
1053+
0, &vcn0, &mi);
1054+
if (!attr2) {
1055+
err = -EINVAL;
1056+
goto out;
1057+
}
1058+
err = attr_load_runs(attr2, ni, run, NULL);
1059+
if (err)
1060+
goto out;
1061+
}
10481062
}
10491063

10501064
if (vcn + to_alloc > asize)

0 commit comments

Comments
 (0)