Skip to content

Commit 1758730

Browse files
LiBaokun96gregkh
authored andcommitted
fuse: fix invalidate lock leak on setattr writeback failure
commit 9afeca0 upstream. fuse_do_setattr() takes filemap_invalidate_lock() for a DAX truncate (fault_blocked = true) and releases it at the out:/error: labels. But when a writeback flush is also needed, a write_inode_now() failure returns directly and leaks the lock, so any later fault or truncate on the file stalls on the stale rwsem. For example, truncate(2) on a setuid file reaches fuse_do_setattr() with both ATTR_SIZE and ATTR_MODE set: truncate(2) └─ do_truncate() ├─ dentry_needs_remove_privs() # S_ISUID └─ notify_change() # KILL_SUID -> ATTR_MODE └─ fuse_setattr() # no killpriv: │ # ia_valid |= ATTR_MODE └─ fuse_do_setattr() ├─ filemap_invalidate_lock() # IS_DAX && is_truncate └─ write_inode_now() # is_wb && ATTR_MODE └─ if (err) # e.g. daemon -> -EIO return err # <- lock leaked Fix this by adding an unlock label that releases the lock before returning the error, and use it for the fuse_dax_break_layouts() failure path as well. Fixes: 6ae330c ("virtiofs: serialize truncate/punch_hole and dax fault path") Cc: stable@vger.kernel.org # v5.10+ Signed-off-by: Baokun Li <libaokun@linux.alibaba.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0f127d5 commit 1758730

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

fs/fuse/dir.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,10 +1976,8 @@ int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
19761976
filemap_invalidate_lock(mapping);
19771977
fault_blocked = true;
19781978
err = fuse_dax_break_layouts(inode, 0, -1);
1979-
if (err) {
1980-
filemap_invalidate_unlock(mapping);
1981-
return err;
1982-
}
1979+
if (err)
1980+
goto unlock;
19831981
}
19841982

19851983
if (attr->ia_valid & ATTR_OPEN) {
@@ -2006,7 +2004,7 @@ int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
20062004
ATTR_TIMES_SET)) {
20072005
err = write_inode_now(inode, true);
20082006
if (err)
2009-
return err;
2007+
goto unlock;
20102008

20112009
fuse_set_nowrite(inode);
20122010
fuse_release_nowrite(inode);
@@ -2114,6 +2112,7 @@ int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
21142112

21152113
clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
21162114

2115+
unlock:
21172116
if (fault_blocked)
21182117
filemap_invalidate_unlock(mapping);
21192118
return err;

0 commit comments

Comments
 (0)