Skip to contentSkip to conversation

gfs2: Check gfs2_metatype_check() return value in revoke_lo_scan_elements()

PATCH New Dmitriy Okunev 1 participant 1 message Oct 22 GFS2 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gfs2: Check gfs2_metatype_check() return value in revoke_lo_scan_elements()

revoke_lo_scan_elements() calls gfs2_metatype_check() on every log block except the first one, but does not check its return value. gfs2_metatype_check() verifies that the block magic and type match GFS2_METATYPE_LB and, on mismatch, calls gfs2_withdraw(), which moves the filesystem into a terminal state (SDF_WITHDRAWN). The function revoke_lo_scan_elements() keeps parsing the block as a valid log descriptor, passes the garbage it reads to gfs2_revoke_add(), and continues with the remaining blocks of the journal in the same way, eventually returning 0 even though the filesystem has already been withdrawn.

Check the return value gfs2_metatype_check() and in case of an error bail out with -EIO.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes b3b94faa5fe5 ("[GFS2] The core of GFS2")
---
 fs/gfs2/lops.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
fs/gfs2/lops.c +6 -2
index 6dabe73ad790..2aacd3f774ab 100644
@@ -936,8 +936,12 @@ static int revoke_lo_scan_elements(struct gfs2_jdesc *jd, u32 start,
 		if (error)
 			return error;
 
-		if (!first)
-			gfs2_metatype_check(sdp, bh, GFS2_METATYPE_LB);
+		if (!first) {
+			if (gfs2_metatype_check(sdp, bh, GFS2_METATYPE_LB)) {
+				brelse(bh);
+				return -EIO;
+			}
+		}
 
 		while (offset + sizeof(u64) <= sdp->sd_sb.sb_bsize) {
 			blkno = be64_to_cpu(*(__be64 *)(bh->b_data + offset));
Signature · 1 line
2.53.0