Skip to content

Commit a61524d

Browse files
LiBaokun96gregkh
authored andcommitted
fuse: fix invalidate lock leak on open O_TRUNC DAX failure
commit a927f18 upstream. fuse_open() takes filemap_invalidate_lock() for a DAX truncate (dax_truncate = true) and releases it before the out_inode_unlock label. But when fuse_dax_break_layouts() fails, the goto out_inode_unlock skips the unlock and leaks the rwsem, so any later fault or truncate on the file stalls on the stale lock. fuse_dax_break_layouts() can fail with -ERESTARTSYS when a signal interrupts the wait for busy DAX pages to drain: open("file", O_RDWR | O_TRUNC) └─ fuse_open() ├─ filemap_invalidate_lock() # dax_truncate └─ fuse_dax_break_layouts() └─ dax_break_layout() └─ wait_page_idle() # TASK_INTERRUPTIBLE └─ fuse_wait_dax_page() # unlock, schedule, re-lock └─ signal → -ERESTARTSYS goto out_inode_unlock # <- lock leaked Fix this by moving filemap_invalidate_unlock() below the label so that all error paths release the lock, and rename the label to out_unlock as it now covers more than just the inode lock. Fixes: 2fdbb8d ("fuse: fix deadlock between atomic O_TRUNC and page invalidation") Cc: stable@vger.kernel.org # v6.0+ 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 03cfeeb commit a61524d

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

fs/fuse/file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ int fuse_open_common(struct inode *inode, struct file *file, bool isdir)
259259
filemap_invalidate_lock(inode->i_mapping);
260260
err = fuse_dax_break_layouts(inode, 0, -1);
261261
if (err)
262-
goto out_inode_unlock;
262+
goto out_unlock;
263263
}
264264

265265
if (is_wb_truncate || dax_truncate)
@@ -279,9 +279,9 @@ int fuse_open_common(struct inode *inode, struct file *file, bool isdir)
279279
else if (!(ff->open_flags & FOPEN_KEEP_CACHE))
280280
invalidate_inode_pages2(inode->i_mapping);
281281
}
282+
out_unlock:
282283
if (dax_truncate)
283284
filemap_invalidate_unlock(inode->i_mapping);
284-
out_inode_unlock:
285285
if (is_wb_truncate || dax_truncate)
286286
inode_unlock(inode);
287287

0 commit comments

Comments
 (0)