backing-file: always end a queued write
Subsystems (3)
Amir Goldstein
maintainerPATCH 1/1 backing-file: always end a queued write
From: Chris Mason <[email protected]>
Writes to a loop device with direct I/O on an overlay file make the next freeze of the upper filesystem hang for ever.
Every kiocb_start_write() needs a kiocb_end_write(). For a write that is queued, vfs_iocb_iter_write() leaves the end to the completion, and backing_aio_rw_complete() only calls kiocb_end_write() when IOCB_WRITE is set in the flags copied from the submitter. In-kernel submitters such as loop do not set that flag, so each queued write keeps the freeze protection of the backing filesystem.
Direct writes to a loop device with direct I/O backed by an overlay file left fsfreeze of the ext4 upper filesystem, and a later touch there, blocked in D state. It takes write access to the node of the loop device, which root has by default, to attach the file and to write.
The fix used here is to mark a write in struct backing_aio and to call kiocb_end_write() on completion of every marked write.
Reproduced under qemu without KVM, on v7.3-rc6-21-g602042bf29f6 with earlier fixes of this series applied, with and without this change, once each. The kernel was not changed for the run. With this change fsfreeze finished in about a second. Not run: the nvmet and LIO file backends, which do not set IOCB_WRITE either, FUSE passthrough, and an xfs upper filesystem.
---
Christian,
This fixes a nasty little bug.
It is not critical because it cannot be exploited by unpriv, but innocent priv users could hit it by mistake.
I could carry it via ovl-fixes with your ACK or you could take it with your other backing file fixes.
Which way do you prefer?
Thanks,
Amir.
fs/backing-file.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/backing-file.c +4 -1
@@ -84,6 +84,7 @@ struct backing_aio {refcount_t ref;struct kiocb *orig_iocb;/* used for aio completion */ +bool is_write;void (*end_write)(struct kiocb *iocb,ssize_t );struct work_struct work;long res;
@@ -124,7 +125,8 @@ static void backing_aio_rw_complete(struct kiocb *iocb, long res) struct backing_aio *aio = container_of(iocb, struct backing_aio, iocb);struct kiocb *orig_iocb = aio->orig_iocb; -if (iocb->ki_flags &IOCB_WRITE ) +/* Pairs with kiocb_start_write() in vfs_iocb_iter_write() */ +if (aio->is_write)kiocb_end_write (iocb);backing_aio_cleanup (aio, res);
@@ -239,6 +241,7 @@ static int do_backing_file_write_iter(struct file *file, struct iov_iter *iter,return -ENOMEM ; aio->orig_iocb = iocb; + aio->is_write = true; aio->end_write = end_write;kiocb_clone (&aio->iocb, iocb,get_file (file)); aio->iocb.ki_flags = flags;
Signature · 1 line
2.55.0
Quoted 11 lines · Amir Goldstein
Writes to a loop device with direct I/O on an overlay file make the next freeze of the upper filesystem hang for ever.
Every
kiocb_start_write()needs akiocb_end_write(). For a write that is queued,vfs_iocb_iter_write()leaves the end to the completion, andbacking_aio_rw_complete()only callskiocb_end_write()whenIOCB_WRITEis set in the flags copied from the submitter. In-kernel submitters such as loop do not set that flag, so each queued write keeps the freeze protection of the backing filesystem.[...]
Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs.fixes
[1/1] backing-file: always end a queued write
https://git.kernel.org/vfs/vfs/c/627cdcbc2a2e