Re: [PATCH v2] gfs2: validate log descriptor tag counts during replay
From: Andreas Gruenbacher
Date: Thu Dec 03 2026 - 19:05:06 EST
Hello,
On Thu, 3 Dec 2026 at 20:52, Kyuwon Cho <kyuwon.cho@xxxxxxxx> wrote:
> Journal replay trusts ld_data1 as the number of metadata or journaled-data
> tags stored after a log descriptor. A corrupt journal can advertise more
> tags than fit in the descriptor block, making the replay scanners read
> beyond the buffer.
>
> Validate the format-specific tag capacity and the exact descriptor length
> before the replay-pass check. Besides protecting the tag scan in pass 1,
> this prevents pass 0 from advancing with an invalid or zero ld_length.
I see where you're going. Shouldn't revoke_lo_scan_elements() receive
similar consistency checks even if it doesn't overrun any buffers?
Thanks,
Andreas
> Fixes: b3b94faa5fe5 ("[GFS2] The core of GFS2")
> Fixes: 18ec7d5c3f43 ("[GFS2] Make journaled data files identical to normal files on disk")
> Signed-off-by: Kyuwon Cho <kyuwon.cho@xxxxxxxx>
> ---
> Changes in v2:
> - Perform the length checks in pass 0 as well as pass 1, as suggested by
> the Sashiko review.
> - Add the introducing commit for databuf_lo_scan_elements() to Fixes.
>
> v1: https://lore.kernel.org/all/179620509057.2012504.1338760759852960966@xxxxxxxx/
>
> The issue was found by an LLM-guided test generator that we are
> developing as a research prototype.
>
> A reproducer is available on request.
>
> fs/gfs2/lops.c | 15 +++++++++++++--
> 1 file changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
> index 657edd406dd1..61cc39db4437 100644
> --- a/fs/gfs2/lops.c
> +++ b/fs/gfs2/lops.c
> @@ -790,7 +790,12 @@ static int buf_lo_scan_elements(struct gfs2_jdesc *jd, u32 start,
> u64 blkno;
> int error = 0;
>
> - if (pass != 1 || be32_to_cpu(ld->ld_type) != GFS2_LOG_DESC_METADATA)
> + if (be32_to_cpu(ld->ld_type) != GFS2_LOG_DESC_METADATA)
> + return 0;
> + if (blks > buf_limit(sdp) ||
> + be32_to_cpu(ld->ld_length) != blks + 1)
> + return -EIO;
> + if (pass != 1)
> return 0;
>
> gfs2_replay_incr_blk(jd, &start);
> @@ -1000,13 +1005,19 @@ static int databuf_lo_scan_elements(struct gfs2_jdesc *jd, u32 start,
> __be64 *ptr, int pass)
> {
> struct gfs2_glock *gl = gfs2_inode_glock(jd->jd_inode);
> + struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
> unsigned int blks = be32_to_cpu(ld->ld_data1);
> struct buffer_head *bh_log, *bh_ip;
> u64 blkno;
> u64 esc;
> int error = 0;
>
> - if (pass != 1 || be32_to_cpu(ld->ld_type) != GFS2_LOG_DESC_JDATA)
> + if (be32_to_cpu(ld->ld_type) != GFS2_LOG_DESC_JDATA)
> + return 0;
> + if (blks > databuf_limit(sdp) ||
> + be32_to_cpu(ld->ld_length) != blks + 1)
> + return -EIO;
> + if (pass != 1)
> return 0;
>
> gfs2_replay_incr_blk(jd, &start);
> --
> 2.43.0
>