deepin-kernel/fs/fuse
Guang Yuan Wu 6e733c8d7e fuse: fix race between concurrent setattrs from multiple nodes
[ Upstream commit 69efbff69f89c9b2b72c4d82ad8b59706add768a ]

When mounting a user-space filesystem on multiple clients, after
concurrent ->setattr() calls from different node, stale inode
attributes may be cached in some node.

This is caused by fuse_setattr() racing with
fuse_reverse_inval_inode().

When filesystem server receives setattr request, the client node
with valid iattr cached will be required to update the fuse_inode's
attr_version and invalidate the cache by fuse_reverse_inval_inode(),
and at the next call to ->getattr() they will be fetched from user
space.

The race scenario is:
1. client-1 sends setattr (iattr-1) request to server
2. client-1 receives the reply from server
3. before client-1 updates iattr-1 to the cached attributes by
   fuse_change_attributes_common(), server receives another setattr
   (iattr-2) request from client-2
4. server requests client-1 to update the inode attr_version and
   invalidate the cached iattr, and iattr-1 becomes staled
5. client-2 receives the reply from server, and caches iattr-2
6. continue with step 2, client-1 invokes
   fuse_change_attributes_common(), and caches iattr-1

The issue has been observed from concurrent of chmod, chown, or
truncate, which all invoke ->setattr() call.

The solution is to use fuse_inode's attr_version to check whether
the attributes have been modified during the setattr request's
lifetime.  If so, mark the attributes as invalid in the function
fuse_change_attributes_common().

Signed-off-by: Guang Yuan Wu <gwu@ddn.com>
Reviewed-by: Bernd Schubert <bschubert@ddn.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit 96715eb1a12097a1a89f7a8912c9597385de63aa)
2025-07-09 09:49:55 +08:00
..
Kconfig dax: remove CONFIG_DAX_DRIVER 2021-12-04 08:58:51 -08:00
Makefile fuse: move ioctl to separate source file 2021-04-12 15:04:30 +02:00
OWNERS deepin: OWNERS: Update OWNERS 2025-05-29 18:26:52 +08:00
acl.c fs.idmapped.v6.3 2023-02-20 11:53:11 -08:00
control.c fuse: convert to ctime accessor functions 2023-07-24 10:29:59 +02:00
cuse.c fuse: fix UAF in rcu pathwalks 2024-12-10 20:40:48 +08:00
dax.c fuse: fix dax truncate/punch_hole fault path 2025-04-14 15:49:23 +08:00
dev.c fs: fuse: add dev id to /dev/fuse fdinfo 2025-06-19 16:56:24 +08:00
dir.c fuse: fix race between concurrent setattrs from multiple nodes 2025-07-09 09:49:55 +08:00
file.c fuse: fix dax truncate/punch_hole fault path 2025-04-14 15:49:23 +08:00
fuse_i.h deepin: KABI: KABI reservation for fuse structures 2025-01-14 21:13:26 +08:00
inode.c fuse: fix UAF in rcu pathwalks 2024-12-10 20:40:48 +08:00
ioctl.c fuse: ioctl: translate ENOSYS in outarg 2023-06-21 11:17:36 +02:00
readdir.c fuse: cache btime 2023-08-21 12:14:59 +02:00
virtio_fs.c virtiofs: add filesystem context source name check 2025-05-09 22:54:46 +08:00
xattr.c fuse: use unsigned type for getxattr/listxattr size truncation 2024-12-10 20:41:17 +08:00