[PATCH] gfs2: validate log descriptor tag counts during replay
From: Kyuwon Cho
Date: Thu Dec 03 2026 - 11:46:11 EST
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.
Check the format-specific tag capacity and require ld_length to account
for exactly the descriptor and its payload blocks. Reject malformed
descriptors before scanning their tags.
Fixes: b3b94faa5fe5 ("[GFS2] The core of GFS2")
Signed-off-by: Kyuwon Cho <kyuwon.cho@xxxxxxxx>
---
The issue was found by an LLM-guided test generator that we are
developing as a research prototype.
The reproducers mount crafted GFS2 images with a dirty journal whose
single-block metadata or JDATA descriptor claims 8192 tags. Mounting the
images and replaying their journals requires root in the initial namespace.
The decoded JDATA trace is:
BUG: KASAN: use-after-free in databuf_lo_scan_elements (fs/gfs2/lops.c:1019)
Workqueue: gfs2_recovery gfs2_recover_func
Call Trace:
dump_stack_lvl (lib/dump_stack.c:94 lib/dump_stack.c:120)
print_report (mm/kasan/report.c:378 mm/kasan/report.c:482)
kasan_report (mm/kasan/report.c:595)
databuf_lo_scan_elements (fs/gfs2/lops.c:1019)
gfs2_recover_func.cold (fs/gfs2/lops.h:72 fs/gfs2/recovery.c:241 fs/gfs2/recovery.c:510)
process_one_work (kernel/workqueue.c:3497)
The decoded metadata trace is:
BUG: KASAN: use-after-free in buf_lo_scan_elements (fs/gfs2/lops.c:795)
Workqueue: gfs2_recovery gfs2_recover_func
Call Trace:
dump_stack_lvl (lib/dump_stack.c:94 lib/dump_stack.c:120)
print_report (mm/kasan/report.c:378 mm/kasan/report.c:482)
kasan_report (mm/kasan/report.c:595)
buf_lo_scan_elements (fs/gfs2/lops.c:795)
gfs2_recover_func.cold (fs/gfs2/lops.h:72 fs/gfs2/recovery.c:241 fs/gfs2/recovery.c:510)
process_one_work (kernel/workqueue.c:3497)
The patch was tested on v7.4-rc5 and rebased onto GFS2 commit
2e177e272b59 ("gfs2: fix withdraw after SDF_JOURNAL_LIVE clearing").
fs/gfs2/lops.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
index 657edd406dd1..57220afac091 100644
--- a/fs/gfs2/lops.c
+++ b/fs/gfs2/lops.c
@@ -792,6 +792,9 @@ static int buf_lo_scan_elements(struct gfs2_jdesc *jd, u32 start,
if (pass != 1 || 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;
gfs2_replay_incr_blk(jd, &start);
@@ -1000,6 +1003,7 @@ 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;
@@ -1008,6 +1012,9 @@ static int databuf_lo_scan_elements(struct gfs2_jdesc *jd, u32 start,
if (pass != 1 || 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;
gfs2_replay_incr_blk(jd, &start);
for (; blks; gfs2_replay_incr_blk(jd, &start), blks--) {
--
2.43.0