Skip to content

Commit fe5e7ba

Browse files
AstralBobagruenba
authored andcommitted
gfs2: fix glock reference problem in gfs2_trans_remove_revoke
Commit 9287c64 fixed a situation in which gfs2 could use a glock after it had been freed. To do that, it temporarily added a new glock reference by calling gfs2_glock_hold in function gfs2_add_revoke. However, if the bd element was removed by gfs2_trans_remove_revoke, it failed to drop the additional reference. This patch adds logic to gfs2_trans_remove_revoke to properly drop the additional glock reference. Fixes: 9287c64 ("gfs2: Fix occasional glock use-after-free") Cc: stable@vger.kernel.org # v5.2+ Signed-off-by: Bob Peterson <rpeterso@redhat.com> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
1 parent feed98a commit fe5e7ba

4 files changed

Lines changed: 12 additions & 4 deletions

File tree

‎fs/gfs2/log.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,14 @@ void gfs2_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd)
611611
list_add(&bd->bd_list, &sdp->sd_log_revokes);
612612
}
613613

614+
void gfs2_glock_remove_revoke(struct gfs2_glock *gl)
615+
{
616+
if (atomic_dec_return(&gl->gl_revokes) == 0) {
617+
clear_bit(GLF_LFLUSH, &gl->gl_flags);
618+
gfs2_glock_queue_put(gl);
619+
}
620+
}
621+
614622
void gfs2_write_revokes(struct gfs2_sbd *sdp)
615623
{
616624
struct gfs2_trans *tr;

‎fs/gfs2/log.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ extern void gfs2_ail1_flush(struct gfs2_sbd *sdp, struct writeback_control *wbc)
7676

7777
extern int gfs2_logd(void *data);
7878
extern void gfs2_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd);
79+
extern void gfs2_glock_remove_revoke(struct gfs2_glock *gl);
7980
extern void gfs2_write_revokes(struct gfs2_sbd *sdp);
8081

8182
#endif /* __LOG_DOT_H__ */

‎fs/gfs2/lops.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -883,10 +883,7 @@ static void revoke_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
883883
bd = list_entry(head->next, struct gfs2_bufdata, bd_list);
884884
list_del_init(&bd->bd_list);
885885
gl = bd->bd_gl;
886-
if (atomic_dec_return(&gl->gl_revokes) == 0) {
887-
clear_bit(GLF_LFLUSH, &gl->gl_flags);
888-
gfs2_glock_queue_put(gl);
889-
}
886+
gfs2_glock_remove_revoke(gl);
890887
kmem_cache_free(gfs2_bufdata_cachep, bd);
891888
}
892889
}

‎fs/gfs2/trans.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ void gfs2_trans_remove_revoke(struct gfs2_sbd *sdp, u64 blkno, unsigned int len)
262262
list_del_init(&bd->bd_list);
263263
gfs2_assert_withdraw(sdp, sdp->sd_log_num_revoke);
264264
sdp->sd_log_num_revoke--;
265+
if (bd->bd_gl)
266+
gfs2_glock_remove_revoke(bd->bd_gl);
265267
kmem_cache_free(gfs2_bufdata_cachep, bd);
266268
tr->tr_num_revoke--;
267269
if (--n == 0)

0 commit comments

Comments
 (0)