From: Bob Peterson Date: Tue, 27 Oct 2020 09:52:20 -0500 Subject: [Cluster-devel] [GFS2 PATCH 1/3] gfs2: Free rd_bits later in gfs2_clear-rgrpd to fix use-after-free In-Reply-To: <20201027145222.363422-1-rpeterso@redhat.com> References: <20201027145222.363422-1-rpeterso@redhat.com> Message-ID: <20201027145222.363422-2-rpeterso@redhat.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Before this patch, function gfs2_clear_rgrpd ran through all the rgrps doing cleanup, but it called kfree(rgd->rd_bits) then return_all_reservations(). But return_all_reservations calls __rs_deltree, which calls rbm_bi, and rbm_bi references: rbm->rgd->rd_bits + rbm->bii. This is use-after-free. This patch moves the call to kfree after the call to return_all_reservations so it can reference it before it is freed. Signed-off-by: Bob Peterson --- fs/gfs2/rgrp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index ee491bb9c1cc..eb1b29734b7f 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -719,9 +719,9 @@ void gfs2_clear_rgrpd(struct gfs2_sbd *sdp) } gfs2_free_clones(rgd); + return_all_reservations(rgd); kfree(rgd->rd_bits); rgd->rd_bits = NULL; - return_all_reservations(rgd); kmem_cache_free(gfs2_rgrpd_cachep, rgd); } } -- 2.26.2