2022-03-25 17:58:54

by [email protected]

[permalink] [raw]
Subject: [PATCH 1/2] exfat: fix referencing wrong parent directory information after renaming

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.

fixes: 5f2aa075070c ("exfat: add inode operations")

Signed-off-by: Yuezhang Mo <[email protected]>
Reviewed-by: Andy Wu <[email protected]>
Reviewed-by: Aoyama Wataru <[email protected]>
Reviewed-by: Daniel Palmer <[email protected]>
---
fs/exfat/namei.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c
index a02a04a993bf..e7adb6bfd9d5 100644
--- a/fs/exfat/namei.c
+++ b/fs/exfat/namei.c
@@ -1080,6 +1080,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) {
--
2.25.1


Attachments:
0001-exfat-fix-referencing-wrong-parent-directory-informa.patch (1.25 kB)
0001-exfat-fix-referencing-wrong-parent-directory-informa.patch

2022-03-28 18:57:48

by [email protected]

[permalink] [raw]
Subject: RE: [PATCH 1/2] exfat: fix referencing wrong parent directory information after renaming

Hi Namjae Jeon,

The issue can be reproduced by

Step 1: create and rename the file as:

dir=${mount_point}/dir

rm -fr ${mount_point}/*
mkdir ${dir}
dirsize=$(du -b ${dir} | awk '{print $1}')

for ((i = 1; i <= dirsize / (32 * 3); i++)); do
touch ${dir}/file-$i
done

mkdir ${mount_point}/dir2

mv ${dir}/file-1 ${dir}/long-file-name-1234567890-1234567890

> > (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
> Could you please elaborate how to reproduce it ?

Step 2: Write data to the renamed file, such as:

echo xxx > ${dir}/file-1 ${dir}/long-file-name-1234567890-1234567890

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

After applying the debug patch,
```diff
--- a/fs/exfat/namei.c
+++ b/fs/exfat/namei.c
@@ -824,6 +824,11 @@ static int exfat_unlink(struct inode *dir, struct dentry *dentry)
num_entries++;
brelse(bh);

+ if (num_entries != ep->dentry.file.num_ext + 1) {
+ pr_err("file has %d entries\n", ep->dentry.file.num_ext + 1);
+ pr_err("But only set %d entries to deleted\n", num_entries);
+ }
+
exfat_set_volume_dirty(sb);
/* update the directory entry */
if (exfat_remove_entries(dir, &cdir, entry, 0, num_entries)) {
```

We can find that 4 entries are not set to delete.

[ 388.140802] file has 5 entries
[ 388.144200] But only set 1 entries to deleted

2022-03-28 22:03:53

by Namjae Jeon

[permalink] [raw]
Subject: Re: [PATCH 1/2] exfat: fix referencing wrong parent directory information after renaming

2022-03-25 18:42 GMT+09:00, [email protected] <[email protected]>:
Hi Yuezhang,

> 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
Could you please elaborate how to reproduce it ?

Thanks.
>
> (2) Some dentries of the renamed file/directory are not set
> to deleted after removing the file/directory.
>
> fixes: 5f2aa075070c ("exfat: add inode operations")
>
> Signed-off-by: Yuezhang Mo <[email protected]>
> Reviewed-by: Andy Wu <[email protected]>
> Reviewed-by: Aoyama Wataru <[email protected]>
> Reviewed-by: Daniel Palmer <[email protected]>
> ---
> fs/exfat/namei.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c
> index a02a04a993bf..e7adb6bfd9d5 100644
> --- a/fs/exfat/namei.c
> +++ b/fs/exfat/namei.c
> @@ -1080,6 +1080,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) {
> --
> 2.25.1
>

2022-04-02 12:43:42

by Sungjong Seo

[permalink] [raw]
Subject: RE: [PATCH 1/2] exfat: fix referencing wrong parent directory information after renaming

> 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.
>
> fixes: 5f2aa075070c ("exfat: add inode operations")
>
> Signed-off-by: Yuezhang Mo <[email protected]>
> Reviewed-by: Andy Wu <[email protected]>
> Reviewed-by: Aoyama Wataru <[email protected]>
> Reviewed-by: Daniel Palmer <[email protected]>

Looks good!
Thanks for your patch!
Reviewed-by: Sungjong Seo <[email protected]>

> ---
> fs/exfat/namei.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c index
> a02a04a993bf..e7adb6bfd9d5 100644
> --- a/fs/exfat/namei.c
> +++ b/fs/exfat/namei.c
> @@ -1080,6 +1080,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) {
> --
> 2.25.1