Skip to content

Commit 7288c27

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 ea9fea3 commit 7288c27

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
@@ -267,7 +267,7 @@ static int fuse_open(struct inode *inode, struct file *file)
267267
filemap_invalidate_lock(inode->i_mapping);
268268
err = fuse_dax_break_layouts(inode, 0, -1);
269269
if (err)
270-
goto out_inode_unlock;
270+
goto out_unlock;
271271
}
272272

273273
if (is_wb_truncate || dax_truncate)
@@ -291,9 +291,9 @@ static int fuse_open(struct inode *inode, struct file *file)
291291
else if (!(ff->open_flags & FOPEN_KEEP_CACHE))
292292
invalidate_inode_pages2(inode->i_mapping);
293293
}
294+
out_unlock:
294295
if (dax_truncate)
295296
filemap_invalidate_unlock(inode->i_mapping);
296-
out_inode_unlock:
297297
if (is_wb_truncate || dax_truncate)
298298
inode_unlock(inode);
299299

0 commit comments

Comments
 (0)