]> git.itanic.dy.fi Git - linux-stable/commitdiff
exfat: fix referencing wrong parent directory information after renaming
authorYuezhang Mo <Yuezhang.Mo@sony.com>
Mon, 4 Apr 2022 02:58:06 +0000 (11:58 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 29 Jul 2022 15:25:28 +0000 (17:25 +0200)
[ Upstream commit d8dad2588addd1d861ce19e7df3b702330f0c7e3 ]

During renaming, the parent directory information maybe
updated. But the file/directory still references to the
old parent directory information.

This bug will cause 2 problems.

(1) The renamed file can not be written.

    [10768.175172] exFAT-fs (sda1): error, failed to bmap (inode : 7afd50e4 iblock : 0, err : -5)
    [10768.184285] exFAT-fs (sda1): Filesystem has been set read-only
    ash: write error: Input/output error

(2) Some dentries of the renamed file/directory are not set
    to deleted after removing the file/directory.

exfat_update_parent_info() is a workaround for the wrong parent
directory information being used after renaming. Now that bug is
fixed, this is no longer needed, so remove it.

Fixes: 5f2aa075070c ("exfat: add inode operations")
Cc: stable@vger.kernel.org # v5.7+
Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
Reviewed-by: Andy Wu <Andy.Wu@sony.com>
Reviewed-by: Aoyama Wataru <wataru.aoyama@sony.com>
Reviewed-by: Daniel Palmer <daniel.palmer@sony.com>
Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/exfat/namei.c

index 9d8ada781250bc4d6956f933d9715ea0b67b016f..939737ba520d0119bb411e821fe8a85fbfb9b3f9 100644 (file)
@@ -1069,6 +1069,7 @@ static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir,
 
                exfat_remove_entries(inode, p_dir, oldentry, 0,
                        num_old_entries);
+               ei->dir = *p_dir;
                ei->entry = newentry;
        } else {
                if (exfat_get_entry_type(epold) == TYPE_FILE) {
@@ -1159,28 +1160,6 @@ static int exfat_move_file(struct inode *inode, struct exfat_chain *p_olddir,
        return 0;
 }
 
-static void exfat_update_parent_info(struct exfat_inode_info *ei,
-               struct inode *parent_inode)
-{
-       struct exfat_sb_info *sbi = EXFAT_SB(parent_inode->i_sb);
-       struct exfat_inode_info *parent_ei = EXFAT_I(parent_inode);
-       loff_t parent_isize = i_size_read(parent_inode);
-
-       /*
-        * the problem that struct exfat_inode_info caches wrong parent info.
-        *
-        * because of flag-mismatch of ei->dir,
-        * there is abnormal traversing cluster chain.
-        */
-       if (unlikely(parent_ei->flags != ei->dir.flags ||
-                    parent_isize != EXFAT_CLU_TO_B(ei->dir.size, sbi) ||
-                    parent_ei->start_clu != ei->dir.dir)) {
-               exfat_chain_set(&ei->dir, parent_ei->start_clu,
-                       EXFAT_B_TO_CLU_ROUND_UP(parent_isize, sbi),
-                       parent_ei->flags);
-       }
-}
-
 /* rename or move a old file into a new file */
 static int __exfat_rename(struct inode *old_parent_inode,
                struct exfat_inode_info *ei, struct inode *new_parent_inode,
@@ -1211,8 +1190,6 @@ static int __exfat_rename(struct inode *old_parent_inode,
                return -ENOENT;
        }
 
-       exfat_update_parent_info(ei, old_parent_inode);
-
        exfat_chain_dup(&olddir, &ei->dir);
        dentry = ei->entry;
 
@@ -1233,8 +1210,6 @@ static int __exfat_rename(struct inode *old_parent_inode,
                        goto out;
                }
 
-               exfat_update_parent_info(new_ei, new_parent_inode);
-
                p_dir = &(new_ei->dir);
                new_entry = new_ei->entry;
                ep = exfat_get_dentry(sb, p_dir, new_entry, &new_bh, NULL);