* [PATCH] gfs2: validate log descriptor tag counts during replay
@ 2026-12-03 16:46 Kyuwon Cho
2026-12-03 17:32 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Kyuwon Cho @ 2026-12-03 16:46 UTC (permalink / raw)
To: Andreas Gruenbacher; +Cc: David Teigland, Steven Whitehouse, gfs2, linux-kernel
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@skku.edu>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] gfs2: validate log descriptor tag counts during replay
2026-12-03 16:46 [PATCH] gfs2: validate log descriptor tag counts during replay Kyuwon Cho
@ 2026-12-03 17:32 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-03 17:32 UTC (permalink / raw)
To: Kyuwon Cho, Andreas Gruenbacher; +Cc: David Teigland, Steven Whitehouse, gfs2
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] gfs2: pass-0 bypass of ld_length checks in
buf/databuf_lo_scan_elements()
- [Low] gfs2: missing Fixes trailer for databuf_lo_scan_elements()
introduction
--
commit b9181f77fc6ab1c6472787275e362b8ec88cc766
Author: Kyuwon Cho <kyuwon.cho@skku.edu>
> gfs2: validate log descriptor tag counts during replay
>
> 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@skku.edu>
[Severity: Low]
Since this also fixes missing validation in databuf_lo_scan_elements(),
which was added later than b3b94faa5fe5 ("[GFS2] The core of GFS2"),
should this also include:
Fixes: 18ec7d5c3f43 ("[GFS2] Make journaled data files identical to normal files on disk")
> diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
> index 657edd406dd1c..57220afac0912 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;
[Severity: Medium]
Can a malformed descriptor bypass the new ld_length check during pass 0?
Both buf_lo_scan_elements() and databuf_lo_scan_elements() return 0 on
pass != 1 before checking blks and ld_length. gfs2_recover_func() runs
foreach_descriptor() with pass = 0 first, where it advances start by the
unvalidated ld->ld_length right after lops_scan_elements() returns 0.
With ld_length == 0 on a corrupt metadata or journaled-data descriptor,
foreach_descriptor() never advances start and loops forever while holding
sdp->sd_freeze_mutex, sdp->sd_log_flush_lock, and JDF_RECOVERY, hanging
mount and unmount.
Checking ld_type first, validating blks and ld_length, and only then
returning 0 when pass != 1 would reject malformed descriptors during
pass 0 before foreach_descriptor() uses ld_length.
--
Sashiko AI review · https://sashiko.dev/#/patchset/179620509057.2012504.1338760759852960966@skku.edu?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-03 17:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 16:46 [PATCH] gfs2: validate log descriptor tag counts during replay Kyuwon Cho
2026-12-03 17:32 ` sashiko-bot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.