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

* Re: [PATCH v3] gfs2: validate log descriptor tag counts during replay
  2026-12-04  6:38 [PATCH v3] gfs2: validate log descriptor tag counts during replay Kyuwon Cho
@ 2026-12-04  6:57 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-04  6:57 UTC (permalink / raw)
  To: Kyuwon Cho, Andreas Gruenbacher; +Cc: David Teigland, Steven Whitehouse, gfs2

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] gfs2: integer overflow in gfs2_struct2blk() bypasses revoke
  validation
--

commit 06a5c8674445cd678fa93b7e482b13dc58aa34fa
Author: Kyuwon Cho <kyuwon.cho@skku.edu>

gfs2: validate log descriptor tag counts during replay

This commit validates metadata, journaled-data, and revoke log descriptor
counts and lengths during journal replay before the pass check.

> diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
> index 657edd406dd1c..e08d221f038c0 100644
> --- a/fs/gfs2/lops.c
> +++ b/fs/gfs2/lops.c

[ ... ]

> @@ -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;

[Severity: Medium]
Can gfs2_struct2blk() overflow when given an untrusted on-disk revokes count?

fs/gfs2/log.c:gfs2_struct2blk() {
    ...
	if (nstruct > first) {
		/* Subsequent struct gfs2_meta_header blocks */
		second = sdp->sd_inptrs;
		blks += DIV_ROUND_UP(nstruct - first, second);
	}
    ...
}

Since sd_inptrs - sd_ldptrs is always 6, DIV_ROUND_UP(nstruct - first,
second) evaluates (nstruct + 5) / second in 32-bit unsigned int
arithmetic.  For ld_data1 in [0xfffffffb, 0xffffffff], the numerator
wraps to 0..4 and divides to 0, so gfs2_struct2blk() returns 1.

A corrupt revoke descriptor with ld_length == 1 and ld_data1 in that
range then bypasses the validation check.  Replay scans all sd_ldptrs
slots in the block into jd->jd_revoke_list because !--revokes never
reaches zero, which can suppress valid block replays in pass 1.

Using 1 + (nstruct - first - 1) / second inside the nstruct > first
branch (or 64-bit arithmetic) avoids the 32-bit overflow.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/179636379461.1106205.14894674361180500595@skku.edu?part=1

^ permalink raw reply	[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.