From: Andrew Price Date: Wed, 7 Oct 2020 12:30:58 +0100 Subject: [Cluster-devel] [PATCH] gfs2: Null-check gl in gfs2_rgrp_dump() Message-ID: <20201007113058.2128527-1-anprice@redhat.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit When an rindex entry is found to be corrupt, compute_bitstructs() calls gfs2_consist_rgrpd() which calls gfs2_rgrp_dump() like this: gfs2_rgrp_dump(NULL, rgd->rd_gl, fs_id_buf); gfs2_rgrp_dump then dereferences the gl without checking it and we get BUG: KASAN: null-ptr-deref in gfs2_rgrp_dump+0x28/0x280 because there's no rgrp glock involved while reading the rindex on mount. Add a NULL check for gl in gfs2_rgrp_dump() to allow the withdraw to continue cleanly. Reported-by: syzbot+43fa87986bdd31df9de6 at syzkaller.appspotmail.com Signed-off-by: Andrew Price --- fs/gfs2/rgrp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index 074f228ea839..ff0cabd819cc 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -2217,12 +2217,13 @@ static void rgblk_free(struct gfs2_sbd *sdp, struct gfs2_rgrpd *rgd, void gfs2_rgrp_dump(struct seq_file *seq, struct gfs2_glock *gl, const char *fs_id_buf) { - struct gfs2_rgrpd *rgd = gl->gl_object; + struct gfs2_rgrpd *rgd; struct gfs2_blkreserv *trs; const struct rb_node *n; - if (rgd == NULL) + if (gl == NULL || gl->gl_object == NULL) return; + rgd = gl->gl_object; gfs2_print_dbg(seq, "%s R: n:%llu f:%02x b:%u/%u i:%u r:%u e:%u\n", fs_id_buf, (unsigned long long)rgd->rd_addr, rgd->rd_flags, -- 2.26.2