All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] gfs2: validate log descriptor tag counts during replay
@ 2026-12-04  6:38 Kyuwon Cho
  2026-12-04  6:57 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Kyuwon Cho @ 2026-12-04  6:38 UTC (permalink / raw)
  To: Andreas Gruenbacher
  Cc: David Teigland, Steven Whitehouse, sashiko-reviews, 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.

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.

Apply equivalent consistency checks to revoke descriptors. A zero revoke
count underflows while scanning, and a count that does not match ld_length
makes replay consume the wrong number of log blocks.

Fixes: b3b94faa5fe5 ("[GFS2] The core of GFS2")
Fixes: 18ec7d5c3f43 ("[GFS2] Make journaled data files identical to normal files on disk")
Suggested-by: Andreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: Kyuwon Cho <kyuwon.cho@skku.edu>
---
Changes in v3:
- Add equivalent type, nonzero-count, and exact-length checks for revoke
  descriptors, as suggested by Andreas Gruenbacher.
- Keep the metadata and journaled-data checks added in v2 unchanged.

v2: https://lore.kernel.org/all/179632380570.3852104.9882872917590234700@skku.edu/
v1: https://lore.kernel.org/all/179620509057.2012504.1338760759852960966@skku.edu/

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 | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
index 657edd406dd1..e08d221f038c 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);
@@ -925,7 +930,11 @@ static int revoke_lo_scan_elements(struct gfs2_jdesc *jd, u32 start,
 	int first = 1;
 	int error;
 
-	if (pass != 0 || be32_to_cpu(ld->ld_type) != GFS2_LOG_DESC_REVOKE)
+	if (be32_to_cpu(ld->ld_type) != GFS2_LOG_DESC_REVOKE)
+		return 0;
+	if (!revokes || blks != gfs2_struct2blk(sdp, revokes))
+		return -EIO;
+	if (pass != 0)
 		return 0;
 
 	offset = sizeof(struct gfs2_log_descriptor);
@@ -1000,13 +1009,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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-04  6:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04  6:38 [PATCH v3] gfs2: validate log descriptor tag counts during replay Kyuwon Cho
2026-12-04  6:57 ` 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.