Skip to content

Commit 2983d1b

Browse files
NTFS: Fix several bugs in fs/ntfs/attrib.c.
- Fix a bug in ntfs_map_runlist_nolock() where we forgot to protect access to the allocated size in the ntfs inode with the size lock. - Fix ntfs_attr_vcn_to_lcn_nolock() and ntfs_attr_find_vcn_nolock() to return LCN_ENOENT when there is no runlist and the allocated size is zero. - Fix load_attribute_list() to handle the case of a NULL runlist. Signed-off-by: Anton Altaparmakov <aia21@cantab.net>
1 parent 0aaccea commit 2983d1b

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

‎fs/ntfs/ChangeLog‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ ToDo/Notes:
6060
the index context. Thanks to Yura Pakhuchiy for finding this bug.
6161
- Remove bogus setting of PageError in ntfs_read_compressed_block().
6262
- Add fs/ntfs/attrib.[hc]::ntfs_resident_attr_value_resize().
63+
- Fix a bug in ntfs_map_runlist_nolock() where we forgot to protect
64+
access to the allocated size in the ntfs inode with the size lock.
65+
- Fix ntfs_attr_vcn_to_lcn_nolock() and ntfs_attr_find_vcn_nolock() to
66+
return LCN_ENOENT when there is no runlist and the allocated size is
67+
zero.
68+
- Fix load_attribute_list() to handle the case of a NULL runlist.
6369

6470
2.1.23 - Implement extension of resident files and make writing safe as well as
6571
many bug fixes, cleanups, and enhancements...

‎fs/ntfs/attrib.c‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
* which is not an error as such. This is -ENOENT. It means that @vcn is out
4444
* of bounds of the runlist.
4545
*
46+
* Note the runlist can be NULL after this function returns if @vcn is zero and
47+
* the attribute has zero allocated size, i.e. there simply is no runlist.
48+
*
4649
* Locking: - The runlist must be locked for writing.
4750
* - This function modifies the runlist.
4851
*/
@@ -54,6 +57,7 @@ int ntfs_map_runlist_nolock(ntfs_inode *ni, VCN vcn)
5457
ATTR_RECORD *a;
5558
ntfs_attr_search_ctx *ctx;
5659
runlist_element *rl;
60+
unsigned long flags;
5761
int err = 0;
5862

5963
ntfs_debug("Mapping runlist part containing vcn 0x%llx.",
@@ -85,8 +89,11 @@ int ntfs_map_runlist_nolock(ntfs_inode *ni, VCN vcn)
8589
* ntfs_mapping_pairs_decompress() fails.
8690
*/
8791
end_vcn = sle64_to_cpu(a->data.non_resident.highest_vcn) + 1;
88-
if (unlikely(!a->data.non_resident.lowest_vcn && end_vcn <= 1))
92+
if (unlikely(!a->data.non_resident.lowest_vcn && end_vcn <= 1)) {
93+
read_lock_irqsave(&ni->size_lock, flags);
8994
end_vcn = ni->allocated_size >> ni->vol->cluster_size_bits;
95+
read_unlock_irqrestore(&ni->size_lock, flags);
96+
}
9097
if (unlikely(vcn >= end_vcn)) {
9198
err = -ENOENT;
9299
goto err_out;
@@ -165,6 +172,7 @@ LCN ntfs_attr_vcn_to_lcn_nolock(ntfs_inode *ni, const VCN vcn,
165172
const BOOL write_locked)
166173
{
167174
LCN lcn;
175+
unsigned long flags;
168176
BOOL is_retry = FALSE;
169177

170178
ntfs_debug("Entering for i_ino 0x%lx, vcn 0x%llx, %s_locked.",
@@ -173,6 +181,14 @@ LCN ntfs_attr_vcn_to_lcn_nolock(ntfs_inode *ni, const VCN vcn,
173181
BUG_ON(!ni);
174182
BUG_ON(!NInoNonResident(ni));
175183
BUG_ON(vcn < 0);
184+
if (!ni->runlist.rl) {
185+
read_lock_irqsave(&ni->size_lock, flags);
186+
if (!ni->allocated_size) {
187+
read_unlock_irqrestore(&ni->size_lock, flags);
188+
return LCN_ENOENT;
189+
}
190+
read_unlock_irqrestore(&ni->size_lock, flags);
191+
}
176192
retry_remap:
177193
/* Convert vcn to lcn. If that fails map the runlist and retry once. */
178194
lcn = ntfs_rl_vcn_to_lcn(ni->runlist.rl, vcn);
@@ -255,6 +271,7 @@ LCN ntfs_attr_vcn_to_lcn_nolock(ntfs_inode *ni, const VCN vcn,
255271
runlist_element *ntfs_attr_find_vcn_nolock(ntfs_inode *ni, const VCN vcn,
256272
const BOOL write_locked)
257273
{
274+
unsigned long flags;
258275
runlist_element *rl;
259276
int err = 0;
260277
BOOL is_retry = FALSE;
@@ -265,6 +282,14 @@ runlist_element *ntfs_attr_find_vcn_nolock(ntfs_inode *ni, const VCN vcn,
265282
BUG_ON(!ni);
266283
BUG_ON(!NInoNonResident(ni));
267284
BUG_ON(vcn < 0);
285+
if (!ni->runlist.rl) {
286+
read_lock_irqsave(&ni->size_lock, flags);
287+
if (!ni->allocated_size) {
288+
read_unlock_irqrestore(&ni->size_lock, flags);
289+
return ERR_PTR(-ENOENT);
290+
}
291+
read_unlock_irqrestore(&ni->size_lock, flags);
292+
}
268293
retry_remap:
269294
rl = ni->runlist.rl;
270295
if (likely(rl && vcn >= rl[0].vcn)) {
@@ -528,6 +553,11 @@ int load_attribute_list(ntfs_volume *vol, runlist *runlist, u8 *al_start,
528553
block_size_bits = sb->s_blocksize_bits;
529554
down_read(&runlist->lock);
530555
rl = runlist->rl;
556+
if (!rl) {
557+
ntfs_error(sb, "Cannot read attribute list since runlist is "
558+
"missing.");
559+
goto err_out;
560+
}
531561
/* Read all clusters specified by the runlist one run at a time. */
532562
while (rl->length) {
533563
lcn = ntfs_rl_vcn_to_lcn(rl, rl->vcn);

0 commit comments

Comments
 (0)