Re: [PATCH 1/3] iomap: don't resubmit an ioend after ->writeback_submit() failed
From: Darrick J. Wong
Date: Mon Sep 21 2026 - 18:30:20 EST
On Mon, Sep 21, 2026 at 10:31:31AM +0200, Andrea Parri wrote:
> iomap_add_to_ioend() submits the pending ioend through
> ->writeback_submit() before allocating a new one for the current range.
> When the submission fails the helper completes the ioend with an error,
> but iomap_add_to_ioend() returns the error without clearing
> wpc->wb_ctx. iomap_writepages() then submits whatever wpc->wb_ctx
> points to, so the already completed ioend is submitted a second time.
>
> For XFS the second bio_endio() lands in xfs_end_bio(), which
> list_add_tail()s the already linked ioend into ip->i_ioend_list. This
> corrupts the list and leaves a use-after-free/double-free window against
> the ioend completion worker.
>
> Clear wpc->wb_ctx when ->writeback_submit() fails. The old
> iomap_submit_ioend() cleared the context unconditionally; that clear was
> lost when submission moved to iomap_ioend_writeback_submit().
>
> Fixes: f4fa7981fa26c ("iomap: hide ioends from the generic writeback code")
> Cc: stable@xxxxxxxxxxxxxxx
Cc: <stable@xxxxxxxxxxxxxxx> # v6.17
> Assisted-by: LLM
> Signed-off-by: Andrea Parri <parri.andrea@xxxxxxxxx>
> ---
> fs/iomap/ioend.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/fs/iomap/ioend.c b/fs/iomap/ioend.c
> index 7bbbb417f9152..bb8575768d888 100644
> --- a/fs/iomap/ioend.c
> +++ b/fs/iomap/ioend.c
> @@ -246,8 +246,16 @@ ssize_t iomap_add_to_ioend(struct iomap_writepage_ctx *wpc, struct folio *folio,
> new_ioend:
> if (ioend) {
> error = wpc->ops->writeback_submit(wpc, 0);
> - if (error)
> + if (error) {
> + /*
> + * ->writeback_submit() completed the ioend with
> + * an error, so drop the stale context.
> + * iomap_writepages() would otherwise submit it a
> + * second time.
> + */
> + wpc->wb_ctx = NULL;
Do you need to do the same thing for the ->writeback_submit call in
iomap_writepages?
--D
> return error;
> + }
> }
> wpc->wb_ctx = ioend = iomap_alloc_ioend(wpc, pos, ioend_flags);
> }
> --
> 2.53.0
>