gfs2: fix glock reference problem in gfs2_trans_remove_revoke
Subsystems (2)
Andreas Gruenbacher
maintainerPATCH 1/1 gfs2: fix glock reference problem in gfs2_trans_remove_revoke
From: Bob Peterson <[email protected]>
Commit 9287c6452d2b 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 9287c6452d2b ("gfs2: Fix occasional glock use-after-free")
Cc [email protected] # v5.2+
Signed-off-by Bob Peterson <[email protected]>
Signed-off-by Andreas Gruenbacher <[email protected]>
--- fs/gfs2/log.c | 8 ++++++++ fs/gfs2/log.h | 1 + fs/gfs2/lops.c | 5 +---- fs/gfs2/trans.c | 2 ++ 4 files changed, 12 insertions(+), 4 deletions(-)
fs/gfs2/log.c +8 -0
@@ -611,6 +611,14 @@ void gfs2_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd)list_add (&bd->bd_list, &sdp->sd_log_revokes); } +void gfs2_glock_remove_revoke (struct gfs2_glock *gl) +{ +if (atomic_dec_return (&gl->gl_revokes) ==0 ) { +clear_bit (GLF_LFLUSH , &gl->gl_flags); +gfs2_glock_queue_put (gl); + } +} +void gfs2_write_revokes (struct gfs2_sbd *sdp) {struct gfs2_trans *tr;
fs/gfs2/log.h +1 -0
@@ -76,6 +76,7 @@ extern void gfs2_ail1_flush(struct gfs2_sbd *sdp, struct writeback_control *wbc)extern int gfs2_logd (void *data);extern void gfs2_add_revoke (struct gfs2_sbd *sdp,struct gfs2_bufdata *bd); +extern void gfs2_glock_remove_revoke (struct gfs2_glock *gl);extern void gfs2_write_revokes (struct gfs2_sbd *sdp);#endif /* __LOG_DOT_H__ */
fs/gfs2/lops.c +1 -4
@@ -883,10 +883,7 @@ static void revoke_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr) bd = list_entry(head->next, struct gfs2_bufdata, bd_list);list_del_init (&bd->bd_list); gl = bd->bd_gl; -if (atomic_dec_return (&gl->gl_revokes) ==0 ) { -clear_bit (GLF_LFLUSH , &gl->gl_flags); -gfs2_glock_queue_put (gl); - } +gfs2_glock_remove_revoke (gl);kmem_cache_free (gfs2_bufdata_cachep, bd); } }
fs/gfs2/trans.c +2 -0
@@ -262,6 +262,8 @@ void gfs2_trans_remove_revoke(struct gfs2_sbd *sdp, u64 blkno, unsigned int len)list_del_init (&bd->bd_list);gfs2_assert_withdraw (sdp, sdp->sd_log_num_revoke); sdp->sd_log_num_revoke--; +if (bd->bd_gl) +gfs2_glock_remove_revoke (bd->bd_gl);kmem_cache_free (gfs2_bufdata_cachep, bd); tr->tr_num_revoke--;if (--n ==0 )
Signature · 1 line
2.20.1