Skip to content

Commit 6d7dce3

Browse files
AstralBobgregkh
authored andcommitted
gfs2: fix use-after-free in trans_drain
[ Upstream commit 1a5a2cf ] This patch adds code to function trans_drain to remove drained bd elements from the ail lists, if queued, before freeing the bd. If we don't remove the bd from the ail, function ail_drain will try to reference the bd after it has been freed by trans_drain. Thanks to Andy Price for his analysis of the problem. Reported-by: Andy Price <anprice@redhat.com> Signed-off-by: Bob Peterson <rpeterso@redhat.com> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 419ebba commit 6d7dce3

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

‎fs/gfs2/log.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,12 +935,16 @@ static void trans_drain(struct gfs2_trans *tr)
935935
while (!list_empty(head)) {
936936
bd = list_first_entry(head, struct gfs2_bufdata, bd_list);
937937
list_del_init(&bd->bd_list);
938+
if (!list_empty(&bd->bd_ail_st_list))
939+
gfs2_remove_from_ail(bd);
938940
kmem_cache_free(gfs2_bufdata_cachep, bd);
939941
}
940942
head = &tr->tr_databuf;
941943
while (!list_empty(head)) {
942944
bd = list_first_entry(head, struct gfs2_bufdata, bd_list);
943945
list_del_init(&bd->bd_list);
946+
if (!list_empty(&bd->bd_ail_st_list))
947+
gfs2_remove_from_ail(bd);
944948
kmem_cache_free(gfs2_bufdata_cachep, bd);
945949
}
946950
}

‎fs/gfs2/trans.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ static struct gfs2_bufdata *gfs2_alloc_bufdata(struct gfs2_glock *gl,
134134
bd->bd_bh = bh;
135135
bd->bd_gl = gl;
136136
INIT_LIST_HEAD(&bd->bd_list);
137+
INIT_LIST_HEAD(&bd->bd_ail_st_list);
138+
INIT_LIST_HEAD(&bd->bd_ail_gl_list);
137139
bh->b_private = bd;
138140
return bd;
139141
}

0 commit comments

Comments
 (0)