Skip to contentSkip to conversation

gfs2: check for empty rgrp tree in gfs2_ri_update

Cluster-devel Applied Bob Peterson 2 participants 2 messages Nov 24, 2020 1 message not in the archive GFS2 file system

lore
Share & tools
lore

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

#1 lore raw

Hi,

If gfs2 tries to mount a (corrupt) file system that has no resource groups it still tries to set preferences on the first one, which causes a kernel null pointer dereference. This patch adds a check to function gfs2_ri_update so this condition is detected and reported back as an error.

Reported-by syzbot
---
 fs/gfs2/rgrp.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/gfs2/rgrp.c +4 -0
index f7addc6197ed..5e8eef9990e3 100644
@@ -985,6 +985,10 @@ static int gfs2_ri_update(struct gfs2_inode *ip)
 	if (error < 0)
 		return error;
 
+	if (RB_EMPTY_ROOT(&sdp->sd_rindex_tree)) {
+		fs_err(sdp, "no resource groups found in the file system.\n");
+		return -ENOENT;
+	}
 	set_rgrp_preferences(sdp);
 
 	sdp->sd_rindex_uptodate = 1;
maintainer Applied
#2 lore raw
Quoted 16 lines · Bob Peterson

If gfs2 tries to mount a (corrupt) file system that has no resource groups it still tries to set preferences on the first one, which causes a kernel null pointer dereference. This patch adds a check to function gfs2_ri_update so this condition is detected and reported back as an error.

Reported-by syzbot
---
 fs/gfs2/rgrp.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/gfs2/rgrp.c +0 -0
index f7addc6197ed..5e8eef9990e3 100644

fs/gfs2/rgrp.c static int gfs2_ri_update(struct gfs2_inode *ip) · line 994

Quoted 10 lines
fs/gfs2/rgrp.c +4 -0
@@ -985,6 +985,10 @@ static int gfs2_ri_update(struct gfs2_inode *ip)
        if (error < 0)
                return error;
 
+       if (RB_EMPTY_ROOT(&sdp->sd_rindex_tree)) {
+               fs_err(sdp, "no resource groups found in the file system.\n");
+               return -ENOENT;
+       }
        set_rgrp_preferences(sdp);
 
        sdp->sd_rindex_uptodate = 1;

Pushed to for-next, thanks.

Andreas