Skip to content

Commit 6314efe

Browse files
author
Miklos Szeredi
committed
fuse: readdirplus: fix RCU walk
Doing dput(parent) is not valid in RCU walk mode. In RCU mode it would probably be okay to update the parent flags, but it's actually not necessary most of the time... So only set the FUSE_I_ADVISE_RDPLUS flag on the parent when the entry was recently initialized by READDIRPLUS. This is achieved by setting FUSE_I_INIT_RDPLUS on entries added by READDIRPLUS and only dropping out of RCU mode if this flag is set. FUSE_I_INIT_RDPLUS is cleared once the FUSE_I_ADVISE_RDPLUS flag is set in the parent. Reported-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Miklos Szeredi <mszeredi@suse.cz> Cc: stable@vger.kernel.org
1 parent 3c70b8e commit 6314efe

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

‎fs/fuse/dir.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
182182
struct inode *inode;
183183
struct dentry *parent;
184184
struct fuse_conn *fc;
185+
struct fuse_inode *fi;
185186
int ret;
186187

187188
inode = ACCESS_ONCE(entry->d_inode);
@@ -228,7 +229,7 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
228229
if (!err && !outarg.nodeid)
229230
err = -ENOENT;
230231
if (!err) {
231-
struct fuse_inode *fi = get_fuse_inode(inode);
232+
fi = get_fuse_inode(inode);
232233
if (outarg.nodeid != get_node_id(inode)) {
233234
fuse_queue_forget(fc, forget, outarg.nodeid, 1);
234235
goto invalid;
@@ -246,8 +247,11 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
246247
attr_version);
247248
fuse_change_entry_timeout(entry, &outarg);
248249
} else if (inode) {
249-
fc = get_fuse_conn(inode);
250-
if (fc->readdirplus_auto) {
250+
fi = get_fuse_inode(inode);
251+
if (flags & LOOKUP_RCU) {
252+
if (test_bit(FUSE_I_INIT_RDPLUS, &fi->state))
253+
return -ECHILD;
254+
} else if (test_and_clear_bit(FUSE_I_INIT_RDPLUS, &fi->state)) {
251255
parent = dget_parent(entry);
252256
fuse_advise_use_readdirplus(parent->d_inode);
253257
dput(parent);
@@ -1292,6 +1296,8 @@ static int fuse_direntplus_link(struct file *file,
12921296
}
12931297

12941298
found:
1299+
if (fc->readdirplus_auto)
1300+
set_bit(FUSE_I_INIT_RDPLUS, &get_fuse_inode(inode)->state);
12951301
fuse_change_entry_timeout(dentry, o);
12961302

12971303
err = 0;

‎fs/fuse/fuse_i.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ struct fuse_inode {
115115
enum {
116116
/** Advise readdirplus */
117117
FUSE_I_ADVISE_RDPLUS,
118+
/** Initialized with readdirplus */
119+
FUSE_I_INIT_RDPLUS,
118120
/** An operation changing file size is in progress */
119121
FUSE_I_SIZE_UNSTABLE,
120122
};

0 commit comments

Comments
 (0)