From: sashiko-bot@kernel.org
To: "Tal Zussman" <tz2294@columbia.edu>,
"Andreas Gruenbacher" <agruenba@redhat.com>
Cc: gfs2@lists.linux.dev, "Matthew Wilcox (Oracle)" <willy@infradead.org>
Subject: Re: [PATCH v2 2/4] gfs2: stop using pages for log buffers
Date: Tue, 24 Nov 2026 21:21:52 +0000 [thread overview]
Message-ID: <sashiko-outbox-232037@kernel.org> (raw)
In-Reply-To: <20261124-gfs2-log-folio-v2-2-f229e90c8285@columbia.edu>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] gfs2: use-after-free of sdp in gfs2_end_log_write_buf() on
teardown
--
commit f7b4eeef3695e09c06bd25c0916b1f82335a68b3
Author: Tal Zussman <tz2294@columbia.edu>
gfs2: stop using pages for log buffers
This commit replaces the per-superblock page mempool for log buffers with a
kmalloc mempool of block-sized buffers and gives pool blocks their own bio
completion handler, gfs2_end_log_write_buf(), splitting bios whenever the
completion handler changes.
> diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
> index 7a2c29652feca..156d7c6341ca1 100644
> --- a/fs/gfs2/lops.c
> +++ b/fs/gfs2/lops.c
> @@ -196,45 +196,70 @@ static void gfs2_end_log_write_bh(struct gfs2_sbd *sdp, struct folio *folio,
> } while (bh && size);
> }
>
[ ... ]
> +static void gfs2_end_log_write_buf(struct bio *bio)
> +{
> + struct gfs2_sbd *sdp = bio->bi_private;
> + struct bio_vec *bvec;
> + struct bvec_iter_all iter_all;
> +
> + if (bio->bi_status)
> + gfs2_log_write_error(bio);
> +
> + bio_for_each_segment_all(bvec, bio, iter_all)
> + mempool_free(bvec_virt(bvec), &sdp->sd_log_buf_pool);
> +
> + gfs2_log_write_done(bio);
> }
>
> /**
> @@ -291,9 +316,9 @@ static struct bio *gfs2_log_alloc_bio(struct gfs2_sbd *sdp, u64 blkno,
> * @flush: Always flush the current bio and allocate a new one?
> *
> * If there is a cached bio, then if the next block number is sequential
> - * with the previous one, return it, otherwise flush the bio to the
> - * device. If there is no cached bio, or we just flushed it, then
> - * allocate a new one.
> + * with the previous one and the bio has the same completion handler,
> + * return it, otherwise flush the bio to the device. If there is no
> + * cached bio, or we just flushed it, then allocate a new one.
> *
> * Returns: The bio to use for log writes
> */
> @@ -309,7 +334,7 @@ static struct bio *gfs2_log_get_bio(struct gfs2_sbd *sdp, u64 blkno,
>
> nblk = bio_end_sector(bio);
> nblk >>= sdp->sd_fsb2bb_shift;
> - if (blkno == nblk && !flush)
> + if (blkno == nblk && bio->bi_end_io == end_io && !flush)
> return bio;
> gfs2_log_submit_write(biop);
> }
[Severity: Medium]
Can gfs2_end_log_write_buf() and gfs2_log_write_done() use sdp after
free_sbd() has freed it?
Because gfs2_log_get_bio() now submits the current bio whenever
bio->bi_end_io changes between gfs2_end_log_write_buf and
gfs2_end_log_write, lops_before_commit() submits log bios before
__gfs2_log_flush() checks for withdraw:
fs/gfs2/log.c:__gfs2_log_flush() {
...
lops_before_commit(sdp, tr);
if (gfs2_withdrawn(sdp))
goto out_withdraw;
if (sdp->sd_jdesc)
gfs2_log_submit_write(&sdp->sd_jdesc->jd_log_bio);
if (gfs2_withdrawn(sdp))
goto out_withdraw;
...
}
Jumping to out_withdraw skips log_write_header() and log_flush_wait(sdp),
and clean_journal() likewise submits a log header bio via
gfs2_write_log_header() without calling log_flush_wait(sdp). Neither the
withdrawn unmount path nor free_sbd() waits for sdp->sd_log_in_flight to
reach zero before calling mempool_exit(&sdp->sd_log_buf_pool) and
kfree(sdp):
CPU0 CPU1 (bio completion)
__gfs2_log_flush()
lops_before_commit()
...
gfs2_log_get_bio()
gfs2_log_submit_write()
if (gfs2_withdrawn(sdp))
goto out_withdraw;
...
deactivate_locked_super()
...
free_sbd(sdp)
mempool_exit(&sdp->sd_log_buf_pool)
kfree(sdp)
gfs2_end_log_write_buf(bio)
mempool_free(...,
&sdp->sd_log_buf_pool)
<-- use-after-free
gfs2_log_write_done(bio)
atomic_dec_and_test(
&sdp->sd_log_in_flight)
Waiting on log_flush_wait(sdp) before mempool_exit(&sdp->sd_log_buf_pool)
in free_sbd() (and in out_withdraw) would ensure all in-flight log bios
have completed before sdp is torn down.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-gfs2-log-folio-v2-0-f229e90c8285@columbia.edu?part=2
next prev parent reply other threads:[~2026-11-24 21:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 21:04 [PATCH v2 0/4] gfs2: stop using struct page in the log code Tal Zussman
2026-11-24 21:04 ` [PATCH v2 1/4] gfs2: make the log page pool per superblock Tal Zussman
2026-11-24 21:16 ` sashiko-bot
2026-11-24 21:55 ` Tal Zussman
2026-11-24 21:04 ` [PATCH v2 2/4] gfs2: stop using pages for log buffers Tal Zussman
2026-11-24 21:21 ` sashiko-bot [this message]
2026-11-24 21:04 ` [PATCH v2 3/4] gfs2: plug the log writes of a flush Tal Zussman
2026-11-24 21:04 ` [PATCH v2 4/4] gfs2: remove the remaining page references in the log code Tal Zussman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-232037@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agruenba@redhat.com \
--cc=gfs2@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tz2294@columbia.edu \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox