fs/ntfs3: Correct undo if ntfs_create_inode failed
authorKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Thu, 30 May 2024 07:59:13 +0000 (10:59 +0300)
committerKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Wed, 26 Jun 2024 12:48:51 +0000 (15:48 +0300)
Clusters allocated for Extended Attributes, must be freed
when rolling back inode creation.

Fixes: 82cae269cfa95 ("fs/ntfs3: Add initialization of super block")
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
fs/ntfs3/inode.c

index e9a83a937a02b4e18fbc7c8aeea152d99d82e483..46130cbd08d455527aff51e745ea2255e05c4cb6 100644 (file)
@@ -1666,7 +1666,9 @@ int ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
         * The packed size of extended attribute is stored in direntry too.
         * 'fname' here points to inside new_de.
         */
-       ntfs_save_wsl_perm(inode, &fname->dup.ea_size);
+       err = ntfs_save_wsl_perm(inode, &fname->dup.ea_size);
+       if (err)
+               goto out6;
 
        /*
         * update ea_size in file_name attribute too.
@@ -1710,6 +1712,12 @@ int ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,
        goto out2;
 
 out6:
+       attr = ni_find_attr(ni, NULL, NULL, ATTR_EA, NULL, 0, NULL, NULL);
+       if (attr && attr->non_res) {
+               /* Delete ATTR_EA, if non-resident. */
+               attr_set_size(ni, ATTR_EA, NULL, 0, NULL, 0, NULL, false, NULL);
+       }
+
        if (rp_inserted)
                ntfs_remove_reparse(sbi, IO_REPARSE_TAG_SYMLINK, &new_de->ref);