Skip to content

Commit 69efbff

Browse files
gwu-ddnMiklos Szeredi
authored andcommitted
fuse: fix race between concurrent setattrs from multiple nodes
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 <[email protected]> Reviewed-by: Bernd Schubert <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent 0c58a97 commit 69efbff

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

fs/fuse/dir.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,6 +1963,7 @@ int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
19631963
int err;
19641964
bool trust_local_cmtime = is_wb;
19651965
bool fault_blocked = false;
1966+
u64 attr_version;
19661967

19671968
if (!fc->default_permissions)
19681969
attr->ia_valid |= ATTR_FORCE;
@@ -2047,6 +2048,8 @@ int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
20472048
if (fc->handle_killpriv_v2 && !capable(CAP_FSETID))
20482049
inarg.valid |= FATTR_KILL_SUIDGID;
20492050
}
2051+
2052+
attr_version = fuse_get_attr_version(fm->fc);
20502053
fuse_setattr_fill(fc, &args, inode, &inarg, &outarg);
20512054
err = fuse_simple_request(fm, &args);
20522055
if (err) {
@@ -2072,6 +2075,14 @@ int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
20722075
/* FIXME: clear I_DIRTY_SYNC? */
20732076
}
20742077

2078+
if (fi->attr_version > attr_version) {
2079+
/*
2080+
* Apply attributes, for example for fsnotify_change(), but set
2081+
* attribute timeout to zero.
2082+
*/
2083+
outarg.attr_valid = outarg.attr_valid_nsec = 0;
2084+
}
2085+
20752086
fuse_change_attributes_common(inode, &outarg.attr, NULL,
20762087
ATTR_TIMEOUT(&outarg),
20772088
fuse_get_cache_mask(inode), 0);

0 commit comments

Comments
 (0)