fs/ntfs3: Correct checking while generating attr_list

Correct slightly previous commit:
Enhance sanity check while generating attr_list

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
This commit is contained in:
Konstantin Komarov 2023-05-08 13:32:10 +04:00
parent ea303f72d7
commit 14f527d44d
No known key found for this signature in database
GPG key ID: A9B0331F832407B6

View file

@ -813,10 +813,8 @@ int ni_create_attr_list(struct ntfs_inode *ni)
* Looks like one record_size is always enough. * Looks like one record_size is always enough.
*/ */
le = kmalloc(al_aligned(rs), GFP_NOFS); le = kmalloc(al_aligned(rs), GFP_NOFS);
if (!le) { if (!le)
err = -ENOMEM; return -ENOMEM;
goto out;
}
mi_get_ref(&ni->mi, &le->ref); mi_get_ref(&ni->mi, &le->ref);
ni->attr_list.le = le; ni->attr_list.le = le;
@ -865,14 +863,14 @@ int ni_create_attr_list(struct ntfs_inode *ni)
if (to_free > free_b) { if (to_free > free_b) {
err = -EINVAL; err = -EINVAL;
goto out1; goto out;
} }
} }
/* Allocate child MFT. */ /* Allocate child MFT. */
err = ntfs_look_free_mft(sbi, &rno, is_mft, ni, &mi); err = ntfs_look_free_mft(sbi, &rno, is_mft, ni, &mi);
if (err) if (err)
goto out1; goto out;
err = -EINVAL; err = -EINVAL;
/* Call mi_remove_attr() in reverse order to keep pointers 'arr_move' valid. */ /* Call mi_remove_attr() in reverse order to keep pointers 'arr_move' valid. */
@ -884,7 +882,7 @@ int ni_create_attr_list(struct ntfs_inode *ni)
attr = mi_insert_attr(mi, b->type, Add2Ptr(b, name_off), attr = mi_insert_attr(mi, b->type, Add2Ptr(b, name_off),
b->name_len, asize, name_off); b->name_len, asize, name_off);
if (!attr) if (!attr)
goto out1; goto out;
mi_get_ref(mi, &le_b[nb]->ref); mi_get_ref(mi, &le_b[nb]->ref);
le_b[nb]->id = attr->id; le_b[nb]->id = attr->id;
@ -895,19 +893,19 @@ int ni_create_attr_list(struct ntfs_inode *ni)
/* Remove from primary record. */ /* Remove from primary record. */
if (!mi_remove_attr(NULL, &ni->mi, b)) if (!mi_remove_attr(NULL, &ni->mi, b))
goto out1; goto out;
if (to_free <= asize) if (to_free <= asize)
break; break;
to_free -= asize; to_free -= asize;
if (!nb) if (!nb)
goto out1; goto out;
} }
attr = mi_insert_attr(&ni->mi, ATTR_LIST, NULL, 0, attr = mi_insert_attr(&ni->mi, ATTR_LIST, NULL, 0,
lsize + SIZEOF_RESIDENT, SIZEOF_RESIDENT); lsize + SIZEOF_RESIDENT, SIZEOF_RESIDENT);
if (!attr) if (!attr)
goto out1; goto out;
attr->non_res = 0; attr->non_res = 0;
attr->flags = 0; attr->flags = 0;
@ -921,16 +919,13 @@ int ni_create_attr_list(struct ntfs_inode *ni)
ni->attr_list.dirty = false; ni->attr_list.dirty = false;
mark_inode_dirty(&ni->vfs_inode); mark_inode_dirty(&ni->vfs_inode);
goto out; return 0;
out1: out:
kfree(ni->attr_list.le); kfree(ni->attr_list.le);
ni->attr_list.le = NULL; ni->attr_list.le = NULL;
ni->attr_list.size = 0; ni->attr_list.size = 0;
return err; return err;
out:
return 0;
} }
/* /*