Skip to contentSkip to conversation

libgfs2: Check block range when inserting into rgrp tree

PATCH New Bob Peterson 2 participants 2 messages Sep 14, 2015 – Sep 16, 2015 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 libgfs2: Check block range when inserting into rgrp tree

Hi,

This patch adds checks to function rindex_read to make sure the rgrp starting address isn't grossly outside the file system. It may be in the case of severely corrupt file systems from fsck. If we added them to the rgrp tree, our calculations will get screwed up, eventually causing a segfault.

Regards,

Bob Peterson
Red Hat File Systems

---

gfs2/libgfs2/super.c +6 -0
index b956366..73354ff 100644
@@ -166,6 +166,12 @@ int rindex_read(struct gfs2_sbd *sdp, int fd, int *count1, int *sane)
 			return -1;
 
 		gfs2_rindex_in(&ri, (char *)&buf.bufgfs2);
+		if (gfs2_check_range(sdp, ri.ri_addr) != 0) {
+			*sane = 0;
+			if (prev_rgd == NULL)
+				return -1;
+			ri.ri_addr = prev_rgd->ri.ri_addr + prev_rgd->length;
+		}
 		rgd = rgrp_insert(&sdp->rgtree, ri.ri_addr);
 		memcpy(&rgd->ri, &ri, sizeof(struct gfs2_rindex));
 
#2 lore raw

PATCH 1/1 libgfs2: Check block range when inserting into rgrp tree

Quoted 20 lines · Bob Peterson

Hi,

This patch adds checks to function rindex_read to make sure the rgrp starting address isn't grossly outside the file system. It may be in the case of severely corrupt file systems from fsck. If we added them to the rgrp tree, our calculations will get screwed up, eventually causing a segfault.

Regards,

Bob Peterson
Red Hat File Systems

---

gfs2/libgfs2/super.c +0 -0
index b956366..73354ff 100644

gfs2/libgfs2/super.c int rindex_read(struct gfs2_sbd *sdp, int fd, int *count1, int *sane) · line 169

Quoted 4 lines
gfs2/libgfs2/super.c +1 -0
@@ -166,6 +166,12 @@ int rindex_read(struct gfs2_sbd *sdp, int fd, int *count1, int *sane)
  			return -1;
 
  		gfs2_rindex_in(&ri, (char *)&buf.bufgfs2);
+		if (gfs2_check_range(sdp, ri.ri_addr) != 0) {

I guess since we don't have the full rindex yet to get the fs size it's checking against the device size here. Assuming other tools using this function have initialized sdp->fssize sensibly before calling it: ACK.

Andy

Quoted 9 lines
gfs2/libgfs2/super.c +5 -0
+			*sane = 0;
+			if (prev_rgd == NULL)
+				return -1;
+			ri.ri_addr = prev_rgd->ri.ri_addr + prev_rgd->length;
+		}
  		rgd = rgrp_insert(&sdp->rgtree, ri.ri_addr);
  		memcpy(&rgd->ri, &ri, sizeof(struct gfs2_rindex));