Skip to content

Commit 15db168

Browse files
amir73ilMiklos Szeredi
authored andcommitted
fuse: fix illegal access to inode with reused nodeid
Server responds to LOOKUP and other ops (READDIRPLUS/CREATE/MKNOD/...) with ourarg containing nodeid and generation. If a fuse inode is found in inode cache with the same nodeid but different generation, the existing fuse inode should be unhashed and marked "bad" and a new inode with the new generation should be hashed instead. This can happen, for example, with passhrough fuse filesystem that returns the real filesystem ino/generation on lookup and where real inode numbers can get recycled due to real files being unlinked not via the fuse passthrough filesystem. With current code, this situation will not be detected and an old fuse dentry that used to point to an older generation real inode, can be used to access a completely new inode, which should be accessed only via the new dentry. Note that because the FORGET message carries the nodeid w/o generation, the server should wait to get FORGET counts for the nlookup counts of the old and reused inodes combined, before it can free the resources associated to that nodeid. Signed-off-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent 6b1bdb5 commit 15db168

4 files changed

Lines changed: 15 additions & 5 deletions

File tree

fs/fuse/dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
252252
if (ret == -ENOMEM)
253253
goto out;
254254
if (ret || fuse_invalid_attr(&outarg.attr) ||
255-
inode_wrong_type(inode, outarg.attr.mode))
255+
fuse_stale_inode(inode, outarg.generation, &outarg.attr))
256256
goto invalid;
257257

258258
forget_all_cached_acls(inode);

fs/fuse/fuse_i.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,13 @@ static inline u64 fuse_get_attr_version(struct fuse_conn *fc)
870870
return atomic64_read(&fc->attr_version);
871871
}
872872

873+
static inline bool fuse_stale_inode(const struct inode *inode, int generation,
874+
struct fuse_attr *attr)
875+
{
876+
return inode->i_generation != generation ||
877+
inode_wrong_type(inode, attr->mode);
878+
}
879+
873880
static inline void fuse_make_bad(struct inode *inode)
874881
{
875882
remove_inode_hash(inode);

fs/fuse/inode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,8 @@ struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
350350
inode->i_generation = generation;
351351
fuse_init_inode(inode, attr);
352352
unlock_new_inode(inode);
353-
} else if (inode_wrong_type(inode, attr->mode)) {
354-
/* Inode has changed type, any I/O on the old should fail */
353+
} else if (fuse_stale_inode(inode, generation, attr)) {
354+
/* nodeid was reused, any I/O on the old inode should fail */
355355
fuse_make_bad(inode);
356356
iput(inode);
357357
goto retry;

fs/fuse/readdir.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,12 @@ static int fuse_direntplus_link(struct file *file,
200200
if (!d_in_lookup(dentry)) {
201201
struct fuse_inode *fi;
202202
inode = d_inode(dentry);
203+
if (inode && get_node_id(inode) != o->nodeid)
204+
inode = NULL;
203205
if (!inode ||
204-
get_node_id(inode) != o->nodeid ||
205-
inode_wrong_type(inode, o->attr.mode)) {
206+
fuse_stale_inode(inode, o->generation, &o->attr)) {
207+
if (inode)
208+
fuse_make_bad(inode);
206209
d_invalidate(dentry);
207210
dput(dentry);
208211
goto retry;

0 commit comments

Comments
 (0)