Skip to contentSkip to conversation

fuse: fix inconsistent status between faccess and mkdir

PATCH In review Fengnan Chang 2 participants 2 messages May 14, 2021 – May 18, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 fuse: fix inconsistent status between faccess and mkdir

since FUSE caches dentries and attributes with separate timeout, It may happen that checking the permission returns -ENOENT, but because the dentries cache has not timed out, creating the file returns -EEXIST. Fix this by when return -ENOENT, mark the entry as stale.

---
 fs/fuse/dir.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
fs/fuse/dir.c +36 -0
index 06a18700a845..a22206290da9 100644
@@ -1065,6 +1065,24 @@ static int fuse_do_getattr(struct inode *inode, struct kstat *stat,
 				fuse_fillattr(inode, &outarg.attr, stat);
 		}
 	}
+	if (err == -ENOENT && get_node_id(inode) != FUSE_ROOT_ID) {
+		if (S_ISDIR(inode->i_mode)) {
+			struct dentry *dir = d_find_any_alias(inode);
+
+			if (dir) {
+				fuse_invalidate_entry_cache(dir);
+				dput(dir);
+			}
+		} else {
+			struct dentry *dentry;
+
+			while ((dentry = d_find_alias(inode))) {
+				fuse_invalidate_entry_cache(dentry);
+				dput(dentry);
+			}
+		}
+	}
+
 	return err;
 }
 
@@ -1226,6 +1244,24 @@ static int fuse_access(struct inode *inode, int mask)
 		fm->fc->no_access = 1;
 		err = 0;
 	}
+	if (err == -ENOENT && get_node_id(inode) != FUSE_ROOT_ID) {
+		if (S_ISDIR(inode->i_mode)) {
+			struct dentry *dir = d_find_any_alias(inode);
+
+			if (dir) {
+				fuse_invalidate_entry_cache(dir);
+				dput(dir);
+			}
+		} else {
+			struct dentry *dentry;
+
+			while ((dentry = d_find_alias(inode))) {
+				fuse_invalidate_entry_cache(dentry);
+				dput(dentry);
+			}
+		}
+	}
+
 	return err;
 }
 
Signature · 1 line
2.29.0
maintainer
#1 lore raw
Quoted 4 lines · Fengnan Chang

since FUSE caches dentries and attributes with separate timeout, It may happen that checking the permission returns -ENOENT, but because the dentries cache has not timed out, creating the file returns -EEXIST.

This should be fixed in v5.11 and later by commit df8629af2934 ("fuse:
always revalidate if exclusive create").

Thanks,
Miklos