fuse: initialize attr_version of new fuse inodes by fc->attr_version

Message ID 20221111093702.80975-1-zhangjiachen.jaycee@bytedance.com
State New
Headers
Series fuse: initialize attr_version of new fuse inodes by fc->attr_version |

Commit Message

Jiachen Zhang Nov. 11, 2022, 9:37 a.m. UTC
  The FUSE_READDIRPLUS request reply handler fuse_direntplus_link() might
call fuse_iget() to initialize a new fuse_inode and change its attributes.
But as the new fi->attr_version is always initialized with 0, even if the
attr_version of the FUSE_READDIRPLUS request has become staled, staled attr
may still be set to the new fuse_inode. This may cause file size
inconsistency even when a filesystem backend is mounted with a single FUSE
mountpoint.

This commit fixes the issue by initializing new fuse_inode attr_versions by
the global fc->attr_version. This may introduce more FUSE_GETATTR but can
avoid weird attributes rollback being seen by users.

Fixes: 19332138887c ("fuse: initialize attr_version of new fuse inodes by fc->attr_version")
Signed-off-by: Jiachen Zhang <zhangjiachen.jaycee@bytedance.com>
---
 fs/fuse/inode.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Jiachen Zhang Nov. 17, 2022, 8:52 a.m. UTC | #1
On Fri, Nov 11, 2022 at 5:37 PM Jiachen Zhang
<zhangjiachen.jaycee@bytedance.com> wrote:
>
> The FUSE_READDIRPLUS request reply handler fuse_direntplus_link() might
> call fuse_iget() to initialize a new fuse_inode and change its attributes.
> But as the new fi->attr_version is always initialized with 0, even if the
> attr_version of the FUSE_READDIRPLUS request has become staled, staled attr
> may still be set to the new fuse_inode. This may cause file size
> inconsistency even when a filesystem backend is mounted with a single FUSE
> mountpoint.
>
> This commit fixes the issue by initializing new fuse_inode attr_versions by
> the global fc->attr_version. This may introduce more FUSE_GETATTR but can
> avoid weird attributes rollback being seen by users.
>
> Fixes: 19332138887c ("fuse: initialize attr_version of new fuse inodes by fc->attr_version")

Ping..., and the Fixes tag should be:

Fixes: fbee36b92abc ("fuse: fix uninitialized field in fuse_inode")

Best regards,
Jiachen

> Signed-off-by: Jiachen Zhang <zhangjiachen.jaycee@bytedance.com>
> ---
>  fs/fuse/inode.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
> index 6b3beda16c1b..145ded6b55af 100644
> --- a/fs/fuse/inode.c
> +++ b/fs/fuse/inode.c
> @@ -71,6 +71,7 @@ struct fuse_forget_link *fuse_alloc_forget(void)
>  static struct inode *fuse_alloc_inode(struct super_block *sb)
>  {
>         struct fuse_inode *fi;
> +       struct fuse_conn *fc = get_fuse_conn_super(sb);
>
>         fi = alloc_inode_sb(sb, fuse_inode_cachep, GFP_KERNEL);
>         if (!fi)
> @@ -80,7 +81,7 @@ static struct inode *fuse_alloc_inode(struct super_block *sb)
>         fi->inval_mask = 0;
>         fi->nodeid = 0;
>         fi->nlookup = 0;
> -       fi->attr_version = 0;
> +       fi->attr_version = fuse_get_attr_version(fc);
>         fi->orig_ino = 0;
>         fi->state = 0;
>         mutex_init(&fi->mutex);
> --
> 2.20.1
>
  
Miklos Szeredi Feb. 1, 2023, 3:54 p.m. UTC | #2
On Thu, 17 Nov 2022 at 09:52, Jiachen Zhang
<zhangjiachen.jaycee@bytedance.com> wrote:
>
> On Fri, Nov 11, 2022 at 5:37 PM Jiachen Zhang
> <zhangjiachen.jaycee@bytedance.com> wrote:
> >
> > The FUSE_READDIRPLUS request reply handler fuse_direntplus_link() might
> > call fuse_iget() to initialize a new fuse_inode and change its attributes.
> > But as the new fi->attr_version is always initialized with 0, even if the
> > attr_version of the FUSE_READDIRPLUS request has become staled, staled attr
> > may still be set to the new fuse_inode. This may cause file size
> > inconsistency even when a filesystem backend is mounted with a single FUSE
> > mountpoint.
> >
> > This commit fixes the issue by initializing new fuse_inode attr_versions by
> > the global fc->attr_version. This may introduce more FUSE_GETATTR but can
> > avoid weird attributes rollback being seen by users.
> >
> > Fixes: 19332138887c ("fuse: initialize attr_version of new fuse inodes by fc->attr_version")
>
> Ping..., and the Fixes tag should be:
>
> Fixes: fbee36b92abc ("fuse: fix uninitialized field in fuse_inode")

Do you have a reproducer?

Thanks,
Miklos
  

Patch

diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 6b3beda16c1b..145ded6b55af 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -71,6 +71,7 @@  struct fuse_forget_link *fuse_alloc_forget(void)
 static struct inode *fuse_alloc_inode(struct super_block *sb)
 {
 	struct fuse_inode *fi;
+	struct fuse_conn *fc = get_fuse_conn_super(sb);
 
 	fi = alloc_inode_sb(sb, fuse_inode_cachep, GFP_KERNEL);
 	if (!fi)
@@ -80,7 +81,7 @@  static struct inode *fuse_alloc_inode(struct super_block *sb)
 	fi->inval_mask = 0;
 	fi->nodeid = 0;
 	fi->nlookup = 0;
-	fi->attr_version = 0;
+	fi->attr_version = fuse_get_attr_version(fc);
 	fi->orig_ino = 0;
 	fi->state = 0;
 	mutex_init(&fi->mutex);